|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | +import { |
| 3 | + addComponentsToCanvas, |
| 4 | + dragAndDrop, |
| 5 | + getWithinCanvasItemList, |
| 6 | +} from '../helpers'; |
| 7 | +import { E2E_CanvasItemKeyAttrs } from '../helpers/types/e2e-types'; |
| 8 | +import { |
| 9 | + clickCopyUiButton, |
| 10 | + clickPasteUiButton, |
| 11 | +} from '../helpers/ui-buttons.helpers'; |
| 12 | + |
| 13 | +test.describe('Copy/Paste functionality tests', () => { |
| 14 | + test.beforeEach(async ({ page }) => { |
| 15 | + await page.goto(''); |
| 16 | + }); |
| 17 | + |
| 18 | + test('Should copy and paste a single shape using the ToolBar UI buttons', async ({ |
| 19 | + page, |
| 20 | + }) => { |
| 21 | + //Arrange one Input component |
| 22 | + const addInputIntoCanvas = ['Input']; |
| 23 | + await addComponentsToCanvas(page, addInputIntoCanvas); |
| 24 | + |
| 25 | + //Copy and assert there are only one component within the canvas |
| 26 | + await clickCopyUiButton(page); |
| 27 | + const insideCanvasItemList = (await getWithinCanvasItemList( |
| 28 | + page |
| 29 | + )) as E2E_CanvasItemKeyAttrs[]; |
| 30 | + expect(insideCanvasItemList.length).toEqual(1); |
| 31 | + |
| 32 | + //Paste and assert there are 2 Input Components and that they have different IDs |
| 33 | + await clickPasteUiButton(page); |
| 34 | + const updatedInsideCanvasItemList = (await getWithinCanvasItemList( |
| 35 | + page |
| 36 | + )) as E2E_CanvasItemKeyAttrs[]; |
| 37 | + const [originalComponent, copiedComponent] = updatedInsideCanvasItemList; |
| 38 | + |
| 39 | + expect(updatedInsideCanvasItemList.length).toEqual(2); |
| 40 | + expect(originalComponent.shapeType).toEqual(copiedComponent.shapeType); |
| 41 | + expect(originalComponent['data-id']).not.toEqual( |
| 42 | + copiedComponent['data-id'] |
| 43 | + ); |
| 44 | + }); |
| 45 | + |
| 46 | + test('Should copy and paste a single shape using keyboard commands', async ({ |
| 47 | + page, |
| 48 | + }) => { |
| 49 | + // NOTE: This test has the same steps as the previous one, except for the keyboard commands. |
| 50 | + //Arrange one Input component |
| 51 | + const addInputIntoCanvas = ['Input']; |
| 52 | + await addComponentsToCanvas(page, addInputIntoCanvas); |
| 53 | + |
| 54 | + //Copy and assert there are only one component within the canvas |
| 55 | + await page.keyboard.press('ControlOrMeta+c'); |
| 56 | + const insideCanvasItemList = (await getWithinCanvasItemList( |
| 57 | + page |
| 58 | + )) as E2E_CanvasItemKeyAttrs[]; |
| 59 | + expect(insideCanvasItemList.length).toEqual(1); |
| 60 | + |
| 61 | + //Paste and assert there are 2 Input Components and that they have different IDs |
| 62 | + await page.keyboard.press('ControlOrMeta+v'); |
| 63 | + const updatedInsideCanvasItemList = (await getWithinCanvasItemList( |
| 64 | + page |
| 65 | + )) as E2E_CanvasItemKeyAttrs[]; |
| 66 | + const [originalComponent, copiedComponent] = updatedInsideCanvasItemList; |
| 67 | + |
| 68 | + expect(updatedInsideCanvasItemList.length).toEqual(2); |
| 69 | + expect(originalComponent.shapeType).toEqual(copiedComponent.shapeType); |
| 70 | + expect(originalComponent['data-id']).not.toEqual( |
| 71 | + copiedComponent['data-id'] |
| 72 | + ); |
| 73 | + }); |
| 74 | + |
| 75 | + /* |
| 76 | + test('Should copy and paste a multiple shapes using the ToolBar UI buttons', async ({ |
| 77 | + page, |
| 78 | + }) => { |
| 79 | + //Add several components into the canvas |
| 80 | + const addInputIntoCanvas = ['Input', 'Combobox', 'Icon']; |
| 81 | + await addComponentsToCanvas(page, addInputIntoCanvas); |
| 82 | +
|
| 83 | + //Select items by drag and drop |
| 84 | + await dragAndDrop(page, { x: 260, y: 130 }, { x: 1000, y: 550 }); |
| 85 | +
|
| 86 | + //Copy and assert there are 3 components within the canvas |
| 87 | + await clickCopyUiButton(page); |
| 88 | + const insideCanvasItemList = (await getWithinCanvasItemList( |
| 89 | + page |
| 90 | + )) as E2E_CanvasItemKeyAttrs[]; |
| 91 | + const [originalComp_1, originalComp_2, originalComp_3] = |
| 92 | + insideCanvasItemList; |
| 93 | + expect(insideCanvasItemList.length).toEqual(3); |
| 94 | +
|
| 95 | + //Paste |
| 96 | + await clickPasteUiButton(page); |
| 97 | + const updatedInsideCanvasItemList = (await getWithinCanvasItemList( |
| 98 | + page |
| 99 | + )) as E2E_CanvasItemKeyAttrs[]; |
| 100 | + const [, , , copiedComp_1, copiedComp_2, copiedComp_3] = |
| 101 | + updatedInsideCanvasItemList; |
| 102 | +
|
| 103 | + //Assert there are 6 Components, |
| 104 | + expect(updatedInsideCanvasItemList.length).toEqual(6); |
| 105 | +
|
| 106 | + //Assert they match the same shapes respectively |
| 107 | + expect(originalComp_1.shapeType).toEqual(copiedComp_1.shapeType); |
| 108 | + expect(originalComp_2.shapeType).toEqual(copiedComp_2.shapeType); |
| 109 | + expect(originalComp_3.shapeType).toEqual(copiedComp_3.shapeType); |
| 110 | +
|
| 111 | + //Assert they have different IDs |
| 112 | + expect(originalComp_1['data-id']).not.toEqual(copiedComp_1['data-id']); |
| 113 | + expect(originalComp_2['data-id']).not.toEqual(copiedComp_2['data-id']); |
| 114 | + expect(originalComp_3['data-id']).not.toEqual(copiedComp_3['data-id']); |
| 115 | + }); |
| 116 | +*/ |
| 117 | + test('Should copy and paste a multiple shapes using keyboard commands', async ({ |
| 118 | + page, |
| 119 | + }) => { |
| 120 | + // NOTE: This test has the same steps as the previous one, except for the keyboard commands. |
| 121 | + //Add several components into the canvas |
| 122 | + const addInputIntoCanvas = ['Input', 'Combobox', 'Icon']; |
| 123 | + await addComponentsToCanvas(page, addInputIntoCanvas); |
| 124 | + |
| 125 | + //Select items by drag and drop |
| 126 | + await dragAndDrop(page, { x: 260, y: 130 }, { x: 1000, y: 550 }); |
| 127 | + |
| 128 | + //Copy and assert there are 3 components within the canvas |
| 129 | + await page.keyboard.press('ControlOrMeta+c'); |
| 130 | + const insideCanvasItemList = (await getWithinCanvasItemList( |
| 131 | + page |
| 132 | + )) as E2E_CanvasItemKeyAttrs[]; |
| 133 | + const [originalComp_1, originalComp_2, originalComp_3] = |
| 134 | + insideCanvasItemList; |
| 135 | + expect(insideCanvasItemList.length).toEqual(3); |
| 136 | + |
| 137 | + //Paste |
| 138 | + await page.keyboard.press('ControlOrMeta+v'); |
| 139 | + const updatedInsideCanvasItemList = (await getWithinCanvasItemList( |
| 140 | + page |
| 141 | + )) as E2E_CanvasItemKeyAttrs[]; |
| 142 | + const [, , , copiedComp_1, copiedComp_2, copiedComp_3] = |
| 143 | + updatedInsideCanvasItemList; |
| 144 | + |
| 145 | + //Assert there are 6 Components, |
| 146 | + expect(updatedInsideCanvasItemList.length).toEqual(6); |
| 147 | + |
| 148 | + //Assert they match the same shapes respectively |
| 149 | + expect(originalComp_1.shapeType).toEqual(copiedComp_1.shapeType); |
| 150 | + expect(originalComp_2.shapeType).toEqual(copiedComp_2.shapeType); |
| 151 | + expect(originalComp_3.shapeType).toEqual(copiedComp_3.shapeType); |
| 152 | + |
| 153 | + //Assert they have different IDs |
| 154 | + expect(originalComp_1['data-id']).not.toEqual(copiedComp_1['data-id']); |
| 155 | + expect(originalComp_2['data-id']).not.toEqual(copiedComp_2['data-id']); |
| 156 | + expect(originalComp_3['data-id']).not.toEqual(copiedComp_3['data-id']); |
| 157 | + }); |
| 158 | +}); |
0 commit comments