Skip to content

Commit 8a63603

Browse files
test(css-isolation): expand playwright host coverage
1 parent 7ad0886 commit 8a63603

File tree

1 file changed

+54
-30
lines changed

1 file changed

+54
-30
lines changed

css-isolation/e2e/checkApplications.spec.ts

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,74 @@
11
import { test, expect } from '@playwright/test';
22

3-
const apps = [
4-
{
5-
name: 'App 1',
6-
header: 'Host Application - React Version',
7-
url: 'http://localhost:3001',
8-
},
9-
{
10-
name: 'App 2',
11-
header: 'Remote Application - React Version',
12-
url: 'http://localhost:3002',
13-
},
14-
];
3+
const hostUrl = 'http://localhost:3001';
4+
const remoteUrl = 'http://localhost:3002';
155

166
test.describe('CSS isolation example', () => {
17-
for (const { name, header, url } of apps) {
18-
test(`${name} renders expected headings`, async ({ page }) => {
19-
await page.goto(url);
7+
test.describe('host application', () => {
8+
test.beforeEach(async ({ page }) => {
9+
await page.goto(hostUrl);
10+
});
2011

21-
const heading = page.getByRole('heading', { level: 1, name: new RegExp(header) });
22-
await expect(heading).toBeVisible();
23-
await expect(page.getByRole('heading', { level: 2, name })).toHaveText(name);
12+
test('renders host headings', async ({ page }) => {
13+
await expect(
14+
page.getByRole('heading', { level: 1, name: /Host Application - React Version/ }),
15+
).toBeVisible();
16+
await expect(page.getByRole('heading', { level: 2, name: 'App 1' })).toBeVisible();
2417
});
25-
}
2618

27-
test('host renders remote button inside shadow DOM', async ({ page }) => {
28-
await page.goto('http://localhost:3001');
19+
test('mounts the remote inside a shadow DOM', async ({ page }) => {
20+
const remoteMount = page.locator('#parent');
21+
await expect(remoteMount).toBeVisible();
22+
23+
const hasShadowRoot = await remoteMount.evaluate(element => Boolean(element.shadowRoot));
24+
expect(hasShadowRoot).toBe(true);
25+
26+
const remoteHeading = remoteMount.getByRole('heading', {
27+
level: 1,
28+
name: /Remote Application - React Version/,
29+
});
30+
const remoteButton = remoteMount.getByRole('button', { name: 'Make Everything Yellow' });
2931

30-
const buttonTextHandle = await page.waitForFunction(() => {
31-
const host = document.querySelector('#parent');
32+
await expect(remoteHeading).toBeVisible();
33+
await expect(remoteButton).toBeVisible();
3234

33-
return host?.shadowRoot?.querySelector('button')?.textContent?.trim() ?? null;
35+
await expect(
36+
page.getByRole('heading', { level: 1, name: /Host Application - React Version/ }),
37+
).toHaveCSS('font-style', 'italic');
3438
});
3539

36-
expect(await buttonTextHandle.jsonValue()).toBe('Make Everything Yellow');
40+
test('retains host styles after interacting with the remote', async ({ page }) => {
41+
const remoteMount = page.locator('#parent');
42+
const remoteButton = remoteMount.getByRole('button', { name: 'Make Everything Yellow' });
43+
44+
await remoteButton.click();
45+
46+
await expect(remoteButton).toBeVisible();
47+
await expect(remoteMount.getByRole('heading', { level: 2, name: 'App 2' })).toBeVisible();
48+
await expect(
49+
page.getByRole('heading', { level: 1, name: /Host Application - React Version/ }),
50+
).toHaveCSS('font-style', 'italic');
51+
});
3752
});
3853

39-
test.describe('standalone remote', () => {
40-
test('button applies yellow styles after click', async ({ page }) => {
41-
await page.goto('http://localhost:3002');
54+
test.describe('standalone remote application', () => {
55+
test.beforeEach(async ({ page }) => {
56+
await page.goto(remoteUrl);
57+
});
4258

43-
const button = page.getByRole('button', { name: 'Make Everything Yellow' });
44-
await expect(button).toBeVisible();
59+
test('renders remote headings and button', async ({ page }) => {
60+
await expect(
61+
page.getByRole('heading', { level: 1, name: /Remote Application - React Version/ }),
62+
).toBeVisible();
63+
await expect(page.getByRole('heading', { level: 2, name: 'App 2' })).toBeVisible();
64+
await expect(page.getByRole('button', { name: 'Make Everything Yellow' })).toBeVisible();
65+
});
4566

67+
test('applies yellow styles after clicking the button', async ({ page }) => {
68+
const button = page.getByRole('button', { name: 'Make Everything Yellow' });
4669
await button.click();
4770

71+
await expect(page.locator('#root')).toHaveCSS('background-color', 'rgb(255, 255, 0)');
4872
await expect(button).toHaveCSS('background-color', 'rgb(255, 255, 0)');
4973
});
5074
});

0 commit comments

Comments
 (0)