Complete rewrite of status adding code.
This now uses nearly only mutation, to take advantage of vue's mutation tracking.
This commit is contained in:
parent
05afbbaf66
commit
9171b382fe
2 changed files with 120 additions and 126 deletions
|
@ -1,13 +1,14 @@
|
|||
import { cloneDeep } from 'lodash'
|
||||
import { defaultState, mutations, findMaxId, prepareStatus } from '../../../../src/modules/statuses.js'
|
||||
|
||||
const makeMockStatus = ({id, text}) => {
|
||||
const makeMockStatus = ({id, text, is_post_verb = true}) => {
|
||||
return {
|
||||
id,
|
||||
name: 'status',
|
||||
text: text || `Text number ${id}`,
|
||||
fave_num: 0,
|
||||
uri: ''
|
||||
uri: '',
|
||||
is_post_verb
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,6 +63,7 @@ describe('The Statuses module', () => {
|
|||
expect(state.allStatuses).to.eql([status])
|
||||
expect(state.timelines.public.statuses).to.eql([status])
|
||||
expect(state.timelines.public.visibleStatuses).to.eql([])
|
||||
expect(state.timelines.public.newStatusCount).to.equal(1)
|
||||
})
|
||||
|
||||
it('adds the status to allStatuses and to the given timeline, directly visible', () => {
|
||||
|
@ -73,12 +75,30 @@ describe('The Statuses module', () => {
|
|||
expect(state.allStatuses).to.eql([status])
|
||||
expect(state.timelines.public.statuses).to.eql([status])
|
||||
expect(state.timelines.public.visibleStatuses).to.eql([status])
|
||||
expect(state.timelines.public.newStatusCount).to.equal(0)
|
||||
})
|
||||
|
||||
it('keeps a descending by id order in timeline.visibleStatuses and timeline.statuses', () => {
|
||||
const state = cloneDeep(defaultState)
|
||||
const status = makeMockStatus({id: 2})
|
||||
const statusTwo = makeMockStatus({id: 1})
|
||||
const statusThree = makeMockStatus({id: 3})
|
||||
|
||||
mutations.addNewStatuses(state, { statuses: [status], showImmediately: true, timeline: 'public' })
|
||||
mutations.addNewStatuses(state, { statuses: [statusTwo], showImmediately: true, timeline: 'public' })
|
||||
|
||||
expect(state.timelines.public.minVisibleId).to.equal(1)
|
||||
|
||||
mutations.addNewStatuses(state, { statuses: [statusThree], showImmediately: true, timeline: 'public' })
|
||||
|
||||
expect(state.timelines.public.statuses).to.eql([statusThree, status, statusTwo])
|
||||
expect(state.timelines.public.visibleStatuses).to.eql([statusThree, status, statusTwo])
|
||||
})
|
||||
|
||||
it('splits retweets from their status and links them', () => {
|
||||
const state = cloneDeep(defaultState)
|
||||
const status = makeMockStatus({id: 1})
|
||||
const retweet = makeMockStatus({id: 2})
|
||||
const retweet = makeMockStatus({id: 2, is_post_verb: false})
|
||||
const modStatus = makeMockStatus({id: 1, text: 'something else'})
|
||||
|
||||
retweet.retweeted_status = status
|
||||
|
@ -86,12 +106,18 @@ describe('The Statuses module', () => {
|
|||
// It adds both statuses, but only the retweet to visible.
|
||||
mutations.addNewStatuses(state, { statuses: [retweet], timeline: 'public', showImmediately: true })
|
||||
expect(state.timelines.public.visibleStatuses).to.have.length(1)
|
||||
expect(state.allStatuses).to.eql([retweet, status])
|
||||
expect(state.timelines.public.statuses).to.have.length(1)
|
||||
expect(state.allStatuses).to.have.length(2)
|
||||
expect(state.allStatuses[0].id).to.equal(1)
|
||||
expect(state.allStatuses[1].id).to.equal(2)
|
||||
|
||||
// It refers to the modified status.
|
||||
mutations.addNewStatuses(state, { statuses: [modStatus], timeline: 'public' })
|
||||
expect(state.allStatuses).to.eql([retweet, modStatus])
|
||||
expect(retweet.retweeted_status).to.eql(modStatus)
|
||||
expect(state.allStatuses).to.have.length(2)
|
||||
expect(state.allStatuses[0].id).to.equal(1)
|
||||
expect(state.allStatuses[0].text).to.equal(modStatus.text)
|
||||
expect(state.allStatuses[1].id).to.equal(2)
|
||||
expect(retweet.retweeted_status.text).to.eql(modStatus.text)
|
||||
})
|
||||
|
||||
it('replaces existing statuses with the same id', () => {
|
||||
|
@ -108,14 +134,14 @@ describe('The Statuses module', () => {
|
|||
mutations.addNewStatuses(state, { statuses: [modStatus], showImmediately: true, timeline: 'public' })
|
||||
expect(state.timelines.public.visibleStatuses).to.have.length(1)
|
||||
expect(state.allStatuses).to.have.length(1)
|
||||
expect(state.allStatuses[0]).to.eql(modStatus)
|
||||
expect(state.allStatuses[0].text).to.eql(modStatus.text)
|
||||
})
|
||||
|
||||
it('replaces existing statuses with the same id, coming from a retweet', () => {
|
||||
const state = cloneDeep(defaultState)
|
||||
const status = makeMockStatus({id: 1})
|
||||
const modStatus = makeMockStatus({id: 1, text: 'something else'})
|
||||
const retweet = makeMockStatus({id: 2})
|
||||
const retweet = makeMockStatus({id: 2, is_post_verb: false})
|
||||
retweet.retweeted_status = modStatus
|
||||
|
||||
// Add original status
|
||||
|
@ -127,7 +153,7 @@ describe('The Statuses module', () => {
|
|||
mutations.addNewStatuses(state, { statuses: [retweet], showImmediately: false, timeline: 'public' })
|
||||
expect(state.timelines.public.visibleStatuses).to.have.length(1)
|
||||
expect(state.allStatuses).to.have.length(2)
|
||||
expect(state.allStatuses[0]).to.eql(modStatus)
|
||||
expect(state.allStatuses[0].text).to.eql(modStatus.text)
|
||||
})
|
||||
|
||||
it('handles favorite actions', () => {
|
||||
|
@ -148,11 +174,5 @@ describe('The Statuses module', () => {
|
|||
expect(state.timelines.public.visibleStatuses.length).to.eql(1)
|
||||
expect(state.timelines.public.visibleStatuses[0].fave_num).to.eql(1)
|
||||
expect(state.timelines.public.maxId).to.eq(favorite.id)
|
||||
|
||||
// Adding again shouldn't change anything
|
||||
mutations.addNewStatuses(state, { statuses: [favorite], showImmediately: true, timeline: 'public' })
|
||||
|
||||
expect(state.timelines.public.visibleStatuses.length).to.eql(1)
|
||||
expect(state.timelines.public.visibleStatuses[0].fave_num).to.eql(1)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue