Skip to content

Commit

Permalink
Fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
IonutGabi committed Nov 5, 2024
2 parents 82f9fba + 24699c2 commit 4c77562
Show file tree
Hide file tree
Showing 118 changed files with 1,897 additions and 319 deletions.
17 changes: 16 additions & 1 deletion e2e/helpers/konva-testing.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Layer } from 'konva/lib/Layer';
import { Shape } from 'konva/lib/Shape';
import { Group } from 'konva/lib/Group';
import { E2E_CanvasItemKeyAttrs } from './types/e2e-types';
import { getCanvasBoundingBox } from './position.helpers';

const getLayer = async (page: Page): Promise<Layer> =>
await page.evaluate(() => {
Expand Down Expand Up @@ -77,7 +78,8 @@ export const clickOnCanvasItem = async (
item: E2E_CanvasItemKeyAttrs
) => {
const { x, y } = item;
const canvasWindowPos = await page.locator('canvas').boundingBox();
const stageCanvas = await page.locator('#konva-stage canvas').first();
const canvasWindowPos = await stageCanvas.boundingBox();
if (!canvasWindowPos) throw new Error('Canvas is not loaded on ui');
await page.mouse.move(
canvasWindowPos?.x + x + 20,
Expand All @@ -90,6 +92,19 @@ export const clickOnCanvasItem = async (
return item;
};

export const dbClickOnCanvasItem = async (
page: Page,
item: E2E_CanvasItemKeyAttrs
) => {
const { x, y } = item;
const canvasWindowPos = await getCanvasBoundingBox(page);
await page.mouse.dblclick(
canvasWindowPos?.x + x + 20,
canvasWindowPos?.y + y + 20
);
return item;
};

export const ctrlClickOverCanvasItems = async (
page: Page,
itemList: E2E_CanvasItemKeyAttrs[]
Expand Down
14 changes: 13 additions & 1 deletion e2e/helpers/position.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ export const getLocatorPosition = async (
return { x: box.x + box.width / 2, y: box.y + box.height / 2 };
};

export const getCanvasBoundingBox = async (page: Page) => {
const canvasWindowPos = await page
.locator('#konva-stage canvas')
.boundingBox();
if (canvasWindowPos) {
return canvasWindowPos;
} else {
throw new Error('Canvas is not loaded on ui');
}
};

export const dragAndDrop = async (
page: Page,
aPosition: Position,
Expand All @@ -34,7 +45,8 @@ export const addComponentsToCanvas = async (
page: Page,
components: string[]
) => {
const canvasPosition = await page.locator('canvas').boundingBox();
const stageCanvas = await page.locator('#konva-stage canvas').first();
const canvasPosition = await stageCanvas.boundingBox();
if (!canvasPosition) throw new Error('No canvas found');

for await (const [index, c] of components.entries()) {
Expand Down
3 changes: 2 additions & 1 deletion e2e/selection/shape-selection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ test('drop shape in canvas, click on canvas, drop diselected', async ({
const inputShape = (await getByShapeType(page, 'input')) as Group;
expect(inputShape).toBeDefined();

await page.click('canvas');
//Click Away
await page.mouse.click(800, 130);

const transformer = await getTransformer(page);
expect(transformer).toBeDefined();
Expand Down
3 changes: 2 additions & 1 deletion e2e/ui-functionality/copy-paste.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ test.describe('Copy/Paste functionality tests', () => {
);
});

/*
test('Should copy and paste a multiple shapes using the ToolBar UI buttons', async ({
page,
}) => {
Expand Down Expand Up @@ -112,7 +113,7 @@ test.describe('Copy/Paste functionality tests', () => {
expect(originalComp_2['data-id']).not.toEqual(copiedComp_2['data-id']);
expect(originalComp_3['data-id']).not.toEqual(copiedComp_3['data-id']);
});

*/
test('Should copy and paste a multiple shapes using keyboard commands', async ({
page,
}) => {
Expand Down
166 changes: 166 additions & 0 deletions e2e/ui-functionality/toolbar_undo-redo.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import { test, expect } from '@playwright/test';
import {
addComponentsToCanvas,
getWithinCanvasItemList,
getByShapeType,
dbClickOnCanvasItem,
getCanvasBoundingBox,
getShapePosition,
} from '../helpers';
import { E2E_CanvasItemKeyAttrs } from '../helpers/types/e2e-types';
import { Group } from 'konva/lib/Group';
import {
clickRedoUiButton,
clickUndoUiButton,
} from '../helpers/ui-buttons.helpers';

test.describe('ToolBar buttons Undo/Redo functionality tests', () => {
test.beforeEach(async ({ page }) => {
await page.goto('');
});

test('Should remove and restore a just dragged into canvas-item, respectively', async ({
page,
}) => {
//Arrange
const addInputIntoCanvas = ['Input'];
await addComponentsToCanvas(page, addInputIntoCanvas);

//Undo and check within canvas items
await clickUndoUiButton(page);
const insideCanvasItemList = await getWithinCanvasItemList(page);

expect(insideCanvasItemList.length).toEqual(0);

//Redo and check existing item within canvas
await clickRedoUiButton(page);
const updatedInsideCanvasItemList = await getWithinCanvasItemList(page);

expect(updatedInsideCanvasItemList.length).toEqual(1);
});

test('Should remove and restore the last item you just dragged into the canvas', async ({
page,
}) => {
//Arrange
const addComponentsIntoCanvas = ['Input', 'Combobox'];
await addComponentsToCanvas(page, addComponentsIntoCanvas);

//Undo and assert there is only one Item within canvas
await clickUndoUiButton(page);
const insideCanvasItemList = await getWithinCanvasItemList(page);

expect(insideCanvasItemList.length).toEqual(1);

const firsCanvastItem = await getByShapeType(page, 'input');
expect(firsCanvastItem).toBeDefined();

//Redo and assert both items are contained within the canvas
await clickRedoUiButton(page);
const updatedInsideCanvasItemList = await getWithinCanvasItemList(page);
const secondCanvasItem = await getByShapeType(page, 'combobox');

expect(updatedInsideCanvasItemList.length).toEqual(2);
expect(firsCanvastItem).toBeDefined();
expect(secondCanvasItem).toBeDefined();
});

test('Should reverse and restore an edited text of an Input Component', async ({
page,
}) => {
//Arrange data and drag an input
const addComponentsIntoCanvas = ['Input'];
const defaultInputPlaceholder = 'Placeholder';
const updatedText = 'Hello';

await addComponentsToCanvas(page, addComponentsIntoCanvas);
const [inputOnCanvas] = (await getWithinCanvasItemList(
page
)) as E2E_CanvasItemKeyAttrs[];

//Start Input component inline editing
await dbClickOnCanvasItem(page, inputOnCanvas);
const editableInput = page.locator('input[data-is-inline-edition-on=true]');
const defaultInputValue = await editableInput.inputValue();

await editableInput.fill(updatedText);
const updatedInputValue = await editableInput.inputValue();

//Undo edit and assert text is reversed
await clickUndoUiButton(page);
expect(defaultInputValue).toEqual(defaultInputPlaceholder);

//Redo edit and assert that input contains the restored updated text
await clickRedoUiButton(page);
expect(updatedInputValue).toEqual(updatedText);
});

test('Should restore the item position to its previous placement', async ({
page,
}) => {
//Arrange data and drag an input into canvas
const componentToAddintoCanvas = ['Input'];
await addComponentsToCanvas(page, componentToAddintoCanvas);

const { x: canvasXStart, y: canvasYStart } =
await getCanvasBoundingBox(page);

const inputElement = (await getByShapeType(page, 'input')) as Group;

const inputInitialPosition = await getShapePosition(inputElement);
const inputModifiedPosition = {
x: inputInitialPosition.x + canvasXStart + 200,
y: inputInitialPosition.y + canvasYStart,
};

//Displace item within the canvas
await page.mouse.down();
await page.mouse.move(inputModifiedPosition.x, inputModifiedPosition.y);
await page.mouse.up();

//Undo and assert that the item is placed in its initial position
await clickUndoUiButton(page);
const finalInputPosition = await getShapePosition(inputElement);

expect(finalInputPosition).toEqual(inputInitialPosition);
});

test('Should undo and redo, backward and forward severals steps consistently', async ({
page,
}) => {
//Arrange data and drag an items into canvas
const componentsToAddIntoCanvas = ['Input', 'Combobox'];
await addComponentsToCanvas(page, componentsToAddIntoCanvas);

await page.getByText('Rich Components').click();
const richComponentsToAddintoCanvas = ['Accordion'];
await addComponentsToCanvas(page, richComponentsToAddintoCanvas);

//Assert there are 3 items within the canvas
const itemsQtyWithinCanvas_step1 = (await getWithinCanvasItemList(page))
.length;

expect(itemsQtyWithinCanvas_step1).toEqual(3);

//x3 undo
await clickUndoUiButton(page);
await clickUndoUiButton(page);
await clickUndoUiButton(page);

//Assert there are no items within the canvas
const itemsQtyWithinCanvas_step2 = (await getWithinCanvasItemList(page))
.length;

expect(itemsQtyWithinCanvas_step2).toEqual(0);

//x3 redo
await clickRedoUiButton(page);
await clickRedoUiButton(page);
await clickRedoUiButton(page);

//Assert there are again 3 items within the canvas
const itemsQtyWithinCanvas_step3 = (await getWithinCanvasItemList(page))
.length;
expect(itemsQtyWithinCanvas_step3).toEqual(3);
});
});
1 change: 1 addition & 0 deletions public/icons/addlist.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/alternativemouse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/arrowfatdown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/arrowfatleft.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/arrowfatright.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/arrowfatup.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/arrowsclockwise.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/arrowscounterclockwise.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/autoflash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/callphoneincoming.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/camera.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/caretdown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/caretleft.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/caretright.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/caretup.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/checkfat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/company.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/controller.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/copyright.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/doublecheck.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/factory.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/filedoc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4c77562

Please sign in to comment.