-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from Lemoncode/dev
Fix cmd unselect
- Loading branch information
Showing
166 changed files
with
1,512 additions
and
1,095 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './konva-testing.helpers'; | ||
export * from './position.helpers'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Page } from '@playwright/test'; | ||
import { Layer } from 'konva/lib/Layer'; | ||
import { Shape } from 'konva/lib/Shape'; | ||
import { Group } from 'konva/lib/Group'; | ||
|
||
const getLayer = async (page: Page): Promise<Layer> => | ||
await page.evaluate(() => { | ||
const layer = (window as any).KONVA_LAYER; | ||
return layer; | ||
}); | ||
|
||
const getChildren = async (page: Page): Promise<(Group | Shape)[]> => { | ||
const layer = await getLayer(page); | ||
return layer?.children.flatMap(child => | ||
Boolean((child as any)?.children) ? (child as any).children : child | ||
); | ||
}; | ||
|
||
export const getAllByShapeType = async ( | ||
page: Page, | ||
shape: string | ||
): Promise<(Group | Shape)[]> => { | ||
const children = await getChildren(page); | ||
const shapes = children?.filter(child => child.attrs.shapeType === shape); | ||
if (shapes.length === 0) { | ||
throw new Error(`No shapes found with shapeType ${shape}`); | ||
} else { | ||
return shapes; | ||
} | ||
}; | ||
|
||
export const getByShapeType = async ( | ||
page: Page, | ||
shape: string | ||
): Promise<Group | Shape | undefined> => { | ||
const children = await getChildren(page); | ||
const count = children?.filter( | ||
child => child.attrs.shapeType === shape | ||
)?.length; | ||
|
||
if (count === 1) { | ||
return children.find(child => child.attrs.shapeType === shape); | ||
} else if (count > 1) { | ||
throw new Error( | ||
`Found ${count} shapes with shapeType ${shape} you should use getAllByShapeType` | ||
); | ||
} else { | ||
return undefined; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Locator, Page } from '@playwright/test'; | ||
|
||
interface Position { | ||
x: number; | ||
y: number; | ||
} | ||
|
||
export const getLocatorPosition = async ( | ||
locator: Locator | ||
): Promise<Position> => { | ||
const box = (await locator.boundingBox()) || { | ||
x: 0, | ||
y: 0, | ||
width: 0, | ||
height: 0, | ||
}; | ||
return { x: box.x + box.width / 2, y: box.y + box.height / 2 }; | ||
}; | ||
|
||
export const dragAndDrop = async ( | ||
page: Page, | ||
aPosition: Position, | ||
bPosition: Position | ||
): Promise<void> => { | ||
await page.mouse.move(aPosition.x, aPosition.y); | ||
await page.mouse.down(); | ||
await page.mouse.move(bPosition.x, bPosition.y); | ||
await page.mouse.up(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import { Group } from 'konva/lib/Group'; | ||
import { dragAndDrop, getByShapeType, getLocatorPosition } from './helpers'; | ||
|
||
test('has Basic Shapes group', async ({ page }) => { | ||
await page.goto(''); | ||
|
||
await expect(page.getByText('Basic Shapes')).toBeVisible(); | ||
}); | ||
|
||
test('has rectangle component', async ({ page }) => { | ||
await page.goto(''); | ||
await page.getByText('Basic Shapes').click(); | ||
|
||
await expect(page.getByAltText('Rectangle')).toBeVisible(); | ||
}); | ||
|
||
test('can add rectangle component to canvas', async ({ page }) => { | ||
await page.goto(''); | ||
await page.getByText('Basic Shapes').click(); | ||
const component = page.getByAltText('Rectangle'); | ||
|
||
const position = await getLocatorPosition(component); | ||
await dragAndDrop(page, position, { | ||
x: position.x + 500, | ||
y: position.y - 240, | ||
}); | ||
|
||
const rectangle = (await getByShapeType(page, 'rectangle')) as Group; | ||
expect(rectangle).toBeDefined(); | ||
expect(rectangle.attrs.width).toEqual(160); | ||
expect(rectangle.attrs.height).toEqual(160); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
|
||
const BASE_URL = 'http://localhost:5173/editor.html'; | ||
|
||
export default defineConfig({ | ||
testDir: './e2e', | ||
fullyParallel: true, | ||
forbidOnly: !!process.env.CI, | ||
retries: process.env.CI ? 2 : 1, | ||
workers: process.env.CI ? 1 : undefined, | ||
reporter: 'html', | ||
use: { | ||
baseURL: BASE_URL, | ||
trace: 'on-first-retry', | ||
}, | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
}, | ||
{ | ||
name: 'firefox', | ||
use: { ...devices['Desktop Firefox'] }, | ||
}, | ||
], | ||
webServer: { | ||
command: 'npm run dev', | ||
url: BASE_URL, | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |
Oops, something went wrong.