Skip to content

Commit

Permalink
Merge pull request #466 from Lemoncode/dev
Browse files Browse the repository at this point in the history
minor font fix dev to main
  • Loading branch information
brauliodiez authored Oct 18, 2024
2 parents 3b8b84f + c15cf68 commit a7396d3
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 9 deletions.
111 changes: 111 additions & 0 deletions e2e/canvas/move-shape-using-keyboard.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { test, expect } from '@playwright/test';
import {
dragAndDrop,
getLocatorPosition,
getByShapeType,
getShapePosition,
moveSelected,
} from '../helpers';
import { Group } from 'konva/lib/Group';

const numShifts: number = 10;

test('move shape with the keyboard - left', async ({ page }) => {
await page.goto('');

const component = page.getByAltText('Input', { exact: true });
const position = await getLocatorPosition(component);

await dragAndDrop(page, position, {
x: position.x + 500,
y: position.y - 240,
});

const inputShape = (await getByShapeType(page, 'input')) as Group;
expect(inputShape).toBeDefined();

const draggedPosition = await getShapePosition(inputShape);

moveSelected(page, 'ArrowLeft', numShifts);

const inputShapeMoved = (await getByShapeType(page, 'input')) as Group;
const movedPosition = await getShapePosition(inputShapeMoved);

expect(movedPosition.x === draggedPosition.x - numShifts * 2).toBeTruthy();
expect(movedPosition.y === draggedPosition.y).toBeTruthy();
});

test('move shape with the keyboard - up', async ({ page }) => {
await page.goto('');

const component = page.getByAltText('Input', { exact: true });
const position = await getLocatorPosition(component);

await dragAndDrop(page, position, {
x: position.x + 500,
y: position.y - 240,
});

const inputShape = (await getByShapeType(page, 'input')) as Group;
expect(inputShape).toBeDefined();

const draggedPosition = await getShapePosition(inputShape);

moveSelected(page, 'ArrowUp', numShifts);

const inputShapeMoved = (await getByShapeType(page, 'input')) as Group;
const movedPosition = await getShapePosition(inputShapeMoved);

expect(movedPosition.x === draggedPosition.x).toBeTruthy();
expect(movedPosition.y === draggedPosition.y - numShifts * 2).toBeTruthy();
});

test('move shape with the keyboard - down', async ({ page }) => {
await page.goto('');

const component = page.getByAltText('Input', { exact: true });
const position = await getLocatorPosition(component);

await dragAndDrop(page, position, {
x: position.x + 500,
y: position.y - 240,
});

const inputShape = (await getByShapeType(page, 'input')) as Group;
expect(inputShape).toBeDefined();

const draggedPosition = await getShapePosition(inputShape);

moveSelected(page, 'ArrowDown', numShifts);

const inputShapeMoved = (await getByShapeType(page, 'input')) as Group;
const movedPosition = await getShapePosition(inputShapeMoved);

expect(movedPosition.x === draggedPosition.x).toBeTruthy();
expect(movedPosition.y === draggedPosition.y + numShifts * 2).toBeTruthy();
});

test('move shape with the keyboard - right', async ({ page }) => {
await page.goto('');

const component = page.getByAltText('Input', { exact: true });
const position = await getLocatorPosition(component);

await dragAndDrop(page, position, {
x: position.x + 500,
y: position.y - 240,
});

const inputShape = (await getByShapeType(page, 'input')) as Group;
expect(inputShape).toBeDefined();

const draggedPosition = await getShapePosition(inputShape);

moveSelected(page, 'ArrowRight', numShifts);

const inputShapeMoved = (await getByShapeType(page, 'input')) as Group;
const movedPosition = await getShapePosition(inputShapeMoved);

expect(movedPosition.x === draggedPosition.x + numShifts * 2).toBeTruthy();
expect(movedPosition.y === draggedPosition.y).toBeTruthy();
});
13 changes: 13 additions & 0 deletions e2e/helpers/position.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Locator, Page } from '@playwright/test';
import { Group } from 'konva/lib/Group';

interface Position {
x: number;
Expand Down Expand Up @@ -54,3 +55,15 @@ export const addComponentsToCanvas = async (
await dragAndDrop(page, position, targetPosition(120, index));
}
};

export const getShapePosition = async (shape: Group): Promise<Position> => {
return { x: shape?.attrs.x, y: shape?.attrs.y };
};

export const moveSelected = (
page: Page,
direction: string,
numShifts: number
) => {
for (let i: number = 0; i < numShifts; i++) page.keyboard.down(direction);
};
75 changes: 67 additions & 8 deletions public/widgets/datepicker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const DEFAULT_STROKE_COLOR = '#000000';
const DEFAULT_STROKE_WIDTH = 1;
const DEFAULT_STROKE_STYLE: number[] = [];
const DEFAULT_FILL_BACKGROUND = '#ffffff';
const DEFAULT_FONT_FAMILY = 'Comic Sans MS, Balsamiq Sans, cursive';
const DEFAULT_FONT_FAMILY = 'Balsamiq Sans, Comic Sans MS, cursive';
const DEFAULT_FONT_SIZE = 16;
const DEFAULT_FILL_TEXT = '#000000';
const DEFAULT_PADDING = 10;
Expand Down
7 changes: 7 additions & 0 deletions src/pods/canvas/model/shape-other-props.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export const generateDefaultOtherProps = (
};
case 'button':
case 'textarea':
return {
stroke: BASIC_SHAPE.DEFAULT_STROKE_COLOR,
backgroundColor: BASIC_SHAPE.DEFAULT_FILL_BACKGROUND,
textColor: BASIC_SHAPE.DEFAULT_FILL_TEXT,
strokeStyle: [],
borderRadius: `${BASIC_SHAPE.DEFAULT_CORNER_RADIUS}`,
};
case 'vertical-menu':
case 'horizontal-menu':
return {
Expand Down
1 change: 1 addition & 0 deletions src/pods/canvas/use-transform.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const useTransform = (
transformerRef.current.enabledAnchors(
selectedShape.attrs.typeOfTransformer
);
transformerRef.current.rotateEnabled(false);
}
};

Expand Down

0 comments on commit a7396d3

Please sign in to comment.