expose a few state props for debugging (#1008)

* expose a few state props for debugging

* rename h.appState & add h.setState

* support setting elements
This commit is contained in:
David Luzar 2020-03-18 20:44:05 +01:00 committed by GitHub
parent cb66adc716
commit ff033640e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 73 deletions

View file

@ -14,7 +14,7 @@ beforeEach(() => {
renderScene.mockClear();
});
const { __TEST__: h } = window;
const { h } = window;
describe("selection element", () => {
it("create selection element on pointer down", () => {
@ -27,7 +27,7 @@ describe("selection element", () => {
fireEvent.pointerDown(canvas, { clientX: 60, clientY: 100 });
expect(renderScene).toHaveBeenCalledTimes(1);
const selectionElement = h.appState.selectionElement!;
const selectionElement = h.state.selectionElement!;
expect(selectionElement).not.toBeNull();
expect(selectionElement.type).toEqual("selection");
expect([selectionElement.x, selectionElement.y]).toEqual([60, 100]);
@ -48,7 +48,7 @@ describe("selection element", () => {
fireEvent.pointerMove(canvas, { clientX: 150, clientY: 30 });
expect(renderScene).toHaveBeenCalledTimes(2);
const selectionElement = h.appState.selectionElement!;
const selectionElement = h.state.selectionElement!;
expect(selectionElement).not.toBeNull();
expect(selectionElement.type).toEqual("selection");
expect([selectionElement.x, selectionElement.y]).toEqual([60, 30]);
@ -70,7 +70,7 @@ describe("selection element", () => {
fireEvent.pointerUp(canvas);
expect(renderScene).toHaveBeenCalledTimes(3);
expect(h.appState.selectionElement).toBeNull();
expect(h.state.selectionElement).toBeNull();
});
});
@ -95,9 +95,9 @@ describe("select single element on the scene", () => {
fireEvent.pointerUp(canvas);
expect(renderScene).toHaveBeenCalledTimes(7);
expect(h.appState.selectionElement).toBeNull();
expect(h.state.selectionElement).toBeNull();
expect(h.elements.length).toEqual(1);
expect(h.appState.selectedElementIds[h.elements[0].id]).toBeTruthy();
expect(h.state.selectedElementIds[h.elements[0].id]).toBeTruthy();
});
it("diamond", () => {
@ -120,9 +120,9 @@ describe("select single element on the scene", () => {
fireEvent.pointerUp(canvas);
expect(renderScene).toHaveBeenCalledTimes(7);
expect(h.appState.selectionElement).toBeNull();
expect(h.state.selectionElement).toBeNull();
expect(h.elements.length).toEqual(1);
expect(h.appState.selectedElementIds[h.elements[0].id]).toBeTruthy();
expect(h.state.selectedElementIds[h.elements[0].id]).toBeTruthy();
});
it("ellipse", () => {
@ -145,9 +145,9 @@ describe("select single element on the scene", () => {
fireEvent.pointerUp(canvas);
expect(renderScene).toHaveBeenCalledTimes(7);
expect(h.appState.selectionElement).toBeNull();
expect(h.state.selectionElement).toBeNull();
expect(h.elements.length).toEqual(1);
expect(h.appState.selectedElementIds[h.elements[0].id]).toBeTruthy();
expect(h.state.selectedElementIds[h.elements[0].id]).toBeTruthy();
});
it("arrow", () => {
@ -183,9 +183,9 @@ describe("select single element on the scene", () => {
fireEvent.pointerUp(canvas);
expect(renderScene).toHaveBeenCalledTimes(7);
expect(h.appState.selectionElement).toBeNull();
expect(h.state.selectionElement).toBeNull();
expect(h.elements.length).toEqual(1);
expect(h.appState.selectedElementIds[h.elements[0].id]).toBeTruthy();
expect(h.state.selectedElementIds[h.elements[0].id]).toBeTruthy();
});
it("arrow escape", () => {
@ -221,8 +221,8 @@ describe("select single element on the scene", () => {
fireEvent.pointerUp(canvas);
expect(renderScene).toHaveBeenCalledTimes(7);
expect(h.appState.selectionElement).toBeNull();
expect(h.state.selectionElement).toBeNull();
expect(h.elements.length).toEqual(1);
expect(h.appState.selectedElementIds[h.elements[0].id]).toBeTruthy();
expect(h.state.selectedElementIds[h.elements[0].id]).toBeTruthy();
});
});