diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/DirectMessages.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/DirectMessages.spec.ts index d976ecaa..fa0c5249 100644 --- a/spec/renderer/unit/store/TimelineSpace/Contents/DirectMessages.spec.ts +++ b/spec/renderer/unit/store/TimelineSpace/Contents/DirectMessages.spec.ts @@ -85,6 +85,38 @@ const status2: Status = { pinned: null } +const rebloggedStatus: Status = { + id: '3', + uri: 'http://example.com', + url: 'http://example.com', + account: account, + in_reply_to_id: null, + in_reply_to_account_id: null, + reblog: status1, + content: '', + created_at: '2019-03-31T21:40:32', + emojis: [], + replies_count: 0, + reblogs_count: 0, + favourites_count: 0, + reblogged: null, + favourited: null, + muted: null, + sensitive: false, + spoiler_text: '', + visibility: 'public', + media_attachments: [], + mentions: [], + tags: [], + card: null, + poll: null, + application: { + name: 'Web' + } as Application, + language: null, + pinned: null +} + describe('TimelineSpace/Contents/DirectMessages', () => { describe('mutations', () => { let state: DirectMessagesState @@ -108,37 +140,6 @@ describe('TimelineSpace/Contents/DirectMessages', () => { describe('message is reblogged', () => { beforeEach(() => { - const rebloggedStatus: Status = { - id: '3', - uri: 'http://example.com', - url: 'http://example.com', - account: account, - in_reply_to_id: null, - in_reply_to_account_id: null, - reblog: status1, - content: '', - created_at: '2019-03-31T21:40:32', - emojis: [], - replies_count: 0, - reblogs_count: 0, - favourites_count: 0, - reblogged: null, - favourited: null, - muted: null, - sensitive: false, - spoiler_text: '', - visibility: 'public', - media_attachments: [], - mentions: [], - tags: [], - card: null, - poll: null, - application: { - name: 'Web' - } as Application, - language: null, - pinned: null - } state = { lazyLoading: false, heading: true, @@ -153,5 +154,79 @@ describe('TimelineSpace/Contents/DirectMessages', () => { }) }) }) + + describe('appendTimeline', () => { + describe('heading', () => { + describe('normal', () => { + beforeEach(() => { + state = { + lazyLoading: false, + heading: true, + timeline: [status2, status1], + unreadTimeline: [], + filter: '' + } + }) + it('should be updated timeline', () => { + DirectMessages.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', () => { + DirectMessages.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', () => { + DirectMessages.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', () => { + DirectMessages.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus) + expect(state.timeline).toEqual([rebloggedStatus, status2, status1]) + expect(state.unreadTimeline).toEqual([]) + }) + }) + }) + }) }) }) diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Hashtag/Tag.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Hashtag/Tag.spec.ts index e5151fbc..e05edaed 100644 --- a/spec/renderer/unit/store/TimelineSpace/Contents/Hashtag/Tag.spec.ts +++ b/spec/renderer/unit/store/TimelineSpace/Contents/Hashtag/Tag.spec.ts @@ -85,6 +85,38 @@ const status2: Status = { pinned: null } +const rebloggedStatus: Status = { + id: '3', + uri: 'http://example.com', + url: 'http://example.com', + account: account, + in_reply_to_id: null, + in_reply_to_account_id: null, + reblog: status1, + content: '', + created_at: '2019-03-31T21:40:32', + emojis: [], + replies_count: 0, + reblogs_count: 0, + favourites_count: 0, + reblogged: null, + favourited: null, + muted: null, + sensitive: false, + spoiler_text: '', + visibility: 'public', + media_attachments: [], + mentions: [], + tags: [], + card: null, + poll: null, + application: { + name: 'Web' + } as Application, + language: null, + pinned: null +} + describe('TimelineSpace/Contents/Hashtag/Tag', () => { describe('mutations', () => { let state: TagState @@ -108,37 +140,6 @@ describe('TimelineSpace/Contents/Hashtag/Tag', () => { describe('message is reblogged', () => { beforeEach(() => { - const rebloggedStatus: Status = { - id: '3', - uri: 'http://example.com', - url: 'http://example.com', - account: account, - in_reply_to_id: null, - in_reply_to_account_id: null, - reblog: status1, - content: '', - created_at: '2019-03-31T21:40:32', - emojis: [], - replies_count: 0, - reblogs_count: 0, - favourites_count: 0, - reblogged: null, - favourited: null, - muted: null, - sensitive: false, - spoiler_text: '', - visibility: 'public', - media_attachments: [], - mentions: [], - tags: [], - card: null, - poll: null, - application: { - name: 'Web' - } as Application, - language: null, - pinned: null - } state = { lazyLoading: false, heading: true, @@ -153,5 +154,79 @@ describe('TimelineSpace/Contents/Hashtag/Tag', () => { }) }) }) + + describe('appendTimeline', () => { + describe('heading', () => { + describe('normal', () => { + beforeEach(() => { + state = { + lazyLoading: false, + heading: true, + timeline: [status2, status1], + unreadTimeline: [], + filter: '' + } + }) + it('should be updated timeline', () => { + Tag.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', () => { + Tag.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', () => { + Tag.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', () => { + Tag.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus) + expect(state.timeline).toEqual([rebloggedStatus, status2, status1]) + expect(state.unreadTimeline).toEqual([]) + }) + }) + }) + }) }) }) diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Home.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Home.spec.ts index 84969ad3..800c9ec4 100644 --- a/spec/renderer/unit/store/TimelineSpace/Contents/Home.spec.ts +++ b/spec/renderer/unit/store/TimelineSpace/Contents/Home.spec.ts @@ -116,40 +116,81 @@ describe('TimelineSpace/Contents/Home', () => { describe('appendTimeline', () => { describe('heading', () => { - beforeEach(() => { - state = { - lazyLoading: false, - heading: true, - timeline: [status1], - unreadTimeline: [], - filter: '', - showReblogs: true, - showReplies: true - } + describe('normal', () => { + beforeEach(() => { + state = { + lazyLoading: false, + heading: true, + timeline: [status1], + unreadTimeline: [], + filter: '', + showReblogs: true, + showReplies: true + } + }) + it('should update timeline', () => { + Home.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, status2) + expect(state.timeline).toEqual([status2, status1]) + expect(state.unreadTimeline).toEqual([]) + }) }) - it('should update timeline', () => { - Home.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, status2) - expect(state.timeline).toEqual([status2, status1]) - expect(state.unreadTimeline).toEqual([]) + + describe('duplicated status', () => { + beforeEach(() => { + state = { + lazyLoading: false, + heading: true, + timeline: [status2, status1], + unreadTimeline: [], + filter: '', + showReblogs: true, + showReplies: true + } + }) + it('should not update timeline', () => { + Home.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, status2) + expect(state.timeline).toEqual([status2, status1]) + expect(state.unreadTimeline).toEqual([]) + }) }) }) describe('not heading', () => { - beforeEach(() => { - state = { - lazyLoading: false, - heading: false, - timeline: [status1], - unreadTimeline: [], - filter: '', - showReblogs: true, - showReplies: true - } + describe('normal', () => { + beforeEach(() => { + state = { + lazyLoading: false, + heading: false, + timeline: [status1], + unreadTimeline: [], + filter: '', + showReblogs: true, + showReplies: true + } + }) + it('should update unreadTimeline', () => { + Home.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, status2) + expect(state.timeline).toEqual([status1]) + expect(state.unreadTimeline).toEqual([status2]) + }) }) - it('should update unreadTimeline', () => { - Home.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, status2) - expect(state.timeline).toEqual([status1]) - expect(state.unreadTimeline).toEqual([status2]) + describe('duplicated status', () => { + beforeEach(() => { + state = { + lazyLoading: false, + heading: false, + timeline: [], + unreadTimeline: [status2, status1], + filter: '', + showReblogs: true, + showReplies: true + } + }) + it('should not update unreadTimeline', () => { + Home.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, status2) + expect(state.timeline).toEqual([]) + expect(state.unreadTimeline).toEqual([status2, status1]) + }) }) }) }) diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Lists/Show.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Lists/Show.spec.ts index 5781a43d..bae785cb 100644 --- a/spec/renderer/unit/store/TimelineSpace/Contents/Lists/Show.spec.ts +++ b/spec/renderer/unit/store/TimelineSpace/Contents/Lists/Show.spec.ts @@ -85,6 +85,38 @@ const status2: Status = { pinned: null } +const rebloggedStatus: Status = { + id: '3', + uri: 'http://example.com', + url: 'http://example.com', + account: account, + in_reply_to_id: null, + in_reply_to_account_id: null, + reblog: status1, + content: '', + created_at: '2019-03-31T21:40:32', + emojis: [], + replies_count: 0, + reblogs_count: 0, + favourites_count: 0, + reblogged: null, + favourited: null, + muted: null, + sensitive: false, + spoiler_text: '', + visibility: 'public', + media_attachments: [], + mentions: [], + tags: [], + card: null, + poll: null, + application: { + name: 'Web' + } as Application, + language: null, + pinned: null +} + describe('TimelineSpace/Contents/Lists/Show', () => { describe('mutations', () => { let state: ShowState @@ -108,37 +140,6 @@ describe('TimelineSpace/Contents/Lists/Show', () => { describe('message is reblogged', () => { beforeEach(() => { - const rebloggedStatus: Status = { - id: '3', - uri: 'http://example.com', - url: 'http://example.com', - account: account, - in_reply_to_id: null, - in_reply_to_account_id: null, - reblog: status1, - content: '', - created_at: '2019-03-31T21:40:32', - emojis: [], - replies_count: 0, - reblogs_count: 0, - favourites_count: 0, - reblogged: null, - favourited: null, - muted: null, - sensitive: false, - spoiler_text: '', - visibility: 'public', - media_attachments: [], - mentions: [], - tags: [], - card: null, - poll: null, - application: { - name: 'Web' - } as Application, - language: null, - pinned: null - } 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([]) + }) + }) + }) + }) }) }) diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Local.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Local.spec.ts index 10dc8fa9..899eb185 100644 --- a/spec/renderer/unit/store/TimelineSpace/Contents/Local.spec.ts +++ b/spec/renderer/unit/store/TimelineSpace/Contents/Local.spec.ts @@ -85,6 +85,38 @@ const status2: Status = { pinned: null } +const rebloggedStatus: Status = { + id: '3', + uri: 'http://example.com', + url: 'http://example.com', + account: account, + in_reply_to_id: null, + in_reply_to_account_id: null, + reblog: status1, + content: '', + created_at: '2019-03-31T21:40:32', + emojis: [], + replies_count: 0, + reblogs_count: 0, + favourites_count: 0, + reblogged: null, + favourited: null, + muted: null, + sensitive: false, + spoiler_text: '', + visibility: 'public', + media_attachments: [], + mentions: [], + tags: [], + card: null, + poll: null, + application: { + name: 'Web' + } as Application, + language: null, + pinned: null +} + describe('TimelineSpace/Contents/Local', () => { describe('mutations', () => { let state: LocalState @@ -108,37 +140,6 @@ describe('TimelineSpace/Contents/Local', () => { describe('message is reblogged', () => { beforeEach(() => { - const rebloggedStatus: Status = { - id: '3', - uri: 'http://example.com', - url: 'http://example.com', - account: account, - in_reply_to_id: null, - in_reply_to_account_id: null, - reblog: status1, - content: '', - created_at: '2019-03-31T21:40:32', - emojis: [], - replies_count: 0, - reblogs_count: 0, - favourites_count: 0, - reblogged: null, - favourited: null, - muted: null, - sensitive: false, - spoiler_text: '', - visibility: 'public', - media_attachments: [], - mentions: [], - tags: [], - card: null, - poll: null, - application: { - name: 'Web' - } as Application, - language: null, - pinned: null - } state = { lazyLoading: false, heading: true, @@ -153,5 +154,78 @@ describe('TimelineSpace/Contents/Local', () => { }) }) }) + describe('appendTimeline', () => { + describe('heading', () => { + describe('normal', () => { + beforeEach(() => { + state = { + lazyLoading: false, + heading: true, + timeline: [status2, status1], + unreadTimeline: [], + filter: '' + } + }) + it('should be updated timeline', () => { + Local.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', () => { + Local.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', () => { + Local.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', () => { + Local.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus) + expect(state.timeline).toEqual([rebloggedStatus, status2, status1]) + expect(state.unreadTimeline).toEqual([]) + }) + }) + }) + }) }) }) diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Mentions.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Mentions.spec.ts index 57abf3c2..eff364f1 100644 --- a/spec/renderer/unit/store/TimelineSpace/Contents/Mentions.spec.ts +++ b/spec/renderer/unit/store/TimelineSpace/Contents/Mentions.spec.ts @@ -172,35 +172,74 @@ describe('TimelineSpace/Contents/Mentions', () => { describe('appendMentions', () => { describe('heading', () => { - beforeEach(() => { - state = { - lazyLoading: false, - heading: true, - mentions: [notification1], - unreadMentions: [], - filter: '' - } + describe('normal', () => { + beforeEach(() => { + state = { + lazyLoading: false, + heading: true, + mentions: [notification1], + unreadMentions: [], + filter: '' + } + }) + it('should update mentions', () => { + Mentions.mutations![MUTATION_TYPES.APPEND_MENTIONS](state, notification2) + expect(state.mentions).toEqual([notification2, notification1]) + expect(state.unreadMentions).toEqual([]) + }) }) - it('should update mentions', () => { - Mentions.mutations![MUTATION_TYPES.APPEND_MENTIONS](state, notification2) - expect(state.mentions).toEqual([notification2, notification1]) - expect(state.unreadMentions).toEqual([]) + + describe('duplicated status', () => { + beforeEach(() => { + state = { + lazyLoading: false, + heading: true, + mentions: [notification2, notification1], + unreadMentions: [], + filter: '' + } + }) + it('should not be updated mentions', () => { + Mentions.mutations![MUTATION_TYPES.APPEND_MENTIONS](state, notification2) + expect(state.mentions).toEqual([notification2, notification1]) + expect(state.unreadMentions).toEqual([]) + }) }) }) + describe('not heading', () => { - beforeEach(() => { - state = { - lazyLoading: false, - heading: false, - mentions: [notification1], - unreadMentions: [], - filter: '' - } + describe('normal', () => { + beforeEach(() => { + state = { + lazyLoading: false, + heading: false, + mentions: [notification1], + unreadMentions: [], + filter: '' + } + }) + it('should update mentions', () => { + Mentions.mutations![MUTATION_TYPES.APPEND_MENTIONS](state, notification2) + expect(state.mentions).toEqual([notification1]) + expect(state.unreadMentions).toEqual([notification2]) + }) }) - it('should update mentions', () => { - Mentions.mutations![MUTATION_TYPES.APPEND_MENTIONS](state, notification2) - expect(state.mentions).toEqual([notification1]) - expect(state.unreadMentions).toEqual([notification2]) + + describe('duplicated status', () => { + beforeEach(() => { + state = { + lazyLoading: false, + heading: false, + mentions: [notification1], + unreadMentions: [notification2], + filter: '' + } + }) + it('should not be updated mentions', () => { + Mentions.mutations![MUTATION_TYPES.APPEND_MENTIONS](state, notification2) + expect(state.mentions).toEqual([notification1]) + expect(state.unreadMentions).toEqual([notification2]) + }) }) }) }) diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Notifications.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Notifications.spec.ts index 6a7531ab..99f54e36 100644 --- a/spec/renderer/unit/store/TimelineSpace/Contents/Notifications.spec.ts +++ b/spec/renderer/unit/store/TimelineSpace/Contents/Notifications.spec.ts @@ -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]) + }) + }) + }) + }) }) }) diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Public.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Public.spec.ts index 33a3b19b..183cbb4e 100644 --- a/spec/renderer/unit/store/TimelineSpace/Contents/Public.spec.ts +++ b/spec/renderer/unit/store/TimelineSpace/Contents/Public.spec.ts @@ -85,6 +85,38 @@ const status2: Status = { pinned: null } +const rebloggedStatus: Status = { + id: '3', + uri: 'http://example.com', + url: 'http://example.com', + account: account, + in_reply_to_id: null, + in_reply_to_account_id: null, + reblog: status1, + content: '', + created_at: '2019-03-31T21:40:32', + emojis: [], + replies_count: 0, + reblogs_count: 0, + favourites_count: 0, + reblogged: null, + favourited: null, + muted: null, + sensitive: false, + spoiler_text: '', + visibility: 'public', + media_attachments: [], + mentions: [], + tags: [], + card: null, + poll: null, + application: { + name: 'Web' + } as Application, + language: null, + pinned: null +} + describe('TimelineSpace/Contents/Local', () => { describe('mutations', () => { let state: PublicState @@ -108,37 +140,6 @@ describe('TimelineSpace/Contents/Local', () => { describe('message is reblogged', () => { beforeEach(() => { - const rebloggedStatus: Status = { - id: '3', - uri: 'http://example.com', - url: 'http://example.com', - account: account, - in_reply_to_id: null, - in_reply_to_account_id: null, - reblog: status1, - content: '', - created_at: '2019-03-31T21:40:32', - emojis: [], - replies_count: 0, - reblogs_count: 0, - favourites_count: 0, - reblogged: null, - favourited: null, - muted: null, - sensitive: false, - spoiler_text: '', - visibility: 'public', - media_attachments: [], - mentions: [], - tags: [], - card: null, - poll: null, - application: { - name: 'Web' - } as Application, - language: null, - pinned: null - } state = { lazyLoading: false, heading: true, @@ -153,5 +154,79 @@ describe('TimelineSpace/Contents/Local', () => { }) }) }) + + describe('appendTimeline', () => { + describe('heading', () => { + describe('normal', () => { + beforeEach(() => { + state = { + lazyLoading: false, + heading: true, + timeline: [status2, status1], + unreadTimeline: [], + filter: '' + } + }) + it('should be updated timeline', () => { + Public.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', () => { + Public.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', () => { + Public.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', () => { + Public.mutations![MUTATION_TYPES.APPEND_TIMELINE](state, rebloggedStatus) + expect(state.timeline).toEqual([rebloggedStatus, status2, status1]) + expect(state.unreadTimeline).toEqual([]) + }) + }) + }) + }) }) }) diff --git a/src/renderer/store/TimelineSpace/Contents/DirectMessages.ts b/src/renderer/store/TimelineSpace/Contents/DirectMessages.ts index fa6d437f..3a51aa75 100644 --- a/src/renderer/store/TimelineSpace/Contents/DirectMessages.ts +++ b/src/renderer/store/TimelineSpace/Contents/DirectMessages.ts @@ -40,10 +40,13 @@ const mutations: MutationTree = { state.heading = value }, [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => { - if (state.heading) { - state.timeline = [update].concat(state.timeline) - } else { - state.unreadTimeline = [update].concat(state.unreadTimeline) + // 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, messages: Array) => { diff --git a/src/renderer/store/TimelineSpace/Contents/Hashtag/Tag.ts b/src/renderer/store/TimelineSpace/Contents/Hashtag/Tag.ts index e732351f..9bb43811 100644 --- a/src/renderer/store/TimelineSpace/Contents/Hashtag/Tag.ts +++ b/src/renderer/store/TimelineSpace/Contents/Hashtag/Tag.ts @@ -39,10 +39,13 @@ const mutations: MutationTree = { state.heading = value }, [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => { - if (state.heading) { - state.timeline = [update].concat(state.timeline) - } else { - state.unreadTimeline = [update].concat(state.unreadTimeline) + // 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) => { diff --git a/src/renderer/store/TimelineSpace/Contents/Home.ts b/src/renderer/store/TimelineSpace/Contents/Home.ts index f2326d7d..5518ab54 100644 --- a/src/renderer/store/TimelineSpace/Contents/Home.ts +++ b/src/renderer/store/TimelineSpace/Contents/Home.ts @@ -46,10 +46,13 @@ const mutations: MutationTree = { state.heading = value }, [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => { - if (state.heading) { - state.timeline = [update].concat(state.timeline) - } else { - state.unreadTimeline = [update].concat(state.unreadTimeline) + // 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, messages: Array) => { diff --git a/src/renderer/store/TimelineSpace/Contents/Lists/Show.ts b/src/renderer/store/TimelineSpace/Contents/Lists/Show.ts index cb938e70..78a8adbc 100644 --- a/src/renderer/store/TimelineSpace/Contents/Lists/Show.ts +++ b/src/renderer/store/TimelineSpace/Contents/Lists/Show.ts @@ -39,10 +39,13 @@ const mutations: MutationTree = { state.heading = value }, [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => { - if (state.heading) { - state.timeline = [update].concat(state.timeline) - } else { - state.unreadTimeline = [update].concat(state.unreadTimeline) + // 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) => { diff --git a/src/renderer/store/TimelineSpace/Contents/Local.ts b/src/renderer/store/TimelineSpace/Contents/Local.ts index d773feb0..3e988789 100644 --- a/src/renderer/store/TimelineSpace/Contents/Local.ts +++ b/src/renderer/store/TimelineSpace/Contents/Local.ts @@ -37,10 +37,13 @@ const mutations: MutationTree = { state.heading = value }, [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => { - if (state.heading) { - state.timeline = [update].concat(state.timeline) - } else { - state.unreadTimeline = [update].concat(state.unreadTimeline) + // 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, messages: Array) => { diff --git a/src/renderer/store/TimelineSpace/Contents/Mentions.ts b/src/renderer/store/TimelineSpace/Contents/Mentions.ts index ccc8f796..58ace721 100644 --- a/src/renderer/store/TimelineSpace/Contents/Mentions.ts +++ b/src/renderer/store/TimelineSpace/Contents/Mentions.ts @@ -40,10 +40,13 @@ const mutations: MutationTree = { state.heading = value }, [MUTATION_TYPES.APPEND_MENTIONS]: (state, update: Notification) => { - if (state.heading) { - state.mentions = [update].concat(state.mentions) - } else { - state.unreadMentions = [update].concat(state.unreadMentions) + // Reject duplicated status in timeline + if (!state.mentions.find(item => item.id === update.id) && !state.unreadMentions.find(item => item.id === update.id)) { + if (state.heading) { + state.mentions = [update].concat(state.mentions) + } else { + state.unreadMentions = [update].concat(state.unreadMentions) + } } }, [MUTATION_TYPES.UPDATE_MENTIONS]: (state, messages: Array) => { diff --git a/src/renderer/store/TimelineSpace/Contents/Notifications.ts b/src/renderer/store/TimelineSpace/Contents/Notifications.ts index 1225b95e..2e245bbd 100644 --- a/src/renderer/store/TimelineSpace/Contents/Notifications.ts +++ b/src/renderer/store/TimelineSpace/Contents/Notifications.ts @@ -41,10 +41,16 @@ const mutations: MutationTree = { 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) => { diff --git a/src/renderer/store/TimelineSpace/Contents/Public.ts b/src/renderer/store/TimelineSpace/Contents/Public.ts index db6ece74..92931056 100644 --- a/src/renderer/store/TimelineSpace/Contents/Public.ts +++ b/src/renderer/store/TimelineSpace/Contents/Public.ts @@ -37,10 +37,13 @@ const mutations: MutationTree = { state.heading = value }, [MUTATION_TYPES.APPEND_TIMELINE]: (state, update: Status) => { - if (state.heading) { - state.timeline = [update].concat(state.timeline) - } else { - state.unreadTimeline = [update].concat(state.unreadTimeline) + // 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, messages: Array) => {