|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | +import { ionPageVisible, ionTabClick, withTestingMode } from './utils/test-utils'; |
| 3 | + |
| 4 | +test.describe('Tab Lifecycle Events', () => { |
| 5 | + test.beforeEach(async ({ page }) => { |
| 6 | + await page.addInitScript(() => { |
| 7 | + (window as any).lifecycleEvents = []; |
| 8 | + }); |
| 9 | + }); |
| 10 | + |
| 11 | + test('ionViewDidLeave should fire on active tab child page when navigating away from tabs', async ({ page }, testInfo) => { |
| 12 | + testInfo.annotations.push({ |
| 13 | + type: 'issue', |
| 14 | + description: 'https://outsystemsrd.atlassian.net/browse/FW-6788', |
| 15 | + }); |
| 16 | + |
| 17 | + await page.goto(withTestingMode('/tab-lifecycle/home')); |
| 18 | + await ionPageVisible(page, 'tab-lifecycle-home'); |
| 19 | + |
| 20 | + await page.evaluate(() => { (window as any).lifecycleEvents = []; }); |
| 21 | + |
| 22 | + await page.locator('#go-outside').click(); |
| 23 | + await ionPageVisible(page, 'tab-lifecycle-outside'); |
| 24 | + |
| 25 | + const events = await page.evaluate(() => (window as any).lifecycleEvents as string[]); |
| 26 | + expect(events).toContain('home:ionViewWillLeave'); |
| 27 | + expect(events).toContain('home:ionViewDidLeave'); |
| 28 | + }); |
| 29 | + |
| 30 | + test('ionViewDidLeave should fire on active tab child page when navigating from non-default tab', async ({ page }, testInfo) => { |
| 31 | + testInfo.annotations.push({ |
| 32 | + type: 'issue', |
| 33 | + description: 'https://outsystemsrd.atlassian.net/browse/FW-6788', |
| 34 | + }); |
| 35 | + |
| 36 | + await page.goto(withTestingMode('/tab-lifecycle/home')); |
| 37 | + await ionPageVisible(page, 'tab-lifecycle-home'); |
| 38 | + |
| 39 | + await ionTabClick(page, 'Settings'); |
| 40 | + await ionPageVisible(page, 'tab-lifecycle-settings'); |
| 41 | + |
| 42 | + await page.evaluate(() => { (window as any).lifecycleEvents = []; }); |
| 43 | + |
| 44 | + await page.locator('#go-outside-settings').click(); |
| 45 | + await ionPageVisible(page, 'tab-lifecycle-outside'); |
| 46 | + |
| 47 | + const events = await page.evaluate(() => (window as any).lifecycleEvents as string[]); |
| 48 | + expect(events).toContain('settings:ionViewWillLeave'); |
| 49 | + expect(events).toContain('settings:ionViewDidLeave'); |
| 50 | + }); |
| 51 | + |
| 52 | + test('ionViewDidEnter should fire on tab child page when navigating back to tabs', async ({ page }, testInfo) => { |
| 53 | + testInfo.annotations.push({ |
| 54 | + type: 'issue', |
| 55 | + description: 'https://outsystemsrd.atlassian.net/browse/FW-6788', |
| 56 | + }); |
| 57 | + |
| 58 | + await page.goto(withTestingMode('/tab-lifecycle/home')); |
| 59 | + await ionPageVisible(page, 'tab-lifecycle-home'); |
| 60 | + |
| 61 | + await page.locator('#go-outside').click(); |
| 62 | + await ionPageVisible(page, 'tab-lifecycle-outside'); |
| 63 | + |
| 64 | + await page.evaluate(() => { (window as any).lifecycleEvents = []; }); |
| 65 | + |
| 66 | + await page.locator('#go-back-to-tabs').click(); |
| 67 | + await ionPageVisible(page, 'tab-lifecycle-home'); |
| 68 | + |
| 69 | + const events = await page.evaluate(() => (window as any).lifecycleEvents as string[]); |
| 70 | + expect(events).toContain('home:ionViewWillEnter'); |
| 71 | + expect(events).toContain('home:ionViewDidEnter'); |
| 72 | + }); |
| 73 | +}); |
0 commit comments