mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Write integration tests (#719)
* Scaffold a simple test case for debugging * Set up Jest environment that works with React - Install and set up react-testing-library - "Unignore" roughjs and browser-nativejs transformations - Separate App component from ReactDOM * Write first passing test - Mock canvas - Remove App file and mount/unmount ReactDOM on import * Add tests for drag create behavior * Fix comments in dragCreate * Pin jest-mock-canvas dependency * Remove dependency range for testing library * Add tests for multi point mode and selection element * Fix all tests due to decrease in updates to canvas when changing tools * Disable state updates if component is unmounted - Remove all event listeners - Disable storing scene in state if component is unmounted * Add tests for move and element selection * Merge branch 'master' into add-integration-tests * Add tests for resizing rectangle * move unmounted check to syncActionResult method * Use a custom test renderer instead of default testing-library functions * Add custom query for selecting tools * move files around Co-authored-by: David Luzar <luzar.david@gmail.com>
This commit is contained in:
parent
ad4ad238ef
commit
7183234895
11 changed files with 1180 additions and 5 deletions
32
src/tests/queries/toolQueries.ts
Normal file
32
src/tests/queries/toolQueries.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { queries, buildQueries } from "@testing-library/react";
|
||||
|
||||
const _getAllByToolName = (container: HTMLElement, tool: string) => {
|
||||
const toolMap: { [propKey: string]: string } = {
|
||||
selection: "Selection — S, 1",
|
||||
rectangle: "Rectangle — R, 2",
|
||||
diamond: "Diamond — D, 3",
|
||||
ellipse: "Ellipse — E, 4",
|
||||
arrow: "Arrow — A, 5",
|
||||
line: "Line — L, 6",
|
||||
};
|
||||
|
||||
const toolTitle = toolMap[tool as string];
|
||||
return queries.getAllByTitle(container, toolTitle);
|
||||
};
|
||||
|
||||
const getMultipleError = (c: any, tool: any) =>
|
||||
`Found multiple elements with tool name: ${tool}`;
|
||||
const getMissingError = (c: any, tool: any) =>
|
||||
`Unable to find an element with tool name: ${tool}`;
|
||||
|
||||
export const [
|
||||
queryByToolName,
|
||||
getAllByToolName,
|
||||
getByToolName,
|
||||
findAllByToolName,
|
||||
findByToolName,
|
||||
] = buildQueries<string[]>(
|
||||
_getAllByToolName,
|
||||
getMultipleError,
|
||||
getMissingError,
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue