Skip to content

Commit 6ff1ba2

Browse files
committed
Convert Component Test list/Chip.mjs to Playwright #7703
1 parent 90ba3a7 commit 6ff1ba2

File tree

2 files changed

+99
-1
lines changed

2 files changed

+99
-1
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import {test, expect} from '@playwright/test';
2+
3+
test.describe('ChipListComponent', () => {
4+
let componentId;
5+
6+
const config = {
7+
importPath : '../list/Chip.mjs', // relative to the App worker
8+
ntype : 'chip-list',
9+
parentId : 'component-test-viewport',
10+
displayField: 'firstname',
11+
width : 300,
12+
role : 'listbox',
13+
itemRole : 'option',
14+
navigator : {wrap: true},
15+
store: {
16+
keyProperty: 'githubId',
17+
model: {
18+
fields: [
19+
{ name: 'country', type: 'String' },
20+
{ name: 'firstname', type: 'String' },
21+
{ name: 'githubId', type: 'String' },
22+
{ name: 'lastname', type: 'String' }
23+
]
24+
},
25+
data: [
26+
{ country: 'Germany', firstname: 'Tobias', githubId: 'tobiu', lastname: 'Uhlig' },
27+
{ country: 'USA', firstname: 'Rich', githubId: 'rwaters', lastname: 'Waters' },
28+
{ country: 'Germany', firstname: 'Nils', githubId: 'mrsunshine', lastname: 'Dehl' },
29+
{ country: 'USA', firstname: 'Gerard', githubId: 'camtnbikerrwc', lastname: 'Horan' },
30+
{ country: 'Slovakia', firstname: 'Jozef', githubId: 'jsakalos', lastname: 'Sakalos' },
31+
{ country: 'Germany', firstname: 'Bastian', githubId: 'bhaustein', lastname: 'Haustein' }
32+
]
33+
}
34+
};
35+
36+
test.beforeEach(async ({page}) => {
37+
await page.goto('/test/playwright/component/apps/empty-viewport/index.html');
38+
await page.waitForSelector('#component-test-viewport');
39+
componentId = await page.evaluate((config) => {
40+
return Neo.worker.App.createNeoInstance(config);
41+
}, config);
42+
});
43+
44+
test.afterEach(async ({page}) => {
45+
if (componentId) {
46+
await page.evaluate((id) => {
47+
return Neo.worker.App.destroyNeoInstance(id);
48+
}, componentId);
49+
}
50+
});
51+
52+
test('Sanity', async ({page}) => {
53+
const listSelector = `#${componentId}`;
54+
55+
await page.waitForSelector(listSelector);
56+
57+
// Click on the *item*, *not* the focusable chip.
58+
await page.click(`${listSelector} .neo-list-item`);
59+
60+
// That should select and activate the clicked item.
61+
// And focus the chip inside it.
62+
await expect(page.locator(`${listSelector} .neo-list-item.neo-navigator-active-item.neo-selected:nth-child(1) .neo-chip`)).toBeFocused();
63+
await expect(page.locator(`${listSelector} .neo-list-item.neo-navigator-active-item`)).toHaveCount(1);
64+
65+
await page.keyboard.press('End');
66+
67+
// That should select and activate the last item.
68+
// And focus the chip inside it.
69+
await expect(page.locator(`${listSelector} .neo-list-item.neo-navigator-active-item:not(.neo-selected):nth-child(6) .neo-chip`)).toBeFocused();
70+
71+
// Item 1 is still the only one selected, and it's not focused
72+
await expect(page.locator(`${listSelector} .neo-list-item.neo-selected:nth-child(1) .neo-chip:not(:focus)`)).toHaveCount(1);
73+
await expect(page.locator(`${listSelector} .neo-list-item.neo-selected`)).toHaveCount(1);
74+
await expect(page.locator(`${listSelector} .neo-list-item.neo-navigator-active-item`)).toHaveCount(1);
75+
76+
await page.keyboard.press('Enter');
77+
78+
// Item 6 is now the only one selected
79+
await expect(page.locator(`${listSelector} .neo-list-item.neo-navigator-active-item.neo-selected:nth-child(6) .neo-chip`)).toBeFocused();
80+
await expect(page.locator(`${listSelector} .neo-list-item.neo-selected`)).toHaveCount(1);
81+
await expect(page.locator(`${listSelector} .neo-list-item.neo-navigator-active-item`)).toHaveCount(1);
82+
83+
await page.keyboard.press('ArrowDown');
84+
85+
// That should select and activate the first item.
86+
// And focus the chip inside it.
87+
await expect(page.locator(`${listSelector} .neo-list-item.neo-navigator-active-item:not(.neo-selected):nth-child(1) .neo-chip`)).toBeFocused();
88+
await expect(page.locator(`${listSelector} .neo-list-item.neo-selected`)).toHaveCount(1);
89+
await expect(page.locator(`${listSelector} .neo-list-item.neo-navigator-active-item`)).toHaveCount(1);
90+
91+
await page.keyboard.press('ArrowUp');
92+
93+
// Item 6 is now the only one selected
94+
await expect(page.locator(`${listSelector} .neo-list-item.neo-navigator-active-item.neo-selected:nth-child(6) .neo-chip`)).toBeFocused();
95+
await expect(page.locator(`${listSelector} .neo-list-item.neo-selected`)).toHaveCount(1);
96+
await expect(page.locator(`${listSelector} .neo-list-item.neo-navigator-active-item`)).toHaveCount(1);
97+
});
98+
});

test/playwright/playwright.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const __dirname = path.dirname(__filename);
77

88
export default defineConfig({
99
testDir : __dirname,
10-
testMatch : [/unit\/.*\.mjs/, /component\/specs\/.*\.mjs/, /mcp\/.*\.mjs/],
10+
testMatch : /.*\.spec\.mjs/,
1111
outputDir : path.join(__dirname, 'test-results/all'),
1212
fullyParallel: false,
1313
forbidOnly : !!process.env.CI,

0 commit comments

Comments
 (0)