From ca78623b348a3ef83c02e451b0b553b431a06551 Mon Sep 17 00:00:00 2001 From: shpuld Date: Mon, 28 Jan 2019 20:15:00 +0200 Subject: [PATCH] fix user tl clearing and give it a test --- src/modules/statuses.js | 6 +++--- test/unit/specs/modules/statuses.spec.js | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 3d6ea2f7d4..04ec4dbc5f 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -2,7 +2,7 @@ import { remove, slice, each, find, maxBy, minBy, merge, last, isArray } from 'l import apiService from '../services/api/api.service.js' // import parse from '../services/status_parser/status_parser.js' -const emptyTl = () => ({ +const emptyTl = (userId = 0) => ({ statuses: [], statusesObject: {}, faves: [], @@ -14,7 +14,7 @@ const emptyTl = () => ({ loading: false, followers: [], friends: [], - userId: 0, + userId, flushMarker: 0 }) @@ -319,7 +319,7 @@ export const mutations = { each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status }) }, clearTimeline (state, { timeline }) { - state.timelines[timeline] = emptyTl() + state.timelines[timeline] = emptyTl(state.timelines[timeline].userId) }, setFavorited (state, { status, value }) { const newStatus = state.allStatusesObject[status.id] diff --git a/test/unit/specs/modules/statuses.spec.js b/test/unit/specs/modules/statuses.spec.js index 33628b9b28..01d2ce061f 100644 --- a/test/unit/specs/modules/statuses.spec.js +++ b/test/unit/specs/modules/statuses.spec.js @@ -240,6 +240,15 @@ describe('The Statuses module', () => { expect(state.timelines.public.visibleStatuses[0].favorited).to.eql(true) }) + it('keeps userId when clearing user timeline', () => { + const state = cloneDeep(defaultState) + state.timelines.user.userId = 123 + + mutations.clearTimeline(state, { timeline: 'user' }) + + expect(state.timelines.user.userId).to.eql(123) + }) + describe('notifications', () => { it('removes a notification when the notice gets removed', () => { const user = { id: '1' }