From 8b16e772c1a25558f266891c7ac1d9a70d6f0659 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 16 Sep 2021 11:14:22 +0200 Subject: [PATCH] newsletterState in store --- frontend/src/store/store.js | 6 ++++++ frontend/src/store/store.test.js | 36 +++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/frontend/src/store/store.js b/frontend/src/store/store.js index 00f8369d2..fcd877a59 100644 --- a/frontend/src/store/store.js +++ b/frontend/src/store/store.js @@ -26,6 +26,9 @@ export const mutations = { token: (state, token) => { state.token = token }, + newsletterState: (state, newsletterState) => { + state.newsletterState = newsletterState + }, } export const actions = { @@ -36,6 +39,7 @@ export const actions = { commit('firstName', data.firstName) commit('lastName', data.lastName) commit('description', data.description) + commit('newsletterState', data.klickTipp.newsletterState) }, logout: ({ commit, state }) => { commit('token', null) @@ -44,6 +48,7 @@ export const actions = { commit('firstName', '') commit('lastName', '') commit('description', '') + commit('newsletterState', null) localStorage.clear() }, } @@ -62,6 +67,7 @@ export const store = new Vuex.Store({ username: '', description: '', token: null, + newsletterState: null, }, getters: {}, // Syncronous mutation of the state diff --git a/frontend/src/store/store.test.js b/frontend/src/store/store.test.js index c067a6e49..7ae3344d9 100644 --- a/frontend/src/store/store.test.js +++ b/frontend/src/store/store.test.js @@ -1,6 +1,15 @@ import { mutations, actions } from './store' -const { language, email, token, username, firstName, lastName, description } = mutations +const { + language, + email, + token, + username, + firstName, + lastName, + description, + newsletterState, +} = mutations const { login, logout } = actions describe('Vuex store', () => { @@ -60,6 +69,14 @@ describe('Vuex store', () => { expect(state.description).toEqual('Nickelbrille') }) }) + + describe('newsletterState', () => { + it('sets the state of newsletterState', () => { + const state = { newsletterState: null } + newsletterState(state, true) + expect(state.newsletterState).toEqual(true) + }) + }) }) describe('actions', () => { @@ -73,11 +90,14 @@ describe('Vuex store', () => { firstName: 'Peter', lastName: 'Lustig', description: 'Nickelbrille', + klickTipp: { + newsletterState: true, + }, } it('calls seven commits', () => { login({ commit, state }, commitedData) - expect(commit).toHaveBeenCalledTimes(6) + expect(commit).toHaveBeenCalledTimes(7) }) it('commits email', () => { @@ -109,6 +129,11 @@ describe('Vuex store', () => { login({ commit, state }, commitedData) expect(commit).toHaveBeenNthCalledWith(6, 'description', 'Nickelbrille') }) + + it('commits newsletterState', () => { + login({ commit, state }, commitedData) + expect(commit).toHaveBeenNthCalledWith(7, 'newsletterState', true) + }) }) describe('logout', () => { @@ -117,7 +142,7 @@ describe('Vuex store', () => { it('calls six commits', () => { logout({ commit, state }) - expect(commit).toHaveBeenCalledTimes(6) + expect(commit).toHaveBeenCalledTimes(7) }) it('commits token', () => { @@ -150,6 +175,11 @@ describe('Vuex store', () => { expect(commit).toHaveBeenNthCalledWith(6, 'description', '') }) + it('commits newsletterState', () => { + logout({ commit, state }) + expect(commit).toHaveBeenNthCalledWith(7, 'newsletterState', null) + }) + // how to get this working? it.skip('calls localStorage.clear()', () => { const clearStorageMock = jest.fn()