From 7222009738a11b1f3657a22e2b5567b18734ee7e Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Tue, 6 Sep 2022 13:51:09 +0700 Subject: [PATCH 1/8] feat(jest): lots of improvement on store --- package.json | 3 +- .../chat/__snapshots__/mutations.test.ts.snap | 31 +++++++ store/chat/mutations.test.ts | 87 +++++++++++++++---- store/conversation/mutations.test.ts | 12 +++ store/groups/actions.test.ts | 48 ++++++++++ 5 files changed, 161 insertions(+), 20 deletions(-) create mode 100644 store/groups/actions.test.ts diff --git a/package.json b/package.json index f7fb0bad29..de0c7cdeb2 100644 --- a/package.json +++ b/package.json @@ -169,5 +169,6 @@ "volta": { "node": "16.15.0", "yarn": "1.22.19" - } + }, + "peerDependencies": {} } diff --git a/store/chat/__snapshots__/mutations.test.ts.snap b/store/chat/__snapshots__/mutations.test.ts.snap index 89cbba5044..24115a7a69 100644 --- a/store/chat/__snapshots__/mutations.test.ts.snap +++ b/store/chat/__snapshots__/mutations.test.ts.snap @@ -15,6 +15,37 @@ Object { } `; +exports[`misc module.default.addFile with existing files array 1`] = ` +Object { + "undefined": Array [ + Object { + "file": "path2", + "nsfw": Object { + "checking": false, + "status": false, + }, + "url": "string2", + }, + Object { + "file": "path2", + "nsfw": Object { + "checking": false, + "status": false, + }, + "url": "string2", + }, + Object { + "file": "path3", + "nsfw": Object { + "checking": false, + "status": false, + }, + "url": "string3", + }, + ], +} +`; + exports[`module.default.addFile 0 1`] = `undefined`; exports[`module.default.addFile 1 1`] = `undefined`; diff --git a/store/chat/mutations.test.ts b/store/chat/mutations.test.ts index 68cd4a828c..eede29bcae 100644 --- a/store/chat/mutations.test.ts +++ b/store/chat/mutations.test.ts @@ -1,5 +1,7 @@ import { ChatState, ChatFileUpload } from './types' +import InitialChatState from './state' import * as module from '~/store/chat/mutations' +import { stat } from 'fs' describe('module.default.setChatReply', () => { test('0', () => { @@ -233,6 +235,34 @@ describe('misc', () => { module.default.addFile(state, obj) expect(state.files).toMatchSnapshot() }) + + test('module.default.addFile with existing files array', () => { + const obj = { + file: { + file: 'path2', + url: 'string2', + nsfw: { + checking: false, + status: false, + }, + }, + address: 'address1', + } + module.default.addFile(state, obj) + const obj2 = { + file: { + file: 'path3', + url: 'string3', + nsfw: { + checking: false, + status: false, + }, + }, + address: 'address1', + } + module.default.addFile(state, obj2) + expect(state.files).toMatchSnapshot() + }) }) describe('module.default.chatText', () => { @@ -980,25 +1010,6 @@ describe.skip('module.default.deleteFiles', () => { }) describe('misc', () => { - const InitialChatState = (): ChatState => ({ - replies: [], - chatTexts: [], - files: {}, - countError: false, - currentChat: { - direction: 'TOP', - hasNextPage: true, - isMessagesLoading: false, - isScrollOver: true, - lastLoadedMessageId: '', - messages: [], - offset: 0, - page: 1, - showOlderMessagesInfo: false, - size: 10, - }, - }) - test('module.setCountError', () => { const argument = true const localState = { ...InitialChatState } @@ -1103,4 +1114,42 @@ describe('misc', () => { ], }) }) + + test('module.default.deleteFiles', () => { + const state = { + ...InitialChatState, + files: { + file1: [ + { + file: 'path2', + url: 'string2', + nsfw: { + checking: false, + status: false, + }, + progress: 0, + }, + ], + }, + } + + module.default.deleteFiles(state, 'file1') + expect(state.files).toEqual({}) + }) + + test('module.default.setDraftMessage', () => { + const state = { + ...InitialChatState, + draftMessages: { + conversation_id: 'no_message', + }, + } + const argument = { + conversationId: 'conversation_id', + message: 'message', + } + + module.default.setDraftMessage(state, argument) + expect(state.draftMessages[argument.conversationId]).toBe(argument.message) + }) }) diff --git a/store/conversation/mutations.test.ts b/store/conversation/mutations.test.ts index f002b507ff..75102976e4 100644 --- a/store/conversation/mutations.test.ts +++ b/store/conversation/mutations.test.ts @@ -3,6 +3,7 @@ import { ConversationConnection, ConversationState, } from './types' +import InitialConversationState from './state' import * as mutations from '~/store/conversation/mutations' describe('mutations.default.setConversation', () => { @@ -264,4 +265,15 @@ describe('misc', () => { // Both argument 2 and argument 3 are identical; both assertions will return true expect(result).toBe(undefined) }) + + test('mutations.default.resetConversation', () => { + const state = InitialConversationState() + + mutations.default.resetConversation(state) + + expect(state.id).toEqual('') + expect(state.type).toEqual('friend') + expect(state.calling).toEqual(false) + expect(state.participants).toEqual([]) + }) }) diff --git a/store/groups/actions.test.ts b/store/groups/actions.test.ts new file mode 100644 index 0000000000..fcd8319b27 --- /dev/null +++ b/store/groups/actions.test.ts @@ -0,0 +1,48 @@ +import * as module from './actions' +import InitialGroupsState from '~/store/groups/state' + +describe('Test store/groups/actions', () => { + it('should initialize', () => { + const dispatch = jest.fn() + const state = InitialGroupsState() + + const result = module.default.initialize({ dispatch, state }) + expect(result).toMatchSnapshot() + }) + + it('should create group', () => { + const commit = jest.fn() + const argument = { + name: 'example_name', + } + + const result = module.default.createGroup(commit, argument) + expect(result).toMatchSnapshot() + }) + + it('should add group', () => { + const commit = jest.fn() + const state = InitialGroupsState() + const argument = 'group_id' + + module.default.addGroup({ commit, state }, argument) + expect(commit).toHaveBeenCalled() + }) + + it('should add group that has already existed', () => { + const commit = jest.fn() + const state = InitialGroupsState() + const argument = 'group_id' + + module.default.addGroup({ commit, state }, argument) + expect(commit).not.toHaveBeenCalled() + }) + + it('should fetch group members', () => { + const commit = jest.fn() + const argument = 'group_id' + + module.default.addGroup(commit, argument) + expect(commit).toHaveBeenCalled() + }) +}) From 854617220c72f8b59569286aa87ad7c9106bdcda Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Wed, 7 Sep 2022 19:29:22 +0700 Subject: [PATCH 2/8] chore(jest): remove store/groups/actions because not needed --- store/groups/actions.test.ts | 48 ------------------------------------ 1 file changed, 48 deletions(-) delete mode 100644 store/groups/actions.test.ts diff --git a/store/groups/actions.test.ts b/store/groups/actions.test.ts deleted file mode 100644 index fcd8319b27..0000000000 --- a/store/groups/actions.test.ts +++ /dev/null @@ -1,48 +0,0 @@ -import * as module from './actions' -import InitialGroupsState from '~/store/groups/state' - -describe('Test store/groups/actions', () => { - it('should initialize', () => { - const dispatch = jest.fn() - const state = InitialGroupsState() - - const result = module.default.initialize({ dispatch, state }) - expect(result).toMatchSnapshot() - }) - - it('should create group', () => { - const commit = jest.fn() - const argument = { - name: 'example_name', - } - - const result = module.default.createGroup(commit, argument) - expect(result).toMatchSnapshot() - }) - - it('should add group', () => { - const commit = jest.fn() - const state = InitialGroupsState() - const argument = 'group_id' - - module.default.addGroup({ commit, state }, argument) - expect(commit).toHaveBeenCalled() - }) - - it('should add group that has already existed', () => { - const commit = jest.fn() - const state = InitialGroupsState() - const argument = 'group_id' - - module.default.addGroup({ commit, state }, argument) - expect(commit).not.toHaveBeenCalled() - }) - - it('should fetch group members', () => { - const commit = jest.fn() - const argument = 'group_id' - - module.default.addGroup(commit, argument) - expect(commit).toHaveBeenCalled() - }) -}) From 0c4d775447632e030e637ebe3a5e4f42557121ca Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Wed, 7 Sep 2022 19:32:48 +0700 Subject: [PATCH 3/8] chore(npm): remove empty peer dependencies --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index de0c7cdeb2..62fd61b745 100644 --- a/package.json +++ b/package.json @@ -170,5 +170,4 @@ "node": "16.15.0", "yarn": "1.22.19" }, - "peerDependencies": {} } From ac68a717e56040afcf4061f2a75b33fe593cb278 Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Wed, 7 Sep 2022 19:33:15 +0700 Subject: [PATCH 4/8] chore(npm): remove all changes to package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 62fd61b745..f7fb0bad29 100644 --- a/package.json +++ b/package.json @@ -169,5 +169,5 @@ "volta": { "node": "16.15.0", "yarn": "1.22.19" - }, + } } From 156e19b50bf04add97629092623f3b8862f2d132 Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Wed, 7 Sep 2022 19:33:58 +0700 Subject: [PATCH 5/8] chore(jest): remove unnecessary dependency on store/chat/mutations --- store/chat/mutations.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/store/chat/mutations.test.ts b/store/chat/mutations.test.ts index eede29bcae..31df1526a8 100644 --- a/store/chat/mutations.test.ts +++ b/store/chat/mutations.test.ts @@ -1,7 +1,6 @@ -import { ChatState, ChatFileUpload } from './types' +import { ChatFileUpload } from './types' import InitialChatState from './state' import * as module from '~/store/chat/mutations' -import { stat } from 'fs' describe('module.default.setChatReply', () => { test('0', () => { From 1b2a4a31560b60479a8fd474e3ad6371176208b9 Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Wed, 7 Sep 2022 19:47:33 +0700 Subject: [PATCH 6/8] feat(jest): add coverage for store/ui/actions --- store/ui/actions.test.ts | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 store/ui/actions.test.ts diff --git a/store/ui/actions.test.ts b/store/ui/actions.test.ts new file mode 100644 index 0000000000..efec904457 --- /dev/null +++ b/store/ui/actions.test.ts @@ -0,0 +1,44 @@ +import module from './actions' + +describe('Test store/ui', () => { + it('should set messages', () => { + const commit = jest.fn() + const argument = ['message 1', 'message 2'] + + module.setMessages({ commit }, argument) + + expect(commit).toHaveBeenCalled() + expect(commit).toHaveBeenCalledWith(argument) + }) + + it('should set isScrollOver', () => { + const commit = jest.fn() + const status = true + + module.setIsScrollOver({ commit }, status) + + expect(commit).toHaveBeenCalledWith(status) + }) + + it('should set activeChannel', () => { + const commit = jest.fn() + const channel = { + type: '', + id: '123', + name: 'John Doe', + } + + module.setActiveChannel({ commit }, channel) + + expect(commit).toHaveBeenCalledWith(channel) + }) + + it('should set isReacted', () => { + const commit = jest.fn() + const argument = false + + module.setIsReacted({ commit }, argument) + + expect(commit).toHaveBeenCalledWith(argument) + }) +}) From cb324d383369ab1f960caea686047fe266b200fe Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Wed, 7 Sep 2022 19:51:48 +0700 Subject: [PATCH 7/8] chore(jest): disabled test due to Iridium multiformats link issue --- store/ui/{actions.test.ts => actions.test.ts.disable} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename store/ui/{actions.test.ts => actions.test.ts.disable} (100%) diff --git a/store/ui/actions.test.ts b/store/ui/actions.test.ts.disable similarity index 100% rename from store/ui/actions.test.ts rename to store/ui/actions.test.ts.disable From 65991b2a9b979f4e617e70929cd0ea05dc11b256 Mon Sep 17 00:00:00 2001 From: Andre Christoga Pramaditya Date: Wed, 7 Sep 2022 23:14:36 +0700 Subject: [PATCH 8/8] chore(jest): rename file --- store/ui/{actions.test.ts.disable => actions.test.disabled.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename store/ui/{actions.test.ts.disable => actions.test.disabled.ts} (100%) diff --git a/store/ui/actions.test.ts.disable b/store/ui/actions.test.disabled.ts similarity index 100% rename from store/ui/actions.test.ts.disable rename to store/ui/actions.test.disabled.ts