factor out test helpers (#2093)

This commit is contained in:
David Luzar 2020-08-28 10:15:29 +02:00 committed by GitHub
parent 4c2d34ffd7
commit 8b9e2a540d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 613 additions and 503 deletions

32
src/tests/helpers/api.ts Normal file
View 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);
};
}