123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635 |
- jest.setTimeout(50000)
- const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
- const isWeb = platformInfo.startsWith('web')
- const isAndroid = platformInfo.startsWith('android')
- const isIos = platformInfo.startsWith('ios')
- const isMP = platformInfo.startsWith('mp')
- const isHarmony = platformInfo.startsWith('harmony')
- const isApp = isAndroid || isIos || isHarmony
- const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
- const FIRST_PAGE_PATH = '/pages/API/dialog-page/dialog-page'
- const NEXT_PAGE_PATH = '/pages/API/dialog-page/next-page'
- describe('dialog page', () => {
- if (isAppWebView || isMP) {
- it('not support', () => {
- expect(1).toBe(1)
- })
- return
- }
- let topSafeArea = 0;
- let page;
- let initLifeCycleNum;
- let lifecycleNum;
- beforeAll(async () => {
- const windowInfo = await program.callUniMethod('getWindowInfo');
- topSafeArea = windowInfo.safeAreaInsets.top;
- page = await program.reLaunch(FIRST_PAGE_PATH)
- await page.waitFor('view');
- initLifeCycleNum = await page.callMethod('getLifeCycleNum');
- await page.callMethod('setLifeCycleNum', 0)
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifecycleNum).toBe(0)
- });
- it('page pageBody safeAreaInsets', async () => {
- const pageBodyWidth = await page.$('#page-body-width')
- expect(parseInt(await pageBodyWidth.text())).toBeGreaterThan(0)
- const pageBodyHeight = await page.$('#page-body-height')
- expect(parseInt(await pageBodyHeight.text())).toBeGreaterThan(0)
- const pageBodyLeft = await page.$('#page-body-left')
- const pageBodyRight = await page.$('#page-body-right')
- const expectRightValue = parseInt(await pageBodyLeft.text()) + parseInt(await pageBodyWidth.text())
- expect(parseInt(await pageBodyRight.text())).toBe(expectRightValue)
- const pageBodyTop = await page.$('#page-body-top')
- const pageBodyBottom = await page.$('#page-body-bottom')
- const expectBottomValue = parseInt(await pageBodyTop.text()) + parseInt(await pageBodyHeight.text())
- expect(parseInt(await pageBodyBottom.text())).toBe(expectBottomValue)
- pageSafeAreaInsetsTop = await page.$('#page-safe-area-insets-top')
- if(isWeb){
- expect(await pageSafeAreaInsetsTop.text()).toBe('44')
- } else {
- expect(await pageSafeAreaInsetsTop.text()).toBe('0')
- }
- pageSafeAreaInsetsBottom = await page.$('#page-safe-area-insets-bottom')
- if(isWeb){
- expect(await pageSafeAreaInsetsBottom.text()).toBe('0')
- }
- if(isIos || isAndroid){
- expect(parseInt(await pageSafeAreaInsetsBottom.text())).toBeGreaterThanOrEqual(0)
- }
- pageSafeAreaInsetsLeft = await page.$('#page-safe-area-insets-left')
- expect(await pageSafeAreaInsetsLeft.text()).toBe('0')
- pageSafeAreaInsetsRight = await page.$('#page-safe-area-insets-right')
- expect(await pageSafeAreaInsetsRight.text()).toBe('0')
- const pageWidth = await page.$('#page-width')
- expect(parseInt(await pageWidth.text())).toBeGreaterThan(0)
- const pageHeight = await page.$('#page-height')
- expect(parseInt(await pageHeight.text())).toBeGreaterThan(0)
- const pageStatusBarHeight = await page.$('#page-statusBarHeight')
- expect(parseInt(await pageStatusBarHeight.text())).toBeGreaterThanOrEqual(0)
- })
- it('dialogPage pageBody safeAreaInsets', async () => {
- await page.callMethod('openDialogCheckMoreAttribute')
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- const image = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- });
- expect(image).toSaveImageSnapshot();
- await page.callMethod('closeDialog');
- lifecycleNum = await page.callMethod('getLifeCycleNum');
- expect(lifecycleNum).toBe(2);
- await page.callMethod('setLifeCycleNum', 0);
- })
- it('open dialog1', async () => {
- await page.callMethod('openDialog1');
- // 无法通过获取 dom 元素来判断是否打开了 dialogPage
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- const image = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- });
- expect(image).toSaveImageSnapshot();
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- // 不应触发父页面的生命周期,应该触发:
- // 1. openDialogPage success & complete callback
- // 2. dialog page 生命周期
- expect(lifecycleNum).toBe(7)
- await page.callMethod('setLifeCycleNum', 0)
- const dialogPageRoute = await page.callMethod('getDialogPageRoute')
- expect(dialogPageRoute).toBe('pages/API/dialog-page/dialog-1')
- });
- it('check dialogPage methods', async () => {
- expect(await page.callMethod('dialogPageCheckGetDialogPages')).toBe(true)
- let dialogPageStyle = await page.callMethod('dialogPageGetPageStyle')
- expect(dialogPageStyle.backgroundColorContent).not.toBe('red')
- await page.callMethod('dialogPageSetPageStyle')
- dialogPageStyle = await page.callMethod('dialogPageGetPageStyle')
- expect(dialogPageStyle.backgroundColorContent).toBe('red')
- expect(await page.callMethod('dialogPageCheckGetElementById')).toBe(true)
- expect(await page.callMethod('dialogCheckGetAndroidView')).toBe(isAndroid)
- expect(await page.callMethod('dialogCheckGetIOSView')).toBe(false)
- expect(await page.callMethod('dialogCheckGetHTMLElement')).toBe(isWeb)
- })
- it('closeDialogPage', async () => {
- await page.callMethod('closeDialog');
- const image = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- });
- expect(image).toSaveImageSnapshot();
- // closeDialogPage success & complete callback 应被触发
- // dialogPage onUnload 应被触发
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifecycleNum).toBe(-3)
- await page.callMethod('setLifeCycleNum', 0)
- })
- it('openDialog with wrong path', async () => {
- await page.callMethod('openDialog1WrongPath')
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifecycleNum).toBe(-3)
- await page.callMethod('setLifeCycleNum', 0)
- })
- it('navigateTo nextPage & open Dialog', async () => {
- await page.callMethod('goNextPageOpenDialog1')
- await page.waitFor(2500)
- if (isWeb) {
- await page.waitFor(3000)
- }
- page = await program.currentPage()
- expect(page.path).toBe(NEXT_PAGE_PATH.substring(1))
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- const image = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- });
- expect(image).toSaveImageSnapshot();
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifecycleNum).toBe(-4)
- await page.callMethod('setLifeCycleNum', 0)
- })
- it('dialog1 navigateBack', async () => {
- await program.navigateBack()
- page = await program.currentPage()
- // dialogPage onBackPress 返回 true, 应可以拦截 navigateBack
- expect(page.path).toBe(NEXT_PAGE_PATH.substring(1))
- const image = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- });
- expect(image).toSaveImageSnapshot();
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- // onBackPress 生命周期应该被触发
- expect(lifecycleNum).toBe(1)
- await page.callMethod('setLifeCycleNum', 0)
- })
- it('open dialog2', async () => {
- await page.callMethod('openDialog2')
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- // 应触发前一个 dialogPage 的 onHide
- expect(lifecycleNum).toBe(4)
- await page.callMethod('setLifeCycleNum', 0)
- })
- it('closeDialogPage', async () => {
- await page.callMethod('closeDialog')
- await page.waitFor(1000)
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- // 应触发 success & complete 回调
- // 应触发 dialogPage 的 unload,下层的 dialogPage 会先 show 再 unload
- expect(lifecycleNum).toBe(-7)
- const image = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- });
- expect(image).toSaveImageSnapshot();
- await page.callMethod('setLifeCycleNum', 0)
- })
- it('open multiple dialog page', async () => {
- await page.callMethod('openDialog1')
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- const image1 = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- });
- expect(image1).toSaveImageSnapshot();
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifecycleNum).toBe(4)
- await page.callMethod('openDialog2')
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- const image2 = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- });
- expect(image2).toSaveImageSnapshot();
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifecycleNum).toBe(8)
- await page.callMethod('setLifeCycleNum', 0)
- })
- it('openDialogPage to home page', async () => {
- // 本测试例中是在 FIRST_PAGE_PATH 中打开
- await page.callMethod('openDialogPage1ToHomePage')
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifecycleNum).toBe(4)
- await page.callMethod('setLifeCycleNum', 0)
- })
- it('dialog2 navigateBack', async () => {
- await program.navigateBack()
- page = await program.currentPage()
- expect(page.path).toBe(FIRST_PAGE_PATH.substring(1))
- const image = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- });
- expect(image).toSaveImageSnapshot();
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- // dialogPage2 onBackPress +1 dialogPage1 show +1 dialogPage unload -5*2 firstPage show +10
- expect(lifecycleNum).toBe(2)
- await page.callMethod('setLifeCycleNum', 0)
- })
- it('close specified dialogPage', async () => {
- await page.callMethod('openDialog2')
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- const image1 = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- });
- expect(image1).toSaveImageSnapshot();
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifecycleNum).toBe(4)
- await page.callMethod('openDialog1')
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- const image2 = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- });
- expect(image2).toSaveImageSnapshot();
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifecycleNum).toBe(10)
- await page.callMethod('closeSpecifiedDialog', 0)
- const image3 = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- });
- expect(image3).toSaveImageSnapshot();
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifecycleNum).toBe(7)
- await page.callMethod('closeSpecifiedDialog', 1)
- const image4 = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- });
- expect(image4).toSaveImageSnapshot();
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifecycleNum).toBe(5)
- await page.callMethod('closeSpecifiedDialog', 0)
- const image5 = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- });
- expect(image5).toSaveImageSnapshot();
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifecycleNum).toBe(2)
- await page.callMethod('setLifeCycleNum', 0)
- })
- it('check triggerParentHide', async () => {
- // no triggerParentHide should not trigger parent hide
- await page.callMethod('openDialog4')
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- // dialog4 show +1
- expect(await page.callMethod('getLifeCycleNum')).toBe(1)
- await page.callMethod('closeDialog')
- await page.waitFor(200)
- // dialog4 unload -5 closeDialog callback +2
- expect(await page.callMethod('getLifeCycleNum')).toBe(-2)
- // triggerParentHide should trigger parent hide
- await page.callMethod('openDialogWithTriggerParentHide')
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- // openDialog callback +2 dialog4 show +1 parent hide -10
- expect(await page.callMethod('getLifeCycleNum')).toBe(-9)
- await page.callMethod('closeDialog')
- await page.waitFor(200)
- // dialog4 unload -5 parent show +10 closeDialog callback +2
- expect(await page.callMethod('getLifeCycleNum')).toBe(-2)
- // triggerParentHide should trigger parent hide
- await page.callMethod('openDialogWithTriggerParentHide')
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- // openDialog callback +2 dialog4 show +1 parent hide -10
- expect(await page.callMethod('getLifeCycleNum')).toBe(-9)
- // second triggerParentHide should not trigger parent hide
- await page.callMethod('openDialogWithTriggerParentHide')
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- // openDialog callback +2 dialog4 show +1
- expect(await page.callMethod('getLifeCycleNum')).toBe(-6)
- await page.callMethod('closeSpecifiedDialog', 1)
- await page.waitFor(200)
- // close not last triggerParentHide should not trigger parent show
- // close callback +2 dialog4 unload -5 dialog4 show +1
- expect(await page.callMethod('getLifeCycleNum')).toBe(-8)
- await page.callMethod('closeSpecifiedDialog', 0)
- await page.waitFor(200)
- // close last triggerParentHide should trigger parent show
- // close callback +2 dialog4 unload -5 parent show +10
- expect(await page.callMethod('getLifeCycleNum')).toBe(-1)
- // no triggerParentHide should not trigger parent hide
- await page.callMethod('openDialog4')
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- // dialog4 show +1
- expect(await page.callMethod('getLifeCycleNum')).toBe(0)
- // triggerParentHide should trigger parent hide
- await page.callMethod('openDialogWithTriggerParentHide')
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- // openDialog callback +2 dialog4 show +1 parent hide -10
- expect(await page.callMethod('getLifeCycleNum')).toBe(-7)
- // second triggerParentHide should not trigger parent hide
- await page.callMethod('openDialogWithTriggerParentHide')
- await page.waitFor(1000)
- if (isWeb) {
- await page.waitFor(2000)
- }
- // openDialog callback +2 dialog4 show +1
- expect(await page.callMethod('getLifeCycleNum')).toBe(-4)
- // close middle triggerParentHide dialogPage
- await page.callMethod('closeSpecifiedDialog', 1)
- await page.waitFor(200)
- // close callback +2 dialog4 unload -5
- expect(await page.callMethod('getLifeCycleNum')).toBe(-7)
- // close last triggerParentHide dialogPage shoud trigger parent show
- await page.callMethod('closeSpecifiedDialog', 1)
- await page.waitFor(200)
- // close callback +2 dialog4 unload -5 dialog4 show +1 parent show +10
- expect(await page.callMethod('getLifeCycleNum')).toBe(1)
- await page.callMethod('closeDialog')
- await page.waitFor(200)
- // close callback +2 dialog4 unload -5
- expect(await page.callMethod('getLifeCycleNum')).toBe(-2)
- })
- if (isApp) {
- it('after closeDialogPage reset statusBar color', async () => {
- const screenShotArea = {
- x: 342,
- y:18,
- width: 40,
- height: 20
- };
- if (isIos) {
- screenShotArea.x = 310
- screenShotArea.y = 20
- screenShotArea.width = 40
- screenShotArea.height = 20
- } else if (platformInfo.startsWith('android 6')) {
- screenShotArea.x = 204
- screenShotArea.width = 34
- screenShotArea.height = 16
- } else if (platformInfo.startsWith('android 12')) {
- screenShotArea.x = 336
- screenShotArea.y = 3
- screenShotArea.width = 50
- screenShotArea.height = 20
- } else if (isHarmony) {
- screenShotArea.x = 295
- screenShotArea.y = 14
- screenShotArea.width = 40
- screenShotArea.height = 20
- }
- const imageForParentInit = await program.screenshot({
- deviceShot: true,
- area: screenShotArea,
- });
- expect(imageForParentInit).toSaveImageSnapshot();
- await page.callMethod('openDialog4')
- await page.waitFor(1000)
- const imageForDialog4_1 = await program.screenshot({
- deviceShot: true,
- area: screenShotArea,
- });
- expect(imageForDialog4_1).toSaveImageSnapshot();
- await page.callMethod('openDialog3')
- await page.waitFor(1000)
- const imageForDialog3 = await program.screenshot({
- deviceShot: true,
- area: screenShotArea,
- });
- expect(imageForDialog3).toSaveImageSnapshot();
- await page.callMethod('closeSpecifiedDialog', 1)
- await page.waitFor(1000)
- const imageForDialog4_2 = await program.screenshot({
- deviceShot: true,
- area: screenShotArea,
- });
- expect(imageForDialog4_2).toSaveImageSnapshot();
- await page.callMethod('closeSpecifiedDialog', 0)
- await page.waitFor(1000)
- const imageForParentEnd = await program.screenshot({
- deviceShot: true,
- area: screenShotArea,
- });
- expect(imageForParentEnd).toSaveImageSnapshot();
- })
- }
- it('input-hold-keyboard in dialog', async () => {
- await page.callMethod('jest_OpenDialog1')
- await page.waitFor(2000);
- await page.callMethod('jest_getTapPoint')
- const point_x = await page.data('jest_click_x');
- const point_y = await page.data('jest_click_y');
- await program.tap({
- x: Math.round(point_x),
- y: Math.round(point_y)
- })
- await page.waitFor(1000);
- const image = await program.screenshot({
- deviceShot: true,
- area: {
- x: 0,
- y: topSafeArea + 44
- }
- })
- expect(image).toSaveImageSnapshot()
- await page.waitFor(2000);
- await page.callMethod('jest_CloseDialog1')
- })
- it('dialogPage hideStatusBar hideBottomNavigationIndicator', async () => {
- if (isAndroid) {
- await page.callMethod('openDialog2ForTest');
- await page.waitFor(1000);
- await page.callMethod('setPageStyleForTest', {
- hideStatusBar: true,
- hideBottomNavigationIndicator: true
- });
- await page.waitFor(2000);
- const image = await program.screenshot({
- deviceShot: true
- });
- expect(image).toSaveImageSnapshot();
- await page.waitFor(2000);
- await page.callMethod('closeDialog2ForTest');
- await page.waitFor(1000);
- await page.callMethod('setPageStyleForTest2', {
- hideStatusBar: true,
- hideBottomNavigationIndicator: true
- });
- await page.waitFor(1000);
- await page.callMethod('openDialog2ForTest');
- await page.waitFor(1000);
- await page.callMethod('closeDialog2ForTest');
- await page.waitFor(1000);
- const image2 = await program.screenshot({
- deviceShot: true
- });
- expect(image2).toSaveImageSnapshot();
- }
- });
- if (isAndroid) {
- it('dialogPage androidThreeButtonNavigationTranslucent', async () => {
- await page.callMethod('openDialog2ForTest');
- await page.waitFor(1000);
- await page.callMethod('setPageStyleForTest', {
- androidThreeButtonNavigationTranslucent: false
- });
- await page.waitFor(2000);
- const image = await program.screenshot({
- deviceShot: true
- });
- expect(image).toSaveImageSnapshot();
- await page.waitFor(2000);
- await page.callMethod('closeDialog2ForTest');
- });
- }
- if ('open dialogPage with relative path', async () => {
- await page.callMethod('closeDialog')
- await page.waitFor(1000);
- await page.callMethod('setLifeCycleNum', 0)
- await page.callMethod('openDialogWithRelativePath');
- await page.waitFor(1000);
- if (isWeb) {
- await page.waitFor(2000);
- }
- lifecycleNum = await page.callMethod('getLifeCycleNum')
- expect(lifecycleNum).toBe(6)
- await page.callMethod('setLifeCycleNum', 0)
- })
- afterAll(async () => {
- await page.callMethod('setLifeCycleNum', initLifeCycleNum)
- });
- });
|