refs #1096 Reject duplicated status when append statuses in Lists
This commit is contained in:
parent
9cdeba0df5
commit
b48a877f5d
|
@ -85,30 +85,7 @@ const status2: Status = {
|
|||
pinned: null
|
||||
}
|
||||
|
||||
describe('TimelineSpace/Contents/Lists/Show', () => {
|
||||
describe('mutations', () => {
|
||||
let state: ShowState
|
||||
|
||||
describe('deleteToot', () => {
|
||||
describe('message is not reblogged', () => {
|
||||
beforeEach(() => {
|
||||
state = {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
timeline: [status2, status1],
|
||||
unreadTimeline: [],
|
||||
filter: ''
|
||||
}
|
||||
})
|
||||
it('should be deleted', () => {
|
||||
Show.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1.id)
|
||||
expect(state.timeline).toEqual([status2])
|
||||
})
|
||||
})
|
||||
|
||||
describe('message is reblogged', () => {
|
||||
beforeEach(() => {
|
||||
const rebloggedStatus: Status = {
|
||||
const rebloggedStatus: Status = {
|
||||
id: '3',
|
||||
uri: 'http://example.com',
|
||||
url: 'http://example.com',
|
||||
|
@ -138,7 +115,31 @@ describe('TimelineSpace/Contents/Lists/Show', () => {
|
|||
} as Application,
|
||||
language: null,
|
||||
pinned: null
|
||||
}
|
||||
|
||||
describe('TimelineSpace/Contents/Lists/Show', () => {
|
||||
describe('mutations', () => {
|
||||
let state: ShowState
|
||||
|
||||
describe('deleteToot', () => {
|
||||
describe('message is not reblogged', () => {
|
||||
beforeEach(() => {
|
||||
state = {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
timeline: [status2, status1],
|
||||
unreadTimeline: [],
|
||||
filter: ''
|
||||
}
|
||||
})
|
||||
it('should be deleted', () => {
|
||||
Show.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1.id)
|
||||
expect(state.timeline).toEqual([status2])
|
||||
})
|
||||
})
|
||||
|
||||
describe('message is reblogged', () => {
|
||||
beforeEach(() => {
|
||||
state = {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
|
@ -153,5 +154,79 @@ describe('TimelineSpace/Contents/Lists/Show', () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('appendTimeline', () => {
|
||||
describe('heading', () => {
|
||||
describe('normal', () => {
|
||||
beforeEach(() => {
|
||||
state = {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
timeline: [status2, status1],
|
||||
unreadTimeline: [],
|
||||
filter: ''
|
||||
}
|
||||
})
|
||||
it('should be updated timeline', () => {
|
||||
Show.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
||||
expect(state.unreadTimeline).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('duplicated status', () => {
|
||||
beforeEach(() => {
|
||||
state = {
|
||||
lazyLoading: false,
|
||||
heading: true,
|
||||
timeline: [rebloggedStatus, status2, status1],
|
||||
unreadTimeline: [],
|
||||
filter: ''
|
||||
}
|
||||
})
|
||||
it('should not be updated timeline', () => {
|
||||
Show.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
||||
expect(state.unreadTimeline).toEqual([])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('not heading', () => {
|
||||
describe('normal', () => {
|
||||
beforeEach(() => {
|
||||
state = {
|
||||
lazyLoading: false,
|
||||
heading: false,
|
||||
timeline: [status2, status1],
|
||||
unreadTimeline: [],
|
||||
filter: ''
|
||||
}
|
||||
})
|
||||
it('should be updated timeline', () => {
|
||||
Show.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||
expect(state.timeline).toEqual([status2, status1])
|
||||
expect(state.unreadTimeline).toEqual([rebloggedStatus])
|
||||
})
|
||||
})
|
||||
|
||||
describe('duplicated status', () => {
|
||||
beforeEach(() => {
|
||||
state = {
|
||||
lazyLoading: false,
|
||||
heading: false,
|
||||
timeline: [rebloggedStatus, status2, status1],
|
||||
unreadTimeline: [],
|
||||
filter: ''
|
||||
}
|
||||
})
|
||||
it('should not be updated timeline', () => {
|
||||
Show.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus)
|
||||
expect(state.timeline).toEqual([rebloggedStatus, status2, status1])
|
||||
expect(state.unreadTimeline).toEqual([])
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -39,11 +39,14 @@ const mutations: MutationTree<ShowState> = {
|
|||
state.heading = value
|
||||
},
|
||||
[MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => {
|
||||
// Reject duplicated status in timeline
|
||||
if (!state.timeline.find(item => item.id === update.id) && !state.unreadTimeline.find(item => item.id === update.id)) {
|
||||
if (state.heading) {
|
||||
state.timeline = [update].concat(state.timeline)
|
||||
} else {
|
||||
state.unreadTimeline = [update].concat(state.unreadTimeline)
|
||||
}
|
||||
}
|
||||
},
|
||||
[MUTATION_TYPES.UPDATE_TIMELINE]: (state, timeline: Array<Status>) => {
|
||||
state.timeline = timeline
|
||||
|
|
Loading…
Reference in New Issue