|
| 1 | +import * as helper from "../helper"; |
| 2 | +import * as TKUnit from "../../TKUnit"; |
| 3 | +import { parse } from "tns-core-modules/ui/builder"; |
| 4 | +import * as view from "tns-core-modules/ui/core/view"; |
| 5 | +import * as platform from "tns-core-modules/platform"; |
| 6 | +import { Repeater } from "tns-core-modules/ui/repeater"; |
| 7 | +import { ios as iosUtils } from "tns-core-modules/utils/utils"; |
| 8 | +import { UITest } from "../../ui-test"; |
| 9 | +import { |
| 10 | + dipToDp, left, top, right, bottom, height, width, |
| 11 | + equal, check, lessOrCloseEnough, greaterOrCloseEnough, |
| 12 | + isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith |
| 13 | +} from "../layouts/layout-tests-helper"; |
| 14 | + |
| 15 | +export class RepeaterSafeAreaTest extends UITest<Repeater> { |
| 16 | + |
| 17 | + private executeSnippet<U extends { root: view.View }>(ui: U, setup: (ui: U) => void, test: (ui: U) => void, pageOptions?: helper.PageOptions): void { |
| 18 | + function waitUntilTestElementLayoutIsValid(view: view.View, timeoutSec?: number): void { |
| 19 | + TKUnit.waitUntilReady(() => { |
| 20 | + return view.isLayoutValid; |
| 21 | + }, timeoutSec || 1); |
| 22 | + } |
| 23 | + |
| 24 | + setup(ui); |
| 25 | + helper.buildUIAndRunTest(ui.root, () => { |
| 26 | + waitUntilTestElementLayoutIsValid(ui.root); |
| 27 | + test(ui); |
| 28 | + }, pageOptions); |
| 29 | + }; |
| 30 | + |
| 31 | + private noop() { |
| 32 | + // no operation |
| 33 | + }; |
| 34 | + |
| 35 | + private getViews(template: string) { |
| 36 | + let root = parse(template); |
| 37 | + return { |
| 38 | + root, |
| 39 | + list: root.getViewById("repeater") as Repeater |
| 40 | + }; |
| 41 | + }; |
| 42 | + |
| 43 | + private repeater_in_full_screen(repeater: Repeater, pageOptions?: helper.PageOptions) { |
| 44 | + let expectedTop = 0; |
| 45 | + if (pageOptions && pageOptions.actionBarFlat) { |
| 46 | + const actionBarHeight = round(dipToDp(repeater.page.actionBar.nativeViewProtected.frame.size.height)); |
| 47 | + const app = iosUtils.getter(UIApplication, UIApplication.sharedApplication); |
| 48 | + const statusBarHeight = round(dipToDp(app.statusBarFrame.size.height)); |
| 49 | + expectedTop = actionBarHeight + statusBarHeight; |
| 50 | + } |
| 51 | + |
| 52 | + const l = left(repeater); |
| 53 | + const t = top(repeater); |
| 54 | + const r = right(repeater); |
| 55 | + const b = bottom(repeater); |
| 56 | + equal(l, 0, `${repeater}.left - actual:${l}; expected: ${0}`); |
| 57 | + equal(t, expectedTop, `${repeater}.top - actual:${t}; expected: ${expectedTop}`); |
| 58 | + equal(r, platform.screen.mainScreen.widthPixels, `${repeater}.right - actual:${r}; expected: ${platform.screen.mainScreen.widthPixels}`); |
| 59 | + equal(b, platform.screen.mainScreen.heightPixels, `${repeater}.bottom - actual:${b}; expected: ${platform.screen.mainScreen.heightPixels}`); |
| 60 | + } |
| 61 | + |
| 62 | + private repeater_in_full_screen_test(pageOptions?: helper.PageOptions) { |
| 63 | + const snippet = ` |
| 64 | + <Repeater id="repeater" loaded="onLoaded" backgroundColor="Crimson"></Repeater> |
| 65 | + `; |
| 66 | + this.executeSnippet( |
| 67 | + this.getViews(snippet), |
| 68 | + this.noop, |
| 69 | + ({ list }) => { |
| 70 | + this.repeater_in_full_screen(list, pageOptions); |
| 71 | + }, |
| 72 | + pageOptions |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + public test_repeater_in_full_screen_action_bar() { |
| 77 | + this.repeater_in_full_screen_test({ actionBar: true }); |
| 78 | + } |
| 79 | + |
| 80 | + public test_repeater_in_full_screen_action_bar_hidden() { |
| 81 | + this.repeater_in_full_screen_test({ actionBarHidden: true }); |
| 82 | + } |
| 83 | + |
| 84 | + public test_repeater_in_full_screen_action_bar_flat() { |
| 85 | + this.repeater_in_full_screen_test({ actionBarFlat: true }); |
| 86 | + } |
| 87 | + |
| 88 | + public test_repeater_in_full_screen_tab_bar() { |
| 89 | + this.repeater_in_full_screen_test({ tabBar: true }); |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +export function createTestCase(): RepeaterSafeAreaTest { |
| 94 | + return new RepeaterSafeAreaTest(); |
| 95 | +} |
0 commit comments