aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/components/timeline/timeline.js28
-rw-r--r--test/unit/specs/components/timeline.spec.js17
2 files changed, 34 insertions, 11 deletions
diff --git a/src/components/timeline/timeline.js b/src/components/timeline/timeline.js
index a5c6418b..aac3869f 100644
--- a/src/components/timeline/timeline.js
+++ b/src/components/timeline/timeline.js
@@ -1,7 +1,20 @@
import Status from '../status/status.vue'
import timelineFetcher from '../../services/timeline_fetcher/timeline_fetcher.service.js'
import Conversation from '../conversation/conversation.vue'
-import { throttle } from 'lodash'
+import { throttle, keyBy } from 'lodash'
+
+export const getExcludedStatusIdsByPinning = (statuses, pinnedStatusIds) => {
+ const ids = []
+ if (pinnedStatusIds && pinnedStatusIds.length > 0) {
+ for (let status of statuses) {
+ if (!pinnedStatusIds.includes(status.id)) {
+ break
+ }
+ ids.push(status.id)
+ }
+ }
+ return ids
+}
const Timeline = {
props: [
@@ -43,16 +56,9 @@ const Timeline = {
},
// id map of statuses which need to be hidden in the main list due to pinning logic
excludedStatusIdsObject () {
- const result = {}
- if (this.pinnedStatusIds && this.pinnedStatusIds.length > 0) {
- for (let status of this.timeline.visibleStatuses) {
- if (!this.pinnedStatusIds.includes(status.id)) {
- break
- }
- result[status.id] = true
- }
- }
- return result
+ const ids = getExcludedStatusIdsByPinning(this.timeline.visibleStatuses, this.pinnedStatusIds)
+ // Convert id array to object
+ return keyBy(ids, id => id)
}
},
components: {
diff --git a/test/unit/specs/components/timeline.spec.js b/test/unit/specs/components/timeline.spec.js
new file mode 100644
index 00000000..b13d3e20
--- /dev/null
+++ b/test/unit/specs/components/timeline.spec.js
@@ -0,0 +1,17 @@
+import { getExcludedStatusIdsByPinning } from 'src/components/timeline/timeline.js'
+import { difference } from 'lodash'
+
+describe('Timeline', () => {
+ describe('getExcludedStatusIdsByPinning', () => {
+ it('should not return unpinned status ids', () => {
+ const statuses = [
+ { id: 1 },
+ { id: 2 },
+ { id: 3 },
+ { id: 4 }
+ ]
+ const pinnedStatusIds = [1, 3]
+ expect(difference(getExcludedStatusIdsByPinning(statuses, pinnedStatusIds), pinnedStatusIds)).to.eql([])
+ })
+ })
+}) \ No newline at end of file