Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jest): 100% coverage for store/chat/mutations #2509

Merged
merged 1 commit into from
Mar 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions store/chat/mutations.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as mutations from '~/store/chat/mutations'
import { UploadDropItemType } from '~/types/files/file'

describe('mutations.default.setChatReply', () => {
test('0', () => {
Expand Down Expand Up @@ -202,3 +203,98 @@ describe('mutations.default.chatText', () => {
expect(result).toMatchSnapshot()
})
})

describe('misc', () => {
const object2: any = [
{ userId: '12345', value: 'Dillenberg' },
{ userId: 'bc23a9d531064583ace8f67dad60f6bb', value: 'Dillenberg' },
{ userId: '12345', value: 'elio@example.com' },
{ userId: '9876', value: 'elio@example.com' },
]
const object: any = [
{ replyId: 'c466a48309794261b64a4f02cfcc3d64', value: false },
{ replyId: '12345', value: false },
]
const object3: UploadDropItemType[] = []
const state = { replies: object, chatTexts: object2, files: object3 }

test('mutations.default.addFile with empty files array', () => {
const obj = {
file: {
file: 'path',
url: 'string',
nsfw: {
checking: false,
status: false,
},
},
address: 'address1',
}
mutations.default.addFile(state, obj)
expect(state.files[obj.address]).toEqual([obj.file])
})
test.skip('draft mutations.default.addFile with non-empty files array', () => {
const state = {
replies: object,
chatTexts: object2,
files: [
{
file: 'path_file_0',
nsfw: { checking: false, status: false },
url: 'string',
},
],
}
const obj = {
file: {
file: 'path',
url: 'string',
nsfw: {
checking: false,
status: false,
},
},
address: 'address1',
}
mutations.default.addFile(state, obj)
expect(state.files[obj.address]).toEqual([obj.file])
})
test('mutations.default.setFiles', () => {
const state = { replies: object, chatTexts: object2, files: object3 }
const obj = {
files: {
file: 'path',
url: 'string',
nsfw: {
checking: false,
status: false,
},
},

address: 'address1',
}

mutations.default.setFiles(state, obj)
expect(state.files[obj.address]).toEqual(obj.files)
})
test('mutations.default.deleteFiles', () => {
const state = { replies: object, chatTexts: object2, files: object3 }
const obj = {
files: {
file: 'path',
url: 'string',
nsfw: {
checking: false,
status: false,
},
},

address: 'address1',
}

mutations.default.setFiles(state, obj)
expect(state.files[obj.address]).toEqual(obj.files)
mutations.default.deleteFiles(state, obj.address)
expect(state.files).not.toEqual(obj.files)
})
})