refs #843 Add unit spec for mentions

This commit is contained in:
AkiraFukushima 2019-03-19 09:24:07 +09:00
parent dfd705b9d3
commit 68114b86f3
2 changed files with 114 additions and 1 deletions

View File

@ -0,0 +1,114 @@
import Mentions from '@/store/TimelineSpace/Contents/Mentions'
describe('TimelineSpace/Contents/Mentions', () => {
describe('mutations', () => {
let state
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
mentions: [],
unreadMentions: [],
filter: ''
}
})
describe('appendMentions', () => {
describe('heading', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
mentions: [5, 4, 3, 2, 1],
unreadMentions: [],
filter: ''
}
})
it('should update mentions', () => {
Mentions.mutations.appendMentions(state, 6)
expect(state.mentions).toEqual([6, 5, 4, 3, 2, 1])
expect(state.unreadMentions).toEqual([])
})
})
describe('not heading', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: false,
mentions: [5, 4, 3, 2, 1],
unreadMentions: [],
filter: ''
}
})
it('should update mentions', () => {
Mentions.mutations.appendMentions(state, 6)
expect(state.mentions).toEqual([5, 4, 3, 2, 1])
expect(state.unreadMentions).toEqual([6])
})
})
})
describe('mergeMentions', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: false,
mentions: [5, 4, 3, 2, 1],
unreadMentions: [8, 7, 6],
filter: ''
}
})
it('should be merged', () => {
Mentions.mutations.mergeMentions(state)
expect(state.mentions).toEqual([8, 7, 6, 5, 4, 3, 2, 1])
expect(state.unreadMentions).toEqual([])
})
})
describe('insertMentions', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: false,
mentions: [5, 4, 3, 2, 1],
unreadMentions: [],
filter: ''
}
})
it('should be inserted', () => {
Mentions.mutations.insertMentions(state, [ -1, -2, -3, -4])
expect(state.mentions).toEqual([5, 4, 3, 2, 1, -1, -2, -3, -4])
})
})
describe('updateToot', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: false,
mentions: [
{ type: 'mention', status: { id: 20, favourited: false } },
{ type: 'favourite', status: { id: 19, favourited: false } },
{ type: 'reblog', status: { id: 18, favourited: false } },
{ type: 'follow', status: { id: 17, favourited: false } },
{ type: 'mention', status: { id: 16, favourited: false } }
],
unreadMentions: [],
filter: ''
}
})
it('should be updated', () => {
Mentions.mutations.updateToot(state, { id: 20, favourited: true })
expect(state.mentions).toEqual(
[
{ type: 'mention', status: { id: 20, favourited: true } },
{ type: 'favourite', status: { id: 19, favourited: false } },
{ type: 'reblog', status: { id: 18, favourited: false } },
{ type: 'follow', status: { id: 17, favourited: false } },
{ type: 'mention', status: { id: 16, favourited: false } }
]
)
})
})
})
})

View File

@ -41,7 +41,6 @@ const Mentions = {
state.unreadMentions = []
},
updateToot (state, message) {
console.log(message)
state.mentions = state.mentions.map((mention) => {
if (mention.type === 'mention' && mention.status.id === message.id) {
const status = {