mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
factor out test helpers (#2093)
This commit is contained in:
parent
4c2d34ffd7
commit
8b9e2a540d
4 changed files with 613 additions and 503 deletions
32
src/tests/helpers/api.ts
Normal file
32
src/tests/helpers/api.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { ExcalidrawElement } from "../../element/types";
|
||||
|
||||
const { h } = window;
|
||||
|
||||
export class API {
|
||||
static getSelectedElements = (): ExcalidrawElement[] => {
|
||||
return h.elements.filter(
|
||||
(element) => h.state.selectedElementIds[element.id],
|
||||
);
|
||||
};
|
||||
|
||||
static getSelectedElement = (): ExcalidrawElement => {
|
||||
const selectedElements = API.getSelectedElements();
|
||||
if (selectedElements.length !== 1) {
|
||||
throw new Error(
|
||||
`expected 1 selected element; got ${selectedElements.length}`,
|
||||
);
|
||||
}
|
||||
return selectedElements[0];
|
||||
};
|
||||
|
||||
static getStateHistory = () => {
|
||||
// @ts-ignore
|
||||
return h.history.stateHistory;
|
||||
};
|
||||
|
||||
static clearSelection = () => {
|
||||
// @ts-ignore
|
||||
h.app.clearSelection(null);
|
||||
expect(API.getSelectedElements().length).toBe(0);
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue