Make minId reset with minVisibleId to prevent gaps when showing new

This commit is contained in:
shpuld 2019-03-10 22:40:48 +02:00
parent 841648676c
commit 70d7ed3607
2 changed files with 241 additions and 220 deletions

View file

@ -333,6 +333,7 @@ export const mutations = {
oldTimeline.newStatusCount = 0 oldTimeline.newStatusCount = 0
oldTimeline.visibleStatuses = slice(oldTimeline.statuses, 0, 50) oldTimeline.visibleStatuses = slice(oldTimeline.statuses, 0, 50)
oldTimeline.minVisibleId = last(oldTimeline.visibleStatuses).id oldTimeline.minVisibleId = last(oldTimeline.visibleStatuses).id
oldTimeline.minId = oldTimeline.minVisibleId
oldTimeline.visibleStatusesObject = {} oldTimeline.visibleStatusesObject = {}
each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status }) each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status })
}, },

View file

@ -14,14 +14,15 @@ const makeMockStatus = ({id, text, type = 'status'}) => {
} }
} }
describe('Statuses.prepareStatus', () => { describe('Statuses module', () => {
describe('prepareStatus', () => {
it('sets deleted flag to false', () => { it('sets deleted flag to false', () => {
const aStatus = makeMockStatus({id: '1', text: 'Hello oniichan'}) const aStatus = makeMockStatus({id: '1', text: 'Hello oniichan'})
expect(prepareStatus(aStatus).deleted).to.eq(false) expect(prepareStatus(aStatus).deleted).to.eq(false)
}) })
}) })
describe('The Statuses module', () => { describe('addNewStatuses', () => {
it('adds the status to allStatuses and to the given timeline', () => { it('adds the status to allStatuses and to the given timeline', () => {
const state = defaultState() const state = defaultState()
const status = makeMockStatus({id: '1'}) const status = makeMockStatus({id: '1'})
@ -238,7 +239,25 @@ describe('The Statuses module', () => {
expect(state.timelines.public.visibleStatuses[0].fave_num).to.eql(1) expect(state.timelines.public.visibleStatuses[0].fave_num).to.eql(1)
expect(state.timelines.public.visibleStatuses[0].favorited).to.eql(true) expect(state.timelines.public.visibleStatuses[0].favorited).to.eql(true)
}) })
})
describe('showNewStatuses', () => {
it('resets the minId to the min of the visible statuses when adding new to visible statuses', () => {
const state = defaultState()
const status = makeMockStatus({ id: '10' })
mutations.addNewStatuses(state, { statuses: [status], showImmediately: true, timeline: 'public' })
const newStatus = makeMockStatus({ id: '20' })
mutations.addNewStatuses(state, { statuses: [newStatus], showImmediately: false, timeline: 'public' })
state.timelines.public.minId = '5'
mutations.showNewStatuses(state, { timeline: 'public' })
expect(state.timelines.public.visibleStatuses.length).to.eql(2)
expect(state.timelines.public.minVisibleId).to.eql('10')
expect(state.timelines.public.minId).to.eql('10')
})
})
describe('clearTimeline', () => {
it('keeps userId when clearing user timeline', () => { it('keeps userId when clearing user timeline', () => {
const state = defaultState() const state = defaultState()
state.timelines.user.userId = 123 state.timelines.user.userId = 123
@ -247,6 +266,7 @@ describe('The Statuses module', () => {
expect(state.timelines.user.userId).to.eql(123) expect(state.timelines.user.userId).to.eql(123)
}) })
})
describe('notifications', () => { describe('notifications', () => {
it('removes a notification when the notice gets removed', () => { it('removes a notification when the notice gets removed', () => {