| 7 | import { dipToDp, left, top, right, bottom, height, width, equal, closeEnough, lessOrCloseEnough, greaterOrCloseEnough, isLeftAlignedWith, isRightAlignedWith, isTopAlignedWith, isBottomAlignedWith, isLeftWith, isAboveWith, isRightWith, isBelowWith } from './layout-tests-helper'; |
| 8 | |
| 9 | export class SafeAreaTests extends testModule.UITest<any> { |
| 10 | public create(): any { |
| 11 | return null; |
| 12 | } |
| 13 | |
| 14 | private executeSnippet<U extends { root: view.View }>(ui: U, setup: (ui: U) => void, test: (ui: U) => void, pageOptions?: helper.PageOptions): void { |
| 15 | function waitUntilTestElementLayoutIsValid(view: view.View, timeoutSec?: number): void { |
| 16 | TKUnit.waitUntilReady(() => { |
| 17 | return view.isLayoutValid; |
| 18 | }, timeoutSec || 1); |
| 19 | } |
| 20 | |
| 21 | setup(ui); |
| 22 | helper.buildUIAndRunTest( |
| 23 | ui.root, |
| 24 | () => { |
| 25 | waitUntilTestElementLayoutIsValid(ui.root); |
| 26 | test(ui); |
| 27 | }, |
| 28 | pageOptions, |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | private noop() { |
| 33 | // no operation |
| 34 | } |
| 35 | |
| 36 | public test_layout_changed_event_count() { |
| 37 | const page = <Page>Builder.parse(` |
| 38 | <Page> |
| 39 | <GridLayout id="grid" backgroundColor="Crimson"> |
| 40 | <Label id="label" text="label1" backgroundColor="Gold"></Label> |
| 41 | </GridLayout> |
| 42 | </Page> |
| 43 | `); |
| 44 | let gridLayoutChangedCounter = 0; |
| 45 | let labelLayoutChangedCounter = 0; |
| 46 | const grid = page.getViewById('grid'); |
| 47 | grid.on(view.View.layoutChangedEvent, () => { |
| 48 | gridLayoutChangedCounter++; |
| 49 | }); |
| 50 | const label = <Label>page.getViewById('label'); |
| 51 | label.on(view.View.layoutChangedEvent, () => { |
| 52 | labelLayoutChangedCounter++; |
| 53 | }); |
| 54 | helper.navigate(() => page); |
| 55 | label.height = 100; |
| 56 | TKUnit.waitUntilReady(() => labelLayoutChangedCounter === 2); |
| 57 | TKUnit.assert(gridLayoutChangedCounter === 1, `${grid} layoutChanged event count - actual:${gridLayoutChangedCounter}; expected: 1`); |
| 58 | } |
| 59 | |
| 60 | // Common |
| 61 | private getViews(template: string) { |
| 62 | let root = Builder.parse(template); |
| 63 | |
| 64 | return { |
| 65 | root, |
| 66 | child0: root.getViewById('child0') as view.View, |
nothing calls this directly
no outgoing calls
no test coverage detected