|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +const ROOT_SELECTOR = '[data-testid="test-render-cycle-root"]'; |
| 4 | +const EDITOR_SELECTOR = `${ROOT_SELECTOR} .eti-editor [contenteditable="true"]`; |
| 5 | +const TOGGLE_BUTTON_SELECTOR = '[data-testid="toggle-variant-button"]'; |
| 6 | +const VARIANT_OUTPUT_SELECTOR = '[data-testid="variant-output"]'; |
| 7 | +const PAGE_PATH = '/test-render-cycle'; |
| 8 | + |
| 9 | +test.describe('EnrichedTextInput render cycle', () => { |
| 10 | + test('does not throw on simultaneous defaultValue and htmlStyle change', async ({ |
| 11 | + page, |
| 12 | + }) => { |
| 13 | + const pageErrors: Error[] = []; |
| 14 | + const consoleErrors: string[] = []; |
| 15 | + |
| 16 | + page.on('pageerror', (error) => pageErrors.push(error)); |
| 17 | + page.on('console', (message) => { |
| 18 | + if (message.type() === 'error') { |
| 19 | + consoleErrors.push(message.text()); |
| 20 | + } |
| 21 | + }); |
| 22 | + |
| 23 | + await page.goto(PAGE_PATH); |
| 24 | + await page.waitForSelector(EDITOR_SELECTOR); |
| 25 | + |
| 26 | + await expect(page.locator(EDITOR_SELECTOR)).toContainText('Variant A'); |
| 27 | + |
| 28 | + await page.click(TOGGLE_BUTTON_SELECTOR); |
| 29 | + await expect(page.locator(VARIANT_OUTPUT_SELECTOR)).toHaveText('b'); |
| 30 | + await expect(page.locator(EDITOR_SELECTOR)).toContainText('Variant B'); |
| 31 | + |
| 32 | + await page.click(TOGGLE_BUTTON_SELECTOR); |
| 33 | + await expect(page.locator(VARIANT_OUTPUT_SELECTOR)).toHaveText('a'); |
| 34 | + await expect(page.locator(EDITOR_SELECTOR)).toContainText('Variant A'); |
| 35 | + |
| 36 | + const editor = page.locator(EDITOR_SELECTOR); |
| 37 | + await editor.click(); |
| 38 | + await expect(editor).toBeFocused(); |
| 39 | + await editor.pressSequentially(' more text'); |
| 40 | + await expect(editor).toContainText('Variant A more text'); |
| 41 | + |
| 42 | + expect(pageErrors).toEqual([]); |
| 43 | + expect(consoleErrors).toEqual([]); |
| 44 | + }); |
| 45 | +}); |
0 commit comments