refs #1096 Reject duplicated status when append statuses in Notifications

This commit is contained in:
AkiraFukushima 2019-11-13 23:42:50 +09:00
parent 542eaf2959
commit 9cdeba0df5
2 changed files with 83 additions and 4 deletions

View File

@ -184,5 +184,78 @@ describe('TimelineSpace/Contents/Notifications', () => {
})
})
})
describe('appendTimeline', () => {
describe('heading', () => {
describe('normal', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
notifications: [notification1],
unreadNotifications: [],
filter: ''
}
})
it('should update timeline', () => {
Notifications.mutations![MUTATION_TYPES.APPEND_NOTIFICATIONS](state, notification2)
expect(state.notifications).toEqual([notification2, notification1])
expect(state.unreadNotifications).toEqual([])
})
})
describe('duplicated status', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: true,
notifications: [notification2, notification1],
unreadNotifications: [],
filter: ''
}
})
it('should not update timeline', () => {
Notifications.mutations![MUTATION_TYPES.APPEND_NOTIFICATIONS](state, notification2)
expect(state.notifications).toEqual([notification2, notification1])
expect(state.unreadNotifications).toEqual([])
})
})
})
describe('not heading', () => {
describe('normal', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: false,
notifications: [notification1],
unreadNotifications: [],
filter: ''
}
})
it('should update unreadTimeline', () => {
Notifications.mutations![MUTATION_TYPES.APPEND_NOTIFICATIONS](state, notification2)
expect(state.notifications).toEqual([notification1])
expect(state.unreadNotifications).toEqual([notification2])
})
})
describe('duplicated status', () => {
beforeEach(() => {
state = {
lazyLoading: false,
heading: false,
notifications: [notification1],
unreadNotifications: [notification2],
filter: ''
}
})
it('should not update unreadTimeline', () => {
Notifications.mutations![MUTATION_TYPES.APPEND_NOTIFICATIONS](state, notification2)
expect(state.notifications).toEqual([notification1])
expect(state.unreadNotifications).toEqual([notification2])
})
})
})
})
})
})

View File

@ -41,10 +41,16 @@ const mutations: MutationTree<NotificationsState> = {
state.heading = value
},
[MUTATION_TYPES.APPEND_NOTIFICATIONS]: (state, notification: Notification) => {
if (state.heading) {
state.notifications = [notification].concat(state.notifications)
} else {
state.unreadNotifications = [notification].concat(state.unreadNotifications)
// Reject duplicated status in timeline
if (
!state.notifications.find(item => item.id === notification.id) &&
!state.unreadNotifications.find(item => item.id === notification.id)
) {
if (state.heading) {
state.notifications = [notification].concat(state.notifications)
} else {
state.unreadNotifications = [notification].concat(state.unreadNotifications)
}
}
},
[MUTATION_TYPES.UPDATE_NOTIFICATIONS]: (state, notifications: Array<Notification>) => {