Skip to content

Commit 73f7b3f

Browse files
test(item-sliding): add test for side issue with CDN (#30469)
Adds test for #29845 Must be merged after the fix in that PR is released. The test will fail while using the older version of the CDN. --------- Co-authored-by: Brandy Smith <[email protected]>
1 parent 498f7c7 commit 73f7b3f

File tree

3 files changed

+111
-2
lines changed

3 files changed

+111
-2
lines changed

core/src/components/item-sliding/test/async/item-sliding.e2e.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { expect } from '@playwright/test';
22
import { configs, test } from '@utils/test/playwright';
33

4+
/**
5+
* This behavior does not vary across modes/directions
6+
*/
47
configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) => {
58
test.describe(title('item-sliding: async'), () => {
69
test.beforeEach(async ({ page }) => {
@@ -35,5 +38,85 @@ configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, config }) =>
3538

3639
await expect(itemSlidingEl).toHaveClass(/item-sliding-active-slide/);
3740
});
41+
42+
// NOTE: This test uses the CDN version of Ionic.
43+
// If this test fails, it is likely due to a regression in the published package.
44+
test('should not throw errors when adding multiple items with side="end" using the Ionic CDN', async ({
45+
page,
46+
}, testInfo) => {
47+
testInfo.annotations.push({
48+
type: 'issue',
49+
description: 'https://github.com/ionic-team/ionic-framework/issues/29499',
50+
});
51+
52+
const errors: string[] = [];
53+
page.on('console', (msg) => {
54+
if (msg.type() === 'error') {
55+
errors.push(msg.text());
56+
}
57+
});
58+
page.on('pageerror', (error) => {
59+
errors.push(error.message);
60+
});
61+
62+
// This issue only happens when using a CDN version of Ionic
63+
// so we need to use the CDN by passing the `importIonicFromCDN` option
64+
// to setContent.
65+
await page.setContent(
66+
`
67+
<ion-header>
68+
<ion-toolbar>
69+
<ion-title>Item Sliding</ion-title>
70+
<ion-buttons slot="end">
71+
<ion-button id="addItem" onclick="addItem()">ADD ITEM</ion-button>
72+
</ion-buttons>
73+
</ion-toolbar>
74+
</ion-header>
75+
<ion-content>
76+
<ion-list id="list"></ion-list>
77+
</ion-content>
78+
79+
<script>
80+
let itemList = [];
81+
function generateItem() {
82+
const currentItem = itemList.length + 1;
83+
const item = \`
84+
<ion-item-sliding>
85+
<ion-item>
86+
<ion-label>Sliding Item \${currentItem}</ion-label>
87+
</ion-item>
88+
<ion-item-options side="end">
89+
<ion-item-option>Delete</ion-item-option>
90+
</ion-item-options>
91+
</ion-item-sliding>
92+
\`;
93+
itemList.push(item);
94+
return item;
95+
}
96+
function addItem() {
97+
const list = document.getElementById('list');
98+
list.innerHTML += generateItem();
99+
const currentItem = itemList.length;
100+
}
101+
</script>
102+
`,
103+
{ ...config, importIonicFromCDN: true }
104+
);
105+
106+
// Click the button enough times to reproduce the issue
107+
const addButton = page.locator('#addItem');
108+
await addButton.click();
109+
await addButton.click();
110+
await addButton.click();
111+
112+
await page.waitForChanges();
113+
114+
// Check that the items have been added
115+
const items = page.locator('ion-item-sliding');
116+
expect(await items.count()).toBe(3);
117+
118+
// Check that no errors have been logged
119+
expect(errors.length).toBe(0);
120+
});
38121
});
39122
});

core/src/utils/test/playwright/page/utils/set-content.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,38 @@ export const setContent = async (page: Page, html: string, testInfo: TestInfo, o
3333

3434
const baseUrl = process.env.PLAYWRIGHT_TEST_BASE_URL;
3535

36+
// The Ionic bundle is included locally by default unless the test
37+
// config passes in the importIonicFromCDN option. This is useful
38+
// when testing with the CDN version of Ionic.
39+
let ionicCSSImports = `
40+
<link href="${baseUrl}/css/ionic.bundle.css" rel="stylesheet" />
41+
`;
42+
let ionicJSImports = `
43+
<script type="module" src="${baseUrl}/dist/ionic/ionic.esm.js"></script>
44+
`;
45+
46+
if (options?.importIonicFromCDN) {
47+
ionicCSSImports = `
48+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core/css/ionic.bundle.css" />
49+
`;
50+
ionicJSImports = `
51+
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.esm.js"></script>
52+
<script nomodule src="https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.js"></script>
53+
`;
54+
}
55+
3656
const output = `
3757
<!DOCTYPE html>
3858
<html dir="${direction}" lang="en">
3959
<head>
4060
<title>Ionic Playwright Test</title>
4161
<meta charset="UTF-8" />
4262
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
43-
<link href="${baseUrl}/css/ionic.bundle.css" rel="stylesheet" />
63+
${ionicCSSImports}
4464
<link href="${baseUrl}/scripts/testing/styles.css" rel="stylesheet" />
4565
${palette !== 'light' ? `<link href="${baseUrl}/css/palettes/${palette}.always.css" rel="stylesheet" />` : ''}
4666
<script src="${baseUrl}/scripts/testing/scripts.js"></script>
47-
<script type="module" src="${baseUrl}/dist/ionic/ionic.esm.js"></script>
67+
${ionicJSImports}
4868
<script>
4969
window.Ionic = {
5070
config: {

core/src/utils/test/playwright/playwright-declarations.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ interface PageOptions {
3131
* - `'commit'` - consider operation to be finished when network response is received and the document started loading.
3232
*/
3333
waitUntil?: 'load' | 'domcontentloaded' | 'networkidle' | 'commit';
34+
35+
/**
36+
* If true, the default Ionic imports will be included
37+
* via the CDN instead of the local bundle.
38+
*/
39+
importIonicFromCDN?: boolean;
3440
}
3541

3642
export interface E2EPage extends Page {

0 commit comments

Comments
 (0)