|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | +import { |
| 3 | + addComponentsToCanvas, |
| 4 | + getByShapeType, |
| 5 | + getByShapeTypeInThumb, |
| 6 | +} from '../helpers'; |
| 7 | +import { Group } from 'konva/lib/Group'; |
| 8 | + |
| 9 | +test('should duplicate thumbpage when triggered via the arrow icon', async ({ |
| 10 | + page, |
| 11 | +}) => { |
| 12 | + await page.goto(''); |
| 13 | + |
| 14 | + // Add components to canvas |
| 15 | + await addComponentsToCanvas(page, ['Button', 'Combobox']); |
| 16 | + |
| 17 | + await page.getByText('Pages').click(); |
| 18 | + |
| 19 | + // Find thumb page |
| 20 | + const siblingElement = page.getByText('Page 1', { exact: true }); |
| 21 | + const thumb = siblingElement.locator('..'); |
| 22 | + |
| 23 | + // Select arrow svg inside the thumb container |
| 24 | + const svgElement = thumb.locator('span > svg'); |
| 25 | + await svgElement.click(); |
| 26 | + |
| 27 | + // Verify duplicate button exists in the context menu |
| 28 | + const duplicateButton = page |
| 29 | + .locator('div') |
| 30 | + .filter({ hasText: /^Duplicate$/ }); |
| 31 | + |
| 32 | + await expect(duplicateButton).toBeVisible(); |
| 33 | + |
| 34 | + // Duplicate thumbpage |
| 35 | + await duplicateButton.click(); |
| 36 | + |
| 37 | + // Verify Page 1 - copy exists and its selected |
| 38 | + const pageTwo = page |
| 39 | + .getByText('Page 1 - copy', { exact: true }) |
| 40 | + .locator('..'); |
| 41 | + await expect(pageTwo).toBeVisible(); |
| 42 | + |
| 43 | + // Additional click to force the duplicate thumbnail to finish rendering. |
| 44 | + await pageTwo.click(); |
| 45 | + // Without this click, the React/Konva pipeline does not always update on time and the |
| 46 | + // assertions fail intermittently. |
| 47 | + |
| 48 | + // Verify components exist in copy thumb |
| 49 | + const buttonInCopyThumb = await getByShapeTypeInThumb(page, 1, 'button'); |
| 50 | + const comboboxInCopyThumb = await getByShapeTypeInThumb(page, 1, 'combobox'); |
| 51 | + expect(buttonInCopyThumb).toBeDefined(); |
| 52 | + expect(comboboxInCopyThumb).toBeDefined(); |
| 53 | + |
| 54 | + // Verify components exist in copy canvas |
| 55 | + const buttonShape = (await getByShapeType(page, 'button')) as Group; |
| 56 | + const comboboxShape = (await getByShapeType(page, 'combobox')) as Group; |
| 57 | + expect(buttonShape).toBeDefined(); |
| 58 | + expect(comboboxShape).toBeDefined(); |
| 59 | +}); |
0 commit comments