From cfb69f4d2e729385bdca1afee11d34a096b0659d Mon Sep 17 00:00:00 2001
From: AkiraFukushima
Date: Wed, 29 May 2019 23:32:16 +0900
Subject: [PATCH] refs #630 Handle delete event for user streaming
---
.../store/TimelineSpace/Contents/Home.spec.ts | 4 +-
.../TimelineSpace/Contents/Mentions.spec.ts | 109 ++++++++++-
.../Contents/Notifications.spec.ts | 185 ++++++++++++++++++
.../TimelineSpace/Contents/Home.vue | 124 ++++++------
src/renderer/store/TimelineSpace.ts | 6 +
.../store/TimelineSpace/Contents/Home.ts | 6 +-
.../store/TimelineSpace/Contents/Mentions.ts | 50 +++--
.../TimelineSpace/Contents/Notifications.ts | 14 ++
8 files changed, 400 insertions(+), 98 deletions(-)
create mode 100644 spec/renderer/unit/store/TimelineSpace/Contents/Notifications.spec.ts
diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Home.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Home.spec.ts
index 8abb77c5..fba72068 100644
--- a/spec/renderer/unit/store/TimelineSpace/Contents/Home.spec.ts
+++ b/spec/renderer/unit/store/TimelineSpace/Contents/Home.spec.ts
@@ -277,7 +277,7 @@ describe('TimelineSpace/Contents/Home', () => {
}
})
it('should be deleted', () => {
- Home.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1)
+ Home.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1.id)
expect(state.timeline).toEqual([status2])
})
})
@@ -325,7 +325,7 @@ describe('TimelineSpace/Contents/Home', () => {
}
})
it('should be deleted', () => {
- Home.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1)
+ Home.mutations![MUTATION_TYPES.DELETE_TOOT](state, status1.id)
expect(state.timeline).toEqual([status2])
})
})
diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Mentions.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Mentions.spec.ts
index 628355b5..d696a22d 100644
--- a/spec/renderer/unit/store/TimelineSpace/Contents/Mentions.spec.ts
+++ b/spec/renderer/unit/store/TimelineSpace/Contents/Mentions.spec.ts
@@ -45,7 +45,7 @@ const account2: Account = {
bot: false
}
-const status: Status = {
+const status1: Status = {
id: '1',
uri: 'http://example.com',
url: 'http://example.com',
@@ -76,19 +76,81 @@ const status: Status = {
pinned: null
}
+const status2: Status = {
+ id: '2',
+ uri: 'http://example.com',
+ url: 'http://example.com',
+ account: account1,
+ in_reply_to_id: null,
+ in_reply_to_account_id: null,
+ reblog: null,
+ content: 'hoge',
+ created_at: '2019-03-26T21: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,
+ application: {
+ name: 'Web'
+ } as Application,
+ language: null,
+ pinned: null
+}
+
+const rebloggedStatus: Status = {
+ id: '3',
+ uri: 'http://example.com',
+ url: 'http://example.com',
+ account: account1,
+ in_reply_to_id: null,
+ in_reply_to_account_id: null,
+ reblog: status2,
+ content: 'hoge',
+ created_at: '2019-03-26T21: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,
+ application: {
+ name: 'Web'
+ } as Application,
+ language: null,
+ pinned: null
+}
+
const notification1: Notification = {
id: '1',
account: account2,
- status: status,
- type: 'favourite',
+ status: status1,
+ type: 'mention',
created_at: '2019-04-01T17:01:32'
}
const notification2: Notification = {
id: '2',
account: account2,
- status: status,
- type: 'reblog',
+ status: rebloggedStatus,
+ type: 'mention',
created_at: '2019-04-01T17:01:32'
}
@@ -184,13 +246,46 @@ describe('TimelineSpace/Contents/Mentions', () => {
}
})
it('should be updated', () => {
- const favourited: Status = Object.assign(status, {
+ const favourited: Status = Object.assign(status1, {
favourited: true
})
Mentions.mutations![MUTATION_TYPES.UPDATE_TOOT](state, favourited)
- expect(state.mentions[0].status!.favourited).toEqual(true)
+ expect(state.mentions[0].status!.favourited).toEqual(null)
expect(state.mentions[1].status!.favourited).toEqual(true)
})
})
+
+ describe('deleteToot', () => {
+ describe('message is not reblogged', () => {
+ beforeEach(() => {
+ state = {
+ lazyLoading: false,
+ heading: true,
+ mentions: [notification2, notification1],
+ unreadMentions: [],
+ filter: ''
+ }
+ })
+ it('should be deleted', () => {
+ Mentions.mutations![MUTATION_TYPES.DELETE_TOOT](state, notification1.status!.id)
+ expect(state.mentions.length).toEqual(1)
+ })
+ })
+ describe('message is reblogged', () => {
+ beforeEach(() => {
+ state = {
+ lazyLoading: false,
+ heading: true,
+ mentions: [notification2, notification1],
+ unreadMentions: [],
+ filter: ''
+ }
+ })
+ it('should be deleted', () => {
+ Mentions.mutations![MUTATION_TYPES.DELETE_TOOT](state, notification2.status!.id)
+ expect(state.mentions.length).toEqual(1)
+ })
+ })
+ })
})
})
diff --git a/spec/renderer/unit/store/TimelineSpace/Contents/Notifications.spec.ts b/spec/renderer/unit/store/TimelineSpace/Contents/Notifications.spec.ts
new file mode 100644
index 00000000..0cc9d5b6
--- /dev/null
+++ b/spec/renderer/unit/store/TimelineSpace/Contents/Notifications.spec.ts
@@ -0,0 +1,185 @@
+import { Account, Notification, Status, Application } from 'megalodon'
+import Notifications, { NotificationsState, MUTATION_TYPES } from '@/store/TimelineSpace/Contents/Notifications'
+
+const account1: Account = {
+ id: '1',
+ username: 'h3poteto',
+ acct: 'h3poteto@pleroma.io',
+ display_name: 'h3poteto',
+ locked: false,
+ created_at: '2019-03-26T21:30:32',
+ followers_count: 10,
+ following_count: 10,
+ statuses_count: 100,
+ note: 'engineer',
+ url: 'https://pleroma.io',
+ avatar: '',
+ avatar_static: '',
+ header: '',
+ header_static: '',
+ emojis: [],
+ moved: null,
+ fields: null,
+ bot: false
+}
+
+const account2: Account = {
+ id: '2',
+ username: 'h3poteto',
+ acct: 'h3poteto@mstdn.io',
+ display_name: 'h3poteto',
+ locked: false,
+ created_at: '2019-03-26T21:30:32',
+ followers_count: 10,
+ following_count: 10,
+ statuses_count: 100,
+ note: 'engineer',
+ url: 'https://mstdn.io',
+ avatar: '',
+ avatar_static: '',
+ header: '',
+ header_static: '',
+ emojis: [],
+ moved: null,
+ fields: null,
+ bot: false
+}
+
+const status1: Status = {
+ id: '1',
+ uri: 'http://example.com',
+ url: 'http://example.com',
+ account: account1,
+ in_reply_to_id: null,
+ in_reply_to_account_id: null,
+ reblog: null,
+ content: 'hoge',
+ created_at: '2019-03-26T21: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,
+ application: {
+ name: 'Web'
+ } as Application,
+ language: null,
+ pinned: null
+}
+
+const status2: Status = {
+ id: '2',
+ uri: 'http://example.com',
+ url: 'http://example.com',
+ account: account1,
+ in_reply_to_id: null,
+ in_reply_to_account_id: null,
+ reblog: null,
+ content: 'hoge',
+ created_at: '2019-03-26T21: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,
+ application: {
+ name: 'Web'
+ } as Application,
+ language: null,
+ pinned: null
+}
+
+const rebloggedStatus: Status = {
+ id: '3',
+ uri: 'http://example.com',
+ url: 'http://example.com',
+ account: account1,
+ in_reply_to_id: null,
+ in_reply_to_account_id: null,
+ reblog: status2,
+ content: 'hoge',
+ created_at: '2019-03-26T21: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,
+ application: {
+ name: 'Web'
+ } as Application,
+ language: null,
+ pinned: null
+}
+
+const notification1: Notification = {
+ id: '1',
+ account: account2,
+ status: status1,
+ type: 'favourite',
+ created_at: '2019-04-01T17:01:32'
+}
+
+const notification2: Notification = {
+ id: '2',
+ account: account2,
+ status: rebloggedStatus,
+ type: 'mention',
+ created_at: '2019-04-01T17:01:32'
+}
+
+describe('TimelineSpace/Contents/Notifications', () => {
+ describe('mutations', () => {
+ let state: NotificationsState
+
+ describe('deleteToot', () => {
+ beforeEach(() => {
+ state = {
+ lazyLoading: false,
+ heading: true,
+ notifications: [notification2, notification1],
+ unreadNotifications: [],
+ filter: ''
+ }
+ })
+ describe('message is not reblogged', () => {
+ it('should be deleted', () => {
+ Notifications.mutations![MUTATION_TYPES.DELETE_TOOT](state, notification1.status!.id)
+ expect(state.notifications.length).toEqual(1)
+ })
+ })
+ describe('message is reblogged', () => {
+ it('should be deleted', () => {
+ Notifications.mutations![MUTATION_TYPES.DELETE_TOOT](state, notification2.status!.id)
+ expect(state.notifications.length).toEqual(1)
+ })
+ })
+ })
+ })
+})
diff --git a/src/renderer/components/TimelineSpace/Contents/Home.vue b/src/renderer/components/TimelineSpace/Contents/Home.vue
index 961055f7..80e4e2a8 100644
--- a/src/renderer/components/TimelineSpace/Contents/Home.vue
+++ b/src/renderer/components/TimelineSpace/Contents/Home.vue
@@ -1,32 +1,29 @@
-
-
{{ unread.length > 0 ? unread.length : '' }}
-
-
-
-
-
+ {{ unread.length > 0 ? unread.length : '' }}
+
+
+
+
-
+
+
+
+
+
+
-
-
-
-
-
-
-