|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +const hostUrl = 'http://localhost:3001'; |
| 4 | +const remoteUrl = 'http://localhost:3002'; |
| 5 | + |
| 6 | +test.describe('CSS isolation example', () => { |
| 7 | + test.describe('host application', () => { |
| 8 | + test.beforeEach(async ({ page }) => { |
| 9 | + await page.goto(hostUrl); |
| 10 | + }); |
| 11 | + |
| 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(); |
| 17 | + }); |
| 18 | + |
| 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' }); |
| 31 | + |
| 32 | + await expect(remoteHeading).toBeVisible(); |
| 33 | + await expect(remoteButton).toBeVisible(); |
| 34 | + |
| 35 | + await expect( |
| 36 | + page.getByRole('heading', { level: 1, name: /Host Application - React Version/ }), |
| 37 | + ).toHaveCSS('font-style', 'italic'); |
| 38 | + }); |
| 39 | + |
| 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 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + test.describe('standalone remote application', () => { |
| 55 | + test.beforeEach(async ({ page }) => { |
| 56 | + await page.goto(remoteUrl); |
| 57 | + }); |
| 58 | + |
| 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 | + }); |
| 66 | + |
| 67 | + test('applies yellow styles after clicking the button', async ({ page }) => { |
| 68 | + const button = page.getByRole('button', { name: 'Make Everything Yellow' }); |
| 69 | + await button.click(); |
| 70 | + |
| 71 | + await expect(page.locator('#root')).toHaveCSS('background-color', 'rgb(255, 255, 0)'); |
| 72 | + await expect(button).toHaveCSS('background-color', 'rgb(255, 255, 0)'); |
| 73 | + }); |
| 74 | + }); |
| 75 | +}); |
0 commit comments