ensure that selected categories are resteted before toggling them to set saved categories

This commit is contained in:
Moriz Wahl 2022-09-08 15:34:29 +02:00
parent 2c4f45ad70
commit 60627ffcf2
2 changed files with 3 additions and 4 deletions

View File

@ -73,8 +73,8 @@ describe('LoginForm', () => {
describe('no categories saved', () => {
it('resets the categories', async () => {
await fillIn(Wrapper())
expect(storeMocks.actions['auth/login']).toBeCalled()
expect(storeMocks.mutations['posts/RESET_CATEGORIES']).toBeCalled()
expect(storeMocks.mutations['posts/TOGGLE_CATEGORY']).not.toBeCalled()
})
})
@ -82,7 +82,7 @@ describe('LoginForm', () => {
it('sets the categories', async () => {
authUserMock.mockReturnValue({ activeCategories: ['cat1', 'cat9', 'cat12'] })
await fillIn(Wrapper())
expect(storeMocks.actions['auth/login']).toBeCalled()
expect(storeMocks.mutations['posts/RESET_CATEGORIES']).toBeCalled()
expect(storeMocks.mutations['posts/TOGGLE_CATEGORY']).toBeCalledTimes(3)
expect(storeMocks.mutations['posts/TOGGLE_CATEGORY']).toBeCalledWith({}, 'cat1')
expect(storeMocks.mutations['posts/TOGGLE_CATEGORY']).toBeCalledWith({}, 'cat9')

View File

@ -99,12 +99,11 @@ export default {
try {
await this.$store.dispatch('auth/login', { email, password })
if (this.currentUser && this.currentUser.activeCategories) {
this.resetCategories()
if (this.currentUser.activeCategories.length > 0) {
this.currentUser.activeCategories.forEach((categoryId) => {
this.toggleCategory(categoryId)
})
} else {
this.resetCategories()
}
}
this.$toast.success(this.$t('login.success'))