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/textile/getters #2952

Merged
merged 1 commit into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
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
8 changes: 0 additions & 8 deletions store/textile/__snapshots__/getters.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`getters.default.getConversation 0 1`] = `[Function]`;

exports[`getters.default.getConversation 1 1`] = `[Function]`;

exports[`getters.default.getConversation 2 1`] = `[Function]`;

exports[`getters.default.getConversationMessages 0 1`] = `[Function]`;

exports[`getters.default.getInitialized 0 1`] = `true`;

exports[`init should return the initialized variable of the state 1`] = `false`;
136 changes: 95 additions & 41 deletions store/textile/getters.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import * as getters from '~/store/textile/getters'
import {
decryptedMessage,
fileMessage,
glyphMessage,
imageMessage,
mediaMessage,
messageEncoder,
messageFromThread,
reactionMessage,
replyMessage,
textMessage,
} from '~/libraries/Textile/encoders'

describe('init', () => {
let inst: any
Expand Down Expand Up @@ -43,58 +55,100 @@ describe('getters.default.getInitialized', () => {
})
})

describe('getters.default.getConversationMessages', () => {
describe('getters.default.getConversation', () => {
test('0', () => {
const result: any = getters.default.getConversationMessages({
let localState = {
initialized: true,
activeConversation: '',
conversations: {},
conversationLoading: false,
messageLoading: false,
uploadProgress: {
key0: { progress: NaN, finished: false, name: '' },
key1: { progress: NaN, finished: false, name: '' },
key2: { progress: NaN, finished: true, name: '' },
activeConversation: '9876',
conversations: {
key0: {
messages: [
{
'01g12df0ey85k9905f85yj4c9c': {
from: 'bbaareibupvl76qkt2n3y7hlj7qmjmogtaw7eaaroj2bdlaao6dxet46bge',
to: 'bbaareidn44vnowdx6y4xfm7ypjh4zjm45qdrdb42uqg25jxtkv3ru2wqdq',
at: 1650422415838,
type: 'text',
payload: 'hey',
id: '01g12df0ey85k9905f85yj4c9c',
readAt: 0,
conversation: 'DA1kvHx1wXX3xLGwkX8in3DKoDcXqWJ9TtdvJJRuz41W',
},
},
],
replies: [],
reactions: [],
lastInbound: 1650422415838,
lastUpdate: 1650504356737,
lastMessage: {
conversation: 'DA1kvHx1wXX3xLGwkX8in3DKoDcXqWJ9TtdvJJRuz41W',
from: 'bbaareidn44vnowdx6y4xfm7ypjh4zjm45qdrdb42uqg25jxtkv3ru2wqdq',
to: 'bbaareibupvl76qkt2n3y7hlj7qmjmogtaw7eaaroj2bdlaao6dxet46bge',
at: 1650504356737,
type: 'glyph',
payload:
'https://satellite.mypinata.cloud/ipfs/QmRwZDz8qavwCcmq6DSDTDLrt1qzzw2nMcz1pcGuNxdhcW/$1/Sad3.gif',
pack: 'Astrobunny',
id: '01g14vkmw10bj09n45630t6m6a',
},
limit: 50,
skip: 0,
},
},
})
expect(result).toMatchSnapshot()
conversationLoading: false,
messageLoading: true,
uploadProgress: {},
}
const result: any = getters.default.getConversation(localState)
expect(result()).toBeNull()
})
})

describe('getters.default.getConversation', () => {
describe('getters.default.getConversationMessages', () => {
test('0', () => {
const result: any = getters.default.getConversation({
let localState = {
initialized: true,
activeConversation: '9876',
conversations: {},
conversations: {
key0: {
messages: [
{
'01g12df0ey85k9905f85yj4c9c': {
from: 'bbaareibupvl76qkt2n3y7hlj7qmjmogtaw7eaaroj2bdlaao6dxet46bge',
to: 'bbaareidn44vnowdx6y4xfm7ypjh4zjm45qdrdb42uqg25jxtkv3ru2wqdq',
at: 1650422415838,
type: 'text',
payload: 'hey',
id: '01g12df0ey85k9905f85yj4c9c',
readAt: 0,
conversation: 'DA1kvHx1wXX3xLGwkX8in3DKoDcXqWJ9TtdvJJRuz41W',
},
},
],
replies: [],
reactions: [],
lastInbound: 1650422415838,
lastUpdate: 1650504356737,
lastMessage: {
conversation: 'DA1kvHx1wXX3xLGwkX8in3DKoDcXqWJ9TtdvJJRuz41W',
from: 'bbaareidn44vnowdx6y4xfm7ypjh4zjm45qdrdb42uqg25jxtkv3ru2wqdq',
to: 'bbaareibupvl76qkt2n3y7hlj7qmjmogtaw7eaaroj2bdlaao6dxet46bge',
at: 1650504356737,
type: 'glyph',
payload:
'https://satellite.mypinata.cloud/ipfs/QmRwZDz8qavwCcmq6DSDTDLrt1qzzw2nMcz1pcGuNxdhcW/$1/Sad3.gif',
pack: 'Astrobunny',
id: '01g14vkmw10bj09n45630t6m6a',
},
limit: 50,
skip: 0,
},
},
conversationLoading: false,
messageLoading: true,
uploadProgress: {},
})
expect(result).toMatchSnapshot()
})

test('1', () => {
const result: any = getters.default.getConversation({
initialized: false,
activeConversation: 'bc23a9d531064583ace8f67dad60f6bb',
conversations: {},
conversationLoading: true,
messageLoading: false,
uploadProgress: {},
})
expect(result).toMatchSnapshot()
})

test('2', () => {
const result: any = getters.default.getConversation({
initialized: false,
activeConversation: '',
conversations: {},
conversationLoading: true,
messageLoading: true,
uploadProgress: {},
})
expect(result).toMatchSnapshot()
}
const result: any = getters.default.getConversationMessages(localState)
expect(result()).toEqual([])
})
})