Skip to content

Commit

Permalink
feat(jest): improve numerous store tests (#4641)
Browse files Browse the repository at this point in the history
* feat(jest): lots of improvement on store

* chore(jest): remove store/groups/actions because not needed

* chore(npm): remove empty peer dependencies

* chore(npm): remove all changes to package.json

* chore(jest): remove unnecessary dependency on store/chat/mutations

* feat(jest): add coverage for store/ui/actions

* chore(jest): disabled test due to Iridium multiformats link issue

* chore(jest): rename file
  • Loading branch information
drepram committed Sep 8, 2022
1 parent 8129318 commit 3d963cf
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 20 deletions.
31 changes: 31 additions & 0 deletions store/chat/__snapshots__/mutations.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
88 changes: 68 additions & 20 deletions store/chat/mutations.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChatState, ChatFileUpload } from './types'
import { ChatFileUpload } from './types'
import InitialChatState from './state'
import * as module from '~/store/chat/mutations'

describe('module.default.setChatReply', () => {
Expand Down Expand Up @@ -233,6 +234,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', () => {
Expand Down Expand Up @@ -980,25 +1009,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 }
Expand Down Expand Up @@ -1103,4 +1113,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)
})
})
12 changes: 12 additions & 0 deletions store/conversation/mutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ConversationConnection,
ConversationState,
} from './types'
import InitialConversationState from './state'
import * as mutations from '~/store/conversation/mutations'

describe('mutations.default.setConversation', () => {
Expand Down Expand Up @@ -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([])
})
})
44 changes: 44 additions & 0 deletions store/ui/actions.test.disabled.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit 3d963cf

Please sign in to comment.