|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { configs, test } from '@utils/test/playwright'; |
| 3 | + |
| 4 | +/** |
| 5 | + * Tests for keyboard controller memory leak fix when tab-bar |
| 6 | + * is rapidly mounted/unmounted. |
| 7 | + */ |
| 8 | +configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => { |
| 9 | + test.describe(title('tab-bar: lifecycle'), () => { |
| 10 | + test('should not error when rapidly mounting and unmounting', async ({ page }) => { |
| 11 | + const errors: string[] = []; |
| 12 | + page.on('console', (msg) => { |
| 13 | + if (msg.type() === 'error') { |
| 14 | + errors.push(msg.text()); |
| 15 | + } |
| 16 | + }); |
| 17 | + |
| 18 | + await page.setContent( |
| 19 | + ` |
| 20 | + <div id="container"></div> |
| 21 | + <script> |
| 22 | + const container = document.getElementById('container'); |
| 23 | +
|
| 24 | + for (let i = 0; i < 10; i++) { |
| 25 | + const tabBar = document.createElement('ion-tab-bar'); |
| 26 | + tabBar.innerHTML = \` |
| 27 | + <ion-tab-button tab="tab1"> |
| 28 | + <ion-label>Tab 1</ion-label> |
| 29 | + </ion-tab-button> |
| 30 | + \`; |
| 31 | + container.appendChild(tabBar); |
| 32 | + container.removeChild(tabBar); |
| 33 | + } |
| 34 | + </script> |
| 35 | + `, |
| 36 | + config |
| 37 | + ); |
| 38 | + |
| 39 | + await page.waitForTimeout(500); |
| 40 | + |
| 41 | + expect(errors.length).toBe(0); |
| 42 | + }); |
| 43 | + |
| 44 | + test('should cleanup keyboard controller when removed from DOM', async ({ page }, testInfo) => { |
| 45 | + testInfo.annotations.push({ |
| 46 | + type: 'issue', |
| 47 | + description: 'IONIC-82', |
| 48 | + }); |
| 49 | + |
| 50 | + const errors: string[] = []; |
| 51 | + page.on('console', (msg) => { |
| 52 | + if (msg.type() === 'error') { |
| 53 | + errors.push(msg.text()); |
| 54 | + } |
| 55 | + }); |
| 56 | + |
| 57 | + await page.setContent( |
| 58 | + ` |
| 59 | + <div id="container"> |
| 60 | + <ion-tab-bar id="test-tab-bar"> |
| 61 | + <ion-tab-button tab="tab1"> |
| 62 | + <ion-label>Tab 1</ion-label> |
| 63 | + </ion-tab-button> |
| 64 | + </ion-tab-bar> |
| 65 | + </div> |
| 66 | + `, |
| 67 | + config |
| 68 | + ); |
| 69 | + |
| 70 | + const tabBar = page.locator('#test-tab-bar'); |
| 71 | + await expect(tabBar).toBeVisible(); |
| 72 | + |
| 73 | + await page.evaluate(() => { |
| 74 | + document.getElementById('test-tab-bar')?.remove(); |
| 75 | + }); |
| 76 | + |
| 77 | + await page.waitForTimeout(100); |
| 78 | + |
| 79 | + await expect(tabBar).not.toBeAttached(); |
| 80 | + expect(errors.length).toBe(0); |
| 81 | + }); |
| 82 | + |
| 83 | + test('should handle re-mounting after unmount', async ({ page }) => { |
| 84 | + await page.setContent( |
| 85 | + ` |
| 86 | + <div id="container"></div> |
| 87 | + <script> |
| 88 | + const container = document.getElementById('container'); |
| 89 | +
|
| 90 | + async function testRemount() { |
| 91 | + const tabBar = document.createElement('ion-tab-bar'); |
| 92 | + tabBar.id = 'remount-tab-bar'; |
| 93 | + tabBar.innerHTML = \` |
| 94 | + <ion-tab-button tab="tab1"> |
| 95 | + <ion-label>Tab 1</ion-label> |
| 96 | + </ion-tab-button> |
| 97 | + \`; |
| 98 | + container.appendChild(tabBar); |
| 99 | +
|
| 100 | + await new Promise(r => setTimeout(r, 100)); |
| 101 | +
|
| 102 | + container.removeChild(tabBar); |
| 103 | +
|
| 104 | + await new Promise(r => setTimeout(r, 50)); |
| 105 | +
|
| 106 | + container.appendChild(tabBar); |
| 107 | + } |
| 108 | +
|
| 109 | + testRemount(); |
| 110 | + </script> |
| 111 | + `, |
| 112 | + config |
| 113 | + ); |
| 114 | + |
| 115 | + await page.waitForTimeout(500); |
| 116 | + |
| 117 | + const tabBar = page.locator('#remount-tab-bar'); |
| 118 | + await expect(tabBar).toBeVisible(); |
| 119 | + }); |
| 120 | + }); |
| 121 | +}); |
0 commit comments