forked from AkkomaGang/akkoma-fe
add unit test for elimination logic
This commit is contained in:
parent
53c9517a4a
commit
65ef039316
2 changed files with 34 additions and 11 deletions
|
@ -1,7 +1,20 @@
|
||||||
import Status from '../status/status.vue'
|
import Status from '../status/status.vue'
|
||||||
import timelineFetcher from '../../services/timeline_fetcher/timeline_fetcher.service.js'
|
import timelineFetcher from '../../services/timeline_fetcher/timeline_fetcher.service.js'
|
||||||
import Conversation from '../conversation/conversation.vue'
|
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 = {
|
const Timeline = {
|
||||||
props: [
|
props: [
|
||||||
|
@ -43,16 +56,9 @@ const Timeline = {
|
||||||
},
|
},
|
||||||
// id map of statuses which need to be hidden in the main list due to pinning logic
|
// id map of statuses which need to be hidden in the main list due to pinning logic
|
||||||
excludedStatusIdsObject () {
|
excludedStatusIdsObject () {
|
||||||
const result = {}
|
const ids = getExcludedStatusIdsByPinning(this.timeline.visibleStatuses, this.pinnedStatusIds)
|
||||||
if (this.pinnedStatusIds && this.pinnedStatusIds.length > 0) {
|
// Convert id array to object
|
||||||
for (let status of this.timeline.visibleStatuses) {
|
return keyBy(ids, id => id)
|
||||||
if (!this.pinnedStatusIds.includes(status.id)) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
result[status.id] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
|
17
test/unit/specs/components/timeline.spec.js
Normal file
17
test/unit/specs/components/timeline.spec.js
Normal file
|
@ -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([])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in a new issue