-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proper child reconciliation for web components with slots. (#762)
- Loading branch information
1 parent
17b9c18
commit 5e02e37
Showing
6 changed files
with
112 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,61 @@ | ||
import {test, expect, Page} from '@playwright/test'; | ||
|
||
test.describe(() => { | ||
// All tests in this describe group will get 2 retry attempts. | ||
test.describe.configure({retries: 2}); | ||
test('web components - slot', async ({page}) => { | ||
await page.goto('http://localhost:32123/web_component/slot/slot_app'); | ||
// Make sure the page has loaded: | ||
expect(page.getByRole('button', {name: 'Decrement'})).toBeVisible(); | ||
|
||
assertValue(10); | ||
await page.getByRole('button', {name: 'increment'}).click(); | ||
assertValue(11); | ||
await page.getByRole('button', {name: 'increment'}).click(); | ||
assertValue(12); | ||
await page.getByRole('button', {name: 'Decrement'}).click(); | ||
assertValue(11); | ||
await page.getByRole('button', {name: 'Decrement'}).click(); | ||
assertValue(10); | ||
|
||
async function assertValue(value: number) { | ||
// Check that the outer component is displaying the right value. | ||
expect( | ||
await page | ||
.locator('div') | ||
.filter({hasText: `Value: ${value} increment Start of`}) | ||
.textContent(), | ||
).toContain(value.toString()); | ||
|
||
// Check that the inner component is displaying the right value. | ||
expect( | ||
await page | ||
.locator('slot-counter-component') | ||
.getByText('Value:') | ||
.textContent(), | ||
).toContain(value.toString()); | ||
} | ||
}); | ||
test('web components - slot', async ({page}) => { | ||
await page.goto('/web_component/slot/slot_app'); | ||
|
||
// Make sure the page has loaded: | ||
expect(page.getByRole('button', {name: 'Decrement'})).toBeVisible(); | ||
|
||
await assertValue(10); | ||
await page.getByRole('button', {name: 'increment'}).click(); | ||
await assertValue(11); | ||
await page.getByRole('button', {name: 'increment'}).click(); | ||
await assertValue(12); | ||
await page.getByRole('button', {name: 'Decrement'}).click(); | ||
await assertValue(11); | ||
await page.getByRole('button', {name: 'Decrement'}).click(); | ||
await assertValue(10); | ||
|
||
async function assertValue(value: number) { | ||
// Check that the outer component is displaying the right value. | ||
expect( | ||
await page | ||
.locator('#outer-value') | ||
.filter({hasText: `Value: ${value}`}) | ||
.textContent(), | ||
).toContain(value.toString()); | ||
|
||
// Check that the inner component is displaying the right value. | ||
expect( | ||
await page | ||
.locator('slot-counter-component') | ||
.getByText('Value:') | ||
.textContent(), | ||
).toContain(value.toString()); | ||
} | ||
}); | ||
|
||
test('web components - slot child reconciliation', async ({page}) => { | ||
await page.goto('/web_component/slot/slot_app'); | ||
await page.getByLabel('input slot').click(); | ||
await page.getByLabel('input slot').fill('abc'); | ||
|
||
await page.locator('slot-counter-component').getByRole('textbox').click(); | ||
await page.locator('slot-counter-component').getByRole('textbox').fill('def'); | ||
|
||
await page.getByRole('button', {name: 'Decrement'}).click(); | ||
await page.getByRole('button', {name: 'add checkbox slot'}).click(); | ||
|
||
await page.getByRole('checkbox').click(); | ||
|
||
// Assertions | ||
await expect(page.getByRole('checkbox')).toBeChecked(); | ||
await expect(page.getByText('Checked? true')).toBeVisible(); | ||
expect(await page.getByLabel('input slot').inputValue()).toEqual('abc'); | ||
expect( | ||
await page | ||
.locator('slot-counter-component') | ||
.getByRole('textbox') | ||
.inputValue(), | ||
).toEqual('def'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters