|
| 1 | +import * as helper from "../../ui-helper"; |
| 2 | +import * as TKUnit from "../../tk-unit"; |
| 3 | + |
| 4 | +import { |
| 5 | + android, |
| 6 | + getRootView, |
| 7 | + ios |
| 8 | +} from "tns-core-modules/application"; |
| 9 | +import { |
| 10 | + isAndroid, |
| 11 | + device |
| 12 | +} from "tns-core-modules/platform"; |
| 13 | +import { Button } from "tns-core-modules/ui/button/button"; |
| 14 | +import { Page } from "tns-core-modules/ui/page"; |
| 15 | +import { |
| 16 | + ShownModallyData, |
| 17 | + ShowModalOptions, |
| 18 | + View |
| 19 | +} from "tns-core-modules/ui/frame"; |
| 20 | +import { |
| 21 | + _rootModalViews |
| 22 | +} from "tns-core-modules/ui/core/view/view-common"; |
| 23 | +import { DeviceType } from "tns-core-modules/ui/enums/enums"; |
| 24 | + |
| 25 | +const ROOT_CSS_CLASS = "ns-root"; |
| 26 | +const MODAL_CSS_CLASS = "ns-modal"; |
| 27 | +const ANDROID_PLATFORM_CSS_CLASS = "ns-android"; |
| 28 | +const IOS_PLATFORM_CSS_CLASS = "ns-ios"; |
| 29 | +const PHONE_DEVICE_TYPE_CSS_CLASS = "ns-phone"; |
| 30 | +const TABLET_DEVICE_TYPE_CSS_CLASS = "ns-tablet"; |
| 31 | +const PORTRAIT_ORIENTATION_CSS_CLASS = "ns-portrait"; |
| 32 | +const LANDSCAPE_ORIENTATION_CSS_CLASS = "ns-landscape"; |
| 33 | +const UNKNOWN_ORIENTATION_CSS_CLASS = "ns-unknown"; |
| 34 | + |
| 35 | +export function test_root_view_root_css_class() { |
| 36 | + const rootViewCssClasses = getRootView().cssClasses; |
| 37 | + |
| 38 | + TKUnit.assertTrue(rootViewCssClasses.has( |
| 39 | + ROOT_CSS_CLASS), |
| 40 | + `${ROOT_CSS_CLASS} CSS class is missing` |
| 41 | + ); |
| 42 | +} |
| 43 | + |
| 44 | +export function test_root_view_platform_css_class() { |
| 45 | + const rootViewCssClasses = getRootView().cssClasses; |
| 46 | + |
| 47 | + if (isAndroid) { |
| 48 | + TKUnit.assertTrue(rootViewCssClasses.has( |
| 49 | + ANDROID_PLATFORM_CSS_CLASS), |
| 50 | + `${ANDROID_PLATFORM_CSS_CLASS} CSS class is missing` |
| 51 | + ); |
| 52 | + TKUnit.assertFalse(rootViewCssClasses.has( |
| 53 | + IOS_PLATFORM_CSS_CLASS), |
| 54 | + `${IOS_PLATFORM_CSS_CLASS} CSS class is present` |
| 55 | + ); |
| 56 | + } else { |
| 57 | + TKUnit.assertTrue(rootViewCssClasses.has( |
| 58 | + IOS_PLATFORM_CSS_CLASS), |
| 59 | + `${IOS_PLATFORM_CSS_CLASS} CSS class is missing` |
| 60 | + ); |
| 61 | + TKUnit.assertFalse(rootViewCssClasses.has( |
| 62 | + ANDROID_PLATFORM_CSS_CLASS), |
| 63 | + `${ANDROID_PLATFORM_CSS_CLASS} CSS class is present` |
| 64 | + ); |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +export function test_root_view_device_type_css_class() { |
| 69 | + const rootViewCssClasses = getRootView().cssClasses; |
| 70 | + const deviceType = device.deviceType; |
| 71 | + |
| 72 | + if (deviceType === DeviceType.Phone) { |
| 73 | + TKUnit.assertTrue(rootViewCssClasses.has( |
| 74 | + PHONE_DEVICE_TYPE_CSS_CLASS), |
| 75 | + `${PHONE_DEVICE_TYPE_CSS_CLASS} CSS class is missing` |
| 76 | + ); |
| 77 | + TKUnit.assertFalse(rootViewCssClasses.has( |
| 78 | + TABLET_DEVICE_TYPE_CSS_CLASS), |
| 79 | + `${TABLET_DEVICE_TYPE_CSS_CLASS} CSS class is present` |
| 80 | + ); |
| 81 | + } else { |
| 82 | + TKUnit.assertTrue(rootViewCssClasses.has( |
| 83 | + TABLET_DEVICE_TYPE_CSS_CLASS), |
| 84 | + `${TABLET_DEVICE_TYPE_CSS_CLASS} CSS class is missing` |
| 85 | + ); |
| 86 | + TKUnit.assertFalse(rootViewCssClasses.has( |
| 87 | + PHONE_DEVICE_TYPE_CSS_CLASS), |
| 88 | + `${PHONE_DEVICE_TYPE_CSS_CLASS} CSS class is present` |
| 89 | + ); |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +export function test_root_view_orientation_css_class() { |
| 94 | + const rootViewCssClasses = getRootView().cssClasses; |
| 95 | + let appOrientation; |
| 96 | + |
| 97 | + if (isAndroid) { |
| 98 | + appOrientation = android.orientation; |
| 99 | + } else { |
| 100 | + appOrientation = ios.orientation; |
| 101 | + } |
| 102 | + |
| 103 | + if (appOrientation === "portrait") { |
| 104 | + TKUnit.assertTrue(rootViewCssClasses.has( |
| 105 | + PORTRAIT_ORIENTATION_CSS_CLASS), |
| 106 | + `${PORTRAIT_ORIENTATION_CSS_CLASS} CSS class is missing` |
| 107 | + ); |
| 108 | + TKUnit.assertFalse(rootViewCssClasses.has( |
| 109 | + LANDSCAPE_ORIENTATION_CSS_CLASS), |
| 110 | + `${LANDSCAPE_ORIENTATION_CSS_CLASS} CSS class is present` |
| 111 | + ); |
| 112 | + TKUnit.assertFalse(rootViewCssClasses.has( |
| 113 | + UNKNOWN_ORIENTATION_CSS_CLASS), |
| 114 | + `${UNKNOWN_ORIENTATION_CSS_CLASS} CSS class is present` |
| 115 | + ); |
| 116 | + } else if (appOrientation === "landscape") { |
| 117 | + TKUnit.assertTrue(rootViewCssClasses.has( |
| 118 | + LANDSCAPE_ORIENTATION_CSS_CLASS), |
| 119 | + `${LANDSCAPE_ORIENTATION_CSS_CLASS} CSS class is missing` |
| 120 | + ); |
| 121 | + TKUnit.assertFalse(rootViewCssClasses.has( |
| 122 | + PORTRAIT_ORIENTATION_CSS_CLASS), |
| 123 | + `${PORTRAIT_ORIENTATION_CSS_CLASS} CSS class is present` |
| 124 | + ); |
| 125 | + TKUnit.assertFalse(rootViewCssClasses.has( |
| 126 | + UNKNOWN_ORIENTATION_CSS_CLASS), |
| 127 | + `${UNKNOWN_ORIENTATION_CSS_CLASS} CSS class is present` |
| 128 | + ); |
| 129 | + } else if (appOrientation === "landscape") { |
| 130 | + TKUnit.assertTrue(rootViewCssClasses.has( |
| 131 | + UNKNOWN_ORIENTATION_CSS_CLASS), |
| 132 | + `${UNKNOWN_ORIENTATION_CSS_CLASS} CSS class is missing` |
| 133 | + ); |
| 134 | + TKUnit.assertFalse(rootViewCssClasses.has( |
| 135 | + LANDSCAPE_ORIENTATION_CSS_CLASS), |
| 136 | + `${LANDSCAPE_ORIENTATION_CSS_CLASS} CSS class is present` |
| 137 | + ); |
| 138 | + TKUnit.assertFalse(rootViewCssClasses.has( |
| 139 | + PORTRAIT_ORIENTATION_CSS_CLASS), |
| 140 | + `${PORTRAIT_ORIENTATION_CSS_CLASS} CSS class is present` |
| 141 | + ); |
| 142 | + } |
| 143 | +} |
| 144 | + |
| 145 | +export function test_modal_root_view_modal_css_class() { |
| 146 | + let modalClosed = false; |
| 147 | + |
| 148 | + const modalCloseCallback = function () { |
| 149 | + modalClosed = true; |
| 150 | + }; |
| 151 | + |
| 152 | + const modalPageShownModallyEventHandler = function (args: ShownModallyData) { |
| 153 | + const page = <Page>args.object; |
| 154 | + page.off(View.shownModallyEvent, modalPageShownModallyEventHandler); |
| 155 | + |
| 156 | + TKUnit.assertTrue(_rootModalViews[0].cssClasses.has(MODAL_CSS_CLASS)); |
| 157 | + args.closeCallback(); |
| 158 | + }; |
| 159 | + |
| 160 | + const hostNavigatedToEventHandler = function (args) { |
| 161 | + const page = <Page>args.object; |
| 162 | + page.off(Page.navigatedToEvent, hostNavigatedToEventHandler); |
| 163 | + |
| 164 | + const modalPage = new Page(); |
| 165 | + modalPage.on(View.shownModallyEvent, modalPageShownModallyEventHandler); |
| 166 | + const button = <Button>page.content; |
| 167 | + const options: ShowModalOptions = { |
| 168 | + context: {}, |
| 169 | + closeCallback: modalCloseCallback, |
| 170 | + fullscreen: false, |
| 171 | + animated: false |
| 172 | + }; |
| 173 | + button.showModal(modalPage, options); |
| 174 | + }; |
| 175 | + |
| 176 | + const hostPageFactory = function (): Page { |
| 177 | + const hostPage = new Page(); |
| 178 | + hostPage.on(Page.navigatedToEvent, hostNavigatedToEventHandler); |
| 179 | + |
| 180 | + const button = new Button(); |
| 181 | + hostPage.content = button; |
| 182 | + |
| 183 | + return hostPage; |
| 184 | + }; |
| 185 | + |
| 186 | + helper.navigate(hostPageFactory); |
| 187 | + TKUnit.waitUntilReady(() => modalClosed); |
| 188 | +} |
0 commit comments