From 0db7ac78c41e33319941b8e554433631d1351727 Mon Sep 17 00:00:00 2001 From: David Luzar Date: Fri, 29 May 2020 21:59:39 +0200 Subject: [PATCH] fix fontFamily state updating (#1679) --- src/actions/actionProperties.tsx | 2 +- .../regressionTests.test.tsx.snap | 69 +++++++++++++++++++ src/tests/queries/toolQueries.ts | 1 + src/tests/regressionTests.test.tsx | 7 ++ 4 files changed, 78 insertions(+), 1 deletion(-) diff --git a/src/actions/actionProperties.tsx b/src/actions/actionProperties.tsx index e56ffc10..72f2ffb6 100644 --- a/src/actions/actionProperties.tsx +++ b/src/actions/actionProperties.tsx @@ -374,7 +374,7 @@ export const actionChangeFontFamily = register({ }), appState: { ...appState, - currentItemFontFamily: appState.currentItemFontFamily, + currentItemFontFamily: value, }, commitToHistory: true, }; diff --git a/src/tests/__snapshots__/regressionTests.test.tsx.snap b/src/tests/__snapshots__/regressionTests.test.tsx.snap index 748a2bb4..b6afadd1 100644 --- a/src/tests/__snapshots__/regressionTests.test.tsx.snap +++ b/src/tests/__snapshots__/regressionTests.test.tsx.snap @@ -15677,6 +15677,75 @@ exports[`regression tests undo/redo drawing an element: [end of test] number of exports[`regression tests undo/redo drawing an element: [end of test] number of renders 1`] = `24`; +exports[`regression tests updates fontSize & fontFamily appState: [end of test] appState 1`] = ` +Object { + "collaborators": Map {}, + "currentItemBackgroundColor": "transparent", + "currentItemFillStyle": "hachure", + "currentItemFontFamily": 3, + "currentItemFontSize": 20, + "currentItemOpacity": 100, + "currentItemRoughness": 1, + "currentItemStrokeColor": "#000000", + "currentItemStrokeStyle": "solid", + "currentItemStrokeWidth": 1, + "currentItemTextAlign": "left", + "cursorButton": "up", + "cursorX": 0, + "cursorY": 0, + "draggingElement": null, + "editingElement": null, + "editingGroupId": null, + "elementLocked": false, + "elementType": "text", + "errorMessage": null, + "exportBackground": true, + "isCollaborating": false, + "isLoading": false, + "isResizing": false, + "isRotating": false, + "lastPointerDownWith": "mouse", + "multiElement": null, + "name": "Unbenannt-201933152653", + "openMenu": null, + "resizingElement": null, + "scrollX": 0, + "scrollY": 0, + "scrolledOutside": false, + "selectedElementIds": Object {}, + "selectedGroupIds": Object {}, + "selectionElement": null, + "shouldAddWatermark": false, + "shouldCacheIgnoreZoom": false, + "showShortcutsDialog": false, + "username": "", + "viewBackgroundColor": "#ffffff", + "zenModeEnabled": false, + "zoom": 1, +} +`; + +exports[`regression tests updates fontSize & fontFamily appState: [end of test] history 1`] = ` +Object { + "recording": false, + "redoStack": Array [], + "stateHistory": Array [ + Object { + "appState": Object { + "name": "Unbenannt-201933152653", + "selectedElementIds": Object {}, + "viewBackgroundColor": "#ffffff", + }, + "elements": Array [], + }, + ], +} +`; + +exports[`regression tests updates fontSize & fontFamily appState: [end of test] number of elements 1`] = `0`; + +exports[`regression tests updates fontSize & fontFamily appState: [end of test] number of renders 1`] = `4`; + exports[`regression tests zoom hotkeys: [end of test] appState 1`] = ` Object { "collaborators": Map {}, diff --git a/src/tests/queries/toolQueries.ts b/src/tests/queries/toolQueries.ts index a106e573..6c18045a 100644 --- a/src/tests/queries/toolQueries.ts +++ b/src/tests/queries/toolQueries.ts @@ -8,6 +8,7 @@ const toolMap = { arrow: "arrow", line: "line", draw: "draw", + text: "text", }; export type ToolName = keyof typeof toolMap; diff --git a/src/tests/regressionTests.test.tsx b/src/tests/regressionTests.test.tsx index bad6ac1a..b369cd36 100644 --- a/src/tests/regressionTests.test.tsx +++ b/src/tests/regressionTests.test.tsx @@ -840,4 +840,11 @@ describe("regression tests", () => { mouse.doubleClick(); expect(getSelectedElements().length).toBe(1); }); + + it("updates fontSize & fontFamily appState", () => { + clickTool("text"); + expect(h.state.currentItemFontFamily).toEqual(1); // Virgil + fireEvent.click(screen.getByText(/code/i)); + expect(h.state.currentItemFontFamily).toEqual(3); // Cascadia + }); });