refs #1096 Reject duplicated status when append statuses in Notifications
This commit is contained in:
parent
542eaf2959
commit
9cdeba0df5
|
@ -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])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -41,11 +41,17 @@ const mutations: MutationTree<NotificationsState> = {
|
||||||
state.heading = value
|
state.heading = value
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.APPEND_NOTIFICATIONS]: (state, notification: Notification) => {
|
[MUTATION_TYPES.APPEND_NOTIFICATIONS]: (state, notification: Notification) => {
|
||||||
|
// 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) {
|
if (state.heading) {
|
||||||
state.notifications = [notification].concat(state.notifications)
|
state.notifications = [notification].concat(state.notifications)
|
||||||
} else {
|
} else {
|
||||||
state.unreadNotifications = [notification].concat(state.unreadNotifications)
|
state.unreadNotifications = [notification].concat(state.unreadNotifications)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[MUTATION_TYPES.UPDATE_NOTIFICATIONS]: (state, notifications: Array<Notification>) => {
|
[MUTATION_TYPES.UPDATE_NOTIFICATIONS]: (state, notifications: Array<Notification>) => {
|
||||||
state.notifications = notifications
|
state.notifications = notifications
|
||||||
|
|
Loading…
Reference in New Issue