Skip to content

Commit

Permalink
feat(jest): 84% coverage for store/ui
Browse files Browse the repository at this point in the history
  • Loading branch information
drepram committed May 17, 2022
1 parent 2f86b32 commit fc8e3a6
Show file tree
Hide file tree
Showing 7 changed files with 879 additions and 2,452 deletions.
13 changes: 0 additions & 13 deletions store/ui/__snapshots__/actions.test.ts.snap

This file was deleted.

31 changes: 31 additions & 0 deletions store/ui/__snapshots__/getters.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`init get all unseen notifications 1`] = `
Array [
Object {
"_id": "01g2ya7w44h4c5mm4bgyedkrvy",
"_mod": 1652432302212590600,
"at": 1652432301322,
"content": Object {
"description": "New DM",
"title": "Notification",
},
"from": "Andre2",
"id": "62fceb8d-60a5-4434-92e8-c07f52f9e8e6",
"state": "UNREAD",
"type": "Direct Message",
},
Object {
"_id": "01g2y9d6499169rzs5etrff48w",
"_mod": 1652431427721842400,
"at": 1652431426842,
"content": Object {
"description": "New DM",
"title": "Notification",
},
"from": "Andre2",
"id": "69c1ad1d-37e9-4ff5-b929-de5509512a11",
"state": "UNREAD",
"type": "Direct Message",
},
]
`;

exports[`init should return the isFilesIndexLoading property of the initial state 1`] = `false`;

exports[`init should return the showSidebar property of the initial state 1`] = `true`;
Expand Down
152 changes: 0 additions & 152 deletions store/ui/__snapshots__/mutations.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -100,166 +100,14 @@ Array [
]
`;

exports[`mutations.default.addReaction 0 1`] = `undefined`;

exports[`mutations.default.addReaction 0 2`] = `undefined`;

exports[`mutations.default.addReaction 1 1`] = `undefined`;

exports[`mutations.default.addReaction 1 2`] = `undefined`;

exports[`mutations.default.addReaction 2 1`] = `undefined`;

exports[`mutations.default.addReaction 2 2`] = `undefined`;

exports[`mutations.default.addReaction 3 1`] = `undefined`;

exports[`mutations.default.addReaction 3 2`] = `undefined`;

exports[`mutations.default.addReaction 4 1`] = `undefined`;

exports[`mutations.default.addReaction 4 2`] = `undefined`;

exports[`mutations.default.addReaction 5 1`] = `undefined`;

exports[`mutations.default.addReaction 5 2`] = `undefined`;

exports[`mutations.default.sendMessage 0 1`] = `undefined`;

exports[`mutations.default.sendMessage 0 2`] = `undefined`;

exports[`mutations.default.sendMessage 0 3`] = `undefined`;

exports[`mutations.default.sendMessage 1 1`] = `undefined`;

exports[`mutations.default.sendMessage 1 2`] = `undefined`;

exports[`mutations.default.sendMessage 1 3`] = `undefined`;

exports[`mutations.default.sendMessage 2 1`] = `undefined`;

exports[`mutations.default.sendMessage 2 2`] = `undefined`;

exports[`mutations.default.sendMessage 2 3`] = `undefined`;

exports[`mutations.default.sendMessage 3 1`] = `undefined`;

exports[`mutations.default.sendMessage 3 2`] = `undefined`;

exports[`mutations.default.sendMessage 3 3`] = `undefined`;

exports[`mutations.default.sendMessage 4 1`] = `undefined`;

exports[`mutations.default.sendMessage 4 2`] = `undefined`;

exports[`mutations.default.sendMessage 4 3`] = `undefined`;

exports[`mutations.default.sendMessage 5 1`] = `undefined`;

exports[`mutations.default.sendMessage 5 2`] = `undefined`;

exports[`mutations.default.sendMessage 5 3`] = `undefined`;

exports[`mutations.default.setContextMenuPosition 0 1`] = `undefined`;

exports[`mutations.default.setContextMenuPosition 0 2`] = `undefined`;

exports[`mutations.default.setContextMenuPosition 1 1`] = `undefined`;

exports[`mutations.default.setContextMenuPosition 1 2`] = `undefined`;

exports[`mutations.default.setContextMenuPosition 2 1`] = `undefined`;

exports[`mutations.default.setContextMenuPosition 2 2`] = `undefined`;

exports[`mutations.default.setContextMenuPosition 3 1`] = `undefined`;

exports[`mutations.default.setContextMenuPosition 3 2`] = `undefined`;

exports[`mutations.default.setContextMenuPosition 4 1`] = `undefined`;

exports[`mutations.default.setContextMenuPosition 4 2`] = `undefined`;

exports[`mutations.default.setContextMenuPosition 5 1`] = `undefined`;

exports[`mutations.default.setContextMenuPosition 5 2`] = `undefined`;

exports[`mutations.default.setIsScrollOver 0 1`] = `undefined`;

exports[`mutations.default.setIsScrollOver 0 2`] = `undefined`;

exports[`mutations.default.setIsScrollOver 1 1`] = `undefined`;

exports[`mutations.default.setIsScrollOver 1 2`] = `undefined`;

exports[`mutations.default.setIsScrollOver 2 1`] = `undefined`;

exports[`mutations.default.setIsScrollOver 2 2`] = `undefined`;

exports[`mutations.default.setIsScrollOver 3 1`] = `undefined`;

exports[`mutations.default.setIsScrollOver 3 2`] = `undefined`;

exports[`mutations.default.setIsScrollOver 4 1`] = `undefined`;

exports[`mutations.default.setIsScrollOver 4 2`] = `undefined`;

exports[`mutations.default.setIsScrollOver 5 1`] = `undefined`;

exports[`mutations.default.setIsScrollOver 5 2`] = `undefined`;

exports[`mutations.default.toggleEnhancers 0 1`] = `undefined`;

exports[`mutations.default.toggleEnhancers 0 2`] = `undefined`;

exports[`mutations.default.toggleEnhancers 1 1`] = `undefined`;

exports[`mutations.default.toggleEnhancers 1 2`] = `undefined`;

exports[`mutations.default.toggleEnhancers 2 1`] = `undefined`;

exports[`mutations.default.toggleEnhancers 2 2`] = `undefined`;

exports[`mutations.default.toggleEnhancers 3 1`] = `undefined`;

exports[`mutations.default.toggleEnhancers 3 2`] = `undefined`;

exports[`mutations.default.toggleEnhancers 4 1`] = `undefined`;

exports[`mutations.default.toggleEnhancers 4 2`] = `undefined`;

exports[`mutations.default.toggleEnhancers 5 1`] = `undefined`;

exports[`mutations.default.toggleEnhancers 5 2`] = `undefined`;

exports[`mutations.default.toggleSettings 0 1`] = `undefined`;

exports[`mutations.default.toggleSettings 0 2`] = `undefined`;

exports[`mutations.default.toggleSettings 1 1`] = `undefined`;

exports[`mutations.default.toggleSettings 1 2`] = `undefined`;

exports[`mutations.default.toggleSettings 2 1`] = `undefined`;

exports[`mutations.default.toggleSettings 2 2`] = `undefined`;

exports[`mutations.default.toggleSettings 3 1`] = `undefined`;

exports[`mutations.default.toggleSettings 3 2`] = `undefined`;

exports[`mutations.default.toggleSettings 4 1`] = `undefined`;

exports[`mutations.default.toggleSettings 4 2`] = `undefined`;

exports[`mutations.default.toggleSettings 5 1`] = `undefined`;

exports[`mutations.default.toggleSettings 5 2`] = `undefined`;

exports[`mutations.default.updateMostUsedEmoji 0 1`] = `undefined`;

exports[`mutations.default.updateMostUsedEmoji 0 2`] = `undefined`;

exports[`mutations.default.updateRecentGlyphs 0 1`] = `undefined`;

exports[`mutations.default.updateRecentGlyphs 0 2`] = `undefined`;
146 changes: 95 additions & 51 deletions store/ui/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { DataStateType } from '~/store/dataState/types'
import { CaptureMouseTypes } from '~/store/settings/types'
import SoundManager from '~/libraries/SoundManager/SoundManager'
import TextileManager from '~/libraries/Textile/TextileManager'
import { TextileError } from '~/store/textile/types'
Vue.prototype.$TextileManager = new TextileManager()

const $Sounds = new SoundManager()

const initialRootState: any = {
accounts: {
storePin: true,
Expand Down Expand Up @@ -86,6 +85,7 @@ const initialRootState: any = {
typingState: 'NOT_TYPING',
item: {},
pending: true,
activeChat: true,
encryptedTextilePubkey: '',
name: 'Taurus Nix',
address: '0xdf9eb223bafbe5c5271415c75aecd68c21fe3d7f',
Expand Down Expand Up @@ -509,67 +509,111 @@ describe('init', () => {
)
expect(result).toBeUndefined()
})
})

describe('actions.default.clearKeybinds', () => {
test('0', async () => {
await actions.default.clearKeybinds(false)
test('removeSeenNotification', async () => {
const commit = jest.fn()
const rootState = { ...initialRootState }
const localInitState = { ...initialState }
const payload = '01g2y9d6499169rzs5etrff48w'
await actions.default.removeSeenNotification(
{ commit, localInitState, rootState },
payload,
)
expect(commit).toHaveBeenCalledWith('notificationSeen', payload)
})
test('sendNotification with initialized mailbox manager', async () => {
const TMConstructor = Vue.prototype.$TextileManager
TMConstructor.notificationManager = jest.fn()
TMConstructor.notificationManager.sendNotification = jest
.fn()
.mockReturnValueOnce({
note: 'notification response',
})
TMConstructor.notificationManager.isInitialized = jest
.fn()
.mockReturnValueOnce(true)

test('1', async () => {
await actions.default.clearKeybinds(true)
})
})
const commit = jest.fn()
const rootState = { ...initialRootState }

describe('actions.default.showQuickProfile', () => {
test('0', () => {
const result: any = actions.default.showQuickProfile(
'commit 03ccef2ffa982df061ae86ca8730cd9ad0af05b3\r\nAuthor: Ladarius Zboncak <[email protected]>\r\nDate: Wed Jul 28 2021 16:52:11 GMT+0200 (Central European Summer Time)\r\n\r\n    program wireless program\r\n',
'Alabama',
await actions.default.sendNotification(
{ commit, rootState },
{
message: 'message',
from: 'from',
imageHash: 'imageHash',
title: 'title',
type: 'DEV',
},
)
expect(result).toMatchSnapshot()
expect(commit).toHaveBeenCalledWith('sendNotification', {
note: 'notification response',
})
})
test('sendNotification without an initialized mailbox manager', async () => {
const TMConstructor = Vue.prototype.$TextileManager
TMConstructor.notificationManager = jest.fn()
TMConstructor.notificationManager.isInitialized = jest
.fn()
.mockReturnValueOnce(false)

test('1', () => {
const result: any = actions.default.showQuickProfile(
'commit d3f6bf9bcee016096098e88aced2d5afdc68c424\r\nAuthor: Edna Rice <[email protected]>\r\nDate: Wed Jul 28 2021 22:05:49 GMT+0200 (Central European Summer Time)\r\n\r\n    bypass cross-platform hard drive\r\n',
'Abruzzo',
)
expect(result).toMatchSnapshot()
})
const commit = jest.fn()
const rootState = { ...initialRootState }

test('2', () => {
const result: any = actions.default.showQuickProfile(
'commit f20ba84baadcbd1f3a45d95e9bb5aef588f4e902\r\nAuthor: Marty Douglas <[email protected]>\r\nDate: Thu Jul 29 2021 09:06:18 GMT+0200 (Central European Summer Time)\r\n\r\n    override solid state microchip\r\n',
'Alabama',
)
expect(result).toMatchSnapshot()
try {
await actions.default.sendNotification(
{ commit, rootState },
{
message: 'message',
from: 'from',
imageHash: 'imageHash',
title: 'title',
type: 'DEV',
},
)
} catch (error) {
expect(error).toBeInstanceOf(Error)
expect(error).toHaveProperty(
'message',
TextileError.MAILBOX_MANAGER_NOT_INITIALIZED,
)
}
})
test('sendNotification with initialized mailbox manager', async () => {
const TMConstructor = Vue.prototype.$TextileManager
TMConstructor.notificationManager = jest.fn()
TMConstructor.notificationManager.getnotifications = jest
.fn()
.mockReturnValueOnce({
note: 'notification response',
})
TMConstructor.notificationManager.isInitialized = jest
.fn()
.mockReturnValueOnce(true)

test('3', () => {
const result: any = actions.default.showQuickProfile(
'commit e6d1117d97e7cc250166120d2eee1c2662c58150\r\nAuthor: Keagan Cole <[email protected]>\r\nDate: Thu Jul 29 2021 05:36:16 GMT+0200 (Central European Summer Time)\r\n\r\n    override wireless alarm\r\n',
'Île-de-France',
)
expect(result).toMatchSnapshot()
})
const commit = jest.fn()

test('4', () => {
const result: any = actions.default.showQuickProfile(
'commit e6d1117d97e7cc250166120d2eee1c2662c58150\r\nAuthor: Keagan Cole <[email protected]>\r\nDate: Thu Jul 29 2021 05:36:16 GMT+0200 (Central European Summer Time)\r\n\r\n    override wireless alarm\r\n',
'Abruzzo',
)
expect(result).toMatchSnapshot()
await actions.default.setNotifications({ commit })
expect(commit).toHaveBeenCalledWith('setNotifications', {
note: 'notification response',
})
})
test('setNotifications without an initialized mailbox manager', async () => {
const TMConstructor = Vue.prototype.$TextileManager
TMConstructor.notificationManager = jest.fn()
TMConstructor.notificationManager.isInitialized = jest
.fn()
.mockReturnValueOnce(false)

test('5', () => {
const result: any = actions.default.showQuickProfile('', '')
expect(result).toMatchSnapshot()
})
})
const commit = jest.fn()

describe('actions.default.showProfile', () => {
test('0', async () => {
await actions.default.showProfile('', '')
try {
await actions.default.setNotifications({ commit })
} catch (error) {
expect(error).toBeInstanceOf(Error)
expect(error).toHaveProperty(
'message',
TextileError.MAILBOX_MANAGER_NOT_INITIALIZED,
)
}
})
})
Loading

0 comments on commit fc8e3a6

Please sign in to comment.