From 51739ad3f282f2a7afef2b1477b53d1502059a6a Mon Sep 17 00:00:00 2001 From: hiroshi Date: Fri, 16 Sep 2022 16:58:57 +0900 Subject: [PATCH 1/2] add test coverage --- src/app/store/models/settings.test.tsx | 163 +++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 src/app/store/models/settings.test.tsx diff --git a/src/app/store/models/settings.test.tsx b/src/app/store/models/settings.test.tsx new file mode 100644 index 000000000..f91b523bc --- /dev/null +++ b/src/app/store/models/settings.test.tsx @@ -0,0 +1,163 @@ +import { init, RematchStore } from '@rematch/core'; +import { RootModel } from '@/types/RootModel'; +import { models } from './index'; +import { UpdateMode } from '@/constants/UpdateMode'; +import { AsyncMessageChannel } from '@/AsyncMessageChannel'; +import { AsyncMessageTypes } from '@/types/AsyncMessages'; + +type Store = RematchStore>; + +describe('settings', () => { + const messageSpy = jest.spyOn(AsyncMessageChannel.ReactInstance, 'message'); + let store: Store; + beforeEach(() => { + store = init({ + redux: { + initialState: { + settings: { + uiWindow: { + width: 400, + height: 600, + isMinimized: false, + }, + updateMode: UpdateMode.PAGE, + updateRemote: true, + updateOnChange: true, + updateStyles: true, + tokenType: 'object', + ignoreFirstPartForStyles: false, + prefixStylesWithThemeName: false, + inspectDeep: false, + }, + }, + }, + models, + }); + }); + + it('should be able to set inspectDeep', () => { + store.dispatch.settings.setInspectDeep(true); + expect(store.getState().settings.inspectDeep).toBe(true); + }); + + it('should be able to set window size', () => { + store.dispatch.settings.setWindowSize({ width: 1024, height: 768 }); + expect(store.getState().settings.uiWindow).toEqual({ + isMinimized: false, + width: 1024, + height: 768, + }); + expect(messageSpy).toBeCalledWith({ + type: AsyncMessageTypes.RESIZE_WINDOW, + width: 1024, + height: 768, + }); + }); + + it('should be able to minimize plugin window', () => { + store.dispatch.settings.setMinimizePluginWindow({ isMinimized: true, width: 40, height: 60 }); + expect(store.getState().settings.uiWindow).toEqual({ + isMinimized: true, + width: 40, + height: 60, + }); + expect(messageSpy).toBeCalledWith({ + type: AsyncMessageTypes.RESIZE_WINDOW, + width: 50, + height: 50, + }); + }); + + it('should be able to set UI settings', () => { + store.dispatch.settings.setUISettings({ + uiWindow: { + width: 1024, + height: 768, + isMinimized: false, + }, + updateMode: UpdateMode.DOCUMENT, + updateRemote: false, + updateOnChange: false, + updateStyles: true, + tokenType: 'object', + ignoreFirstPartForStyles: false, + prefixStylesWithThemeName: false, + inspectDeep: true, + }); + expect(store.getState().settings).toEqual({ + uiWindow: { + width: 1024, + height: 768, + isMinimized: false, + }, + updateMode: UpdateMode.DOCUMENT, + updateRemote: false, + updateOnChange: false, + updateStyles: true, + tokenType: 'object', + ignoreFirstPartForStyles: false, + prefixStylesWithThemeName: false, + inspectDeep: true, + }); + }); + + it('should be able to modify window size', () => { + store.dispatch.settings.triggerWindowChange(); + expect(store.getState().settings).toEqual({ + uiWindow: { + width: 400, + height: 600, + isMinimized: false, + }, + updateMode: UpdateMode.PAGE, + updateRemote: true, + updateOnChange: true, + updateStyles: true, + tokenType: 'object', + ignoreFirstPartForStyles: false, + prefixStylesWithThemeName: false, + inspectDeep: false, + }); + expect(messageSpy).toBeCalledWith({ + type: AsyncMessageTypes.SET_UI, + uiWindow: { + width: 400, + height: 600, + isMinimized: false, + }, + updateMode: UpdateMode.PAGE, + updateRemote: true, + updateOnChange: true, + updateStyles: true, + tokenType: 'object', + ignoreFirstPartForStyles: false, + prefixStylesWithThemeName: false, + inspectDeep: false, + }); + }); + + it('should be able to set update mode', () => { + store.dispatch.settings.setUpdateMode(UpdateMode.DOCUMENT); + expect(store.getState().settings.updateMode).toBe(UpdateMode.DOCUMENT); + }); + + it('should be able to set updateRemote', () => { + store.dispatch.settings.setUpdateRemote(true); + expect(store.getState().settings.updateRemote).toEqual(true); + }); + + it('should be able to set updateOnChange', () => { + store.dispatch.settings.setUpdateOnChange(true); + expect(store.getState().settings.updateOnChange).toEqual(true); + }); + + it('should be able to set token type', () => { + store.dispatch.settings.setTokenType('array'); + expect(store.getState().settings.tokenType).toEqual('array'); + }); + + it('should be able to set ignoreFirstPartForStyles', () => { + store.dispatch.settings.setIgnoreFirstPartForStyles(true); + expect(store.getState().settings.ignoreFirstPartForStyles).toEqual(true); + }); +}); From a397341b73f9dc8bd90b4c329a553792ac957e5a Mon Sep 17 00:00:00 2001 From: hiroshi Date: Fri, 16 Sep 2022 17:11:40 +0900 Subject: [PATCH 2/2] add missing test --- src/app/store/models/settings.test.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/app/store/models/settings.test.tsx b/src/app/store/models/settings.test.tsx index f91b523bc..e263d7182 100644 --- a/src/app/store/models/settings.test.tsx +++ b/src/app/store/models/settings.test.tsx @@ -4,6 +4,7 @@ import { models } from './index'; import { UpdateMode } from '@/constants/UpdateMode'; import { AsyncMessageChannel } from '@/AsyncMessageChannel'; import { AsyncMessageTypes } from '@/types/AsyncMessages'; +import { RootState } from '@/app/store'; type Store = RematchStore>; @@ -68,6 +69,11 @@ describe('settings', () => { }); }); + it('should be able to set update styles', () => { + store.dispatch.settings.setUpdateStyles(true); + expect(store.getState().settings.updateStyles).toBe(true); + }); + it('should be able to set UI settings', () => { store.dispatch.settings.setUISettings({ uiWindow: {