mirror of
https://github.com/IT4Change/gradido.git
synced 2026-01-20 20:01:31 +00:00
refactor: Update Store Tests
This commit is contained in:
parent
0059cffa19
commit
d9f444b0bb
@ -1,6 +1,6 @@
|
|||||||
import { mutations, actions } from './store'
|
import { mutations, actions } from './store'
|
||||||
|
|
||||||
const { language, email, sessionId } = mutations
|
const { language, email, sessionId, username, firstName, lastName, description } = mutations
|
||||||
const { login, logout } = actions
|
const { login, logout } = actions
|
||||||
|
|
||||||
describe('Vuex store', () => {
|
describe('Vuex store', () => {
|
||||||
@ -28,51 +28,102 @@ describe('Vuex store', () => {
|
|||||||
expect(state.sessionId).toEqual('1234')
|
expect(state.sessionId).toEqual('1234')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('username', () => {
|
||||||
|
it('sets the state of username', () => {
|
||||||
|
const state = { username: null }
|
||||||
|
username(state, 'user')
|
||||||
|
expect(state.username).toEqual('user')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('firstName', () => {
|
||||||
|
it('sets the state of firstName', () => {
|
||||||
|
const state = { firstName: null }
|
||||||
|
firstName(state, 'Peter')
|
||||||
|
expect(state.firstName).toEqual('Peter')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('lastName', () => {
|
||||||
|
it('sets the state of lastName', () => {
|
||||||
|
const state = { lastName: null }
|
||||||
|
lastName(state, 'Lustig')
|
||||||
|
expect(state.lastName).toEqual('Lustig')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('description', () => {
|
||||||
|
it('sets the state of description', () => {
|
||||||
|
const state = { description: null }
|
||||||
|
description(state, 'Nickelbrille')
|
||||||
|
expect(state.description).toEqual('Nickelbrille')
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('actions', () => {
|
describe('actions', () => {
|
||||||
describe('login', () => {
|
describe('login', () => {
|
||||||
const commit = jest.fn()
|
const commit = jest.fn()
|
||||||
const state = {}
|
const state = {}
|
||||||
|
const commitedData = {
|
||||||
|
sessionId: 1234,
|
||||||
|
user: {
|
||||||
|
email: 'someone@there.is',
|
||||||
|
language: 'en',
|
||||||
|
username: 'user',
|
||||||
|
first_name: 'Peter',
|
||||||
|
last_name: 'Lustig',
|
||||||
|
description: 'Nickelbrille',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
it('calls three commits', () => {
|
it('calls seven commits', () => {
|
||||||
login(
|
login({ commit, state }, commitedData)
|
||||||
{ commit, state },
|
|
||||||
{ sessionId: 1234, user: { email: 'someone@there.is', language: 'en' } },
|
|
||||||
)
|
|
||||||
expect(commit).toHaveBeenCalledTimes(7)
|
expect(commit).toHaveBeenCalledTimes(7)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('commits sessionId', () => {
|
it('commits sessionId', () => {
|
||||||
login(
|
login({ commit, state }, commitedData)
|
||||||
{ commit, state },
|
|
||||||
{ sessionId: 1234, user: { email: 'someone@there.is', language: 'en' } },
|
|
||||||
)
|
|
||||||
expect(commit).toHaveBeenNthCalledWith(1, 'sessionId', 1234)
|
expect(commit).toHaveBeenNthCalledWith(1, 'sessionId', 1234)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('commits email', () => {
|
it('commits email', () => {
|
||||||
login(
|
login({ commit, state }, commitedData)
|
||||||
{ commit, state },
|
|
||||||
{ sessionId: 1234, user: { email: 'someone@there.is', language: 'en' } },
|
|
||||||
)
|
|
||||||
expect(commit).toHaveBeenNthCalledWith(2, 'email', 'someone@there.is')
|
expect(commit).toHaveBeenNthCalledWith(2, 'email', 'someone@there.is')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('commits language', () => {
|
it('commits language', () => {
|
||||||
login(
|
login({ commit, state }, commitedData)
|
||||||
{ commit, state },
|
|
||||||
{ sessionId: 1234, user: { email: 'someone@there.is', language: 'en' } },
|
|
||||||
)
|
|
||||||
expect(commit).toHaveBeenNthCalledWith(3, 'language', 'en')
|
expect(commit).toHaveBeenNthCalledWith(3, 'language', 'en')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('commits username', () => {
|
||||||
|
login({ commit, state }, commitedData)
|
||||||
|
expect(commit).toHaveBeenNthCalledWith(4, 'username', 'user')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('commits firstName', () => {
|
||||||
|
login({ commit, state }, commitedData)
|
||||||
|
expect(commit).toHaveBeenNthCalledWith(5, 'firstName', 'Peter')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('commits lastName', () => {
|
||||||
|
login({ commit, state }, commitedData)
|
||||||
|
expect(commit).toHaveBeenNthCalledWith(6, 'lastName', 'Lustig')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('commits description', () => {
|
||||||
|
login({ commit, state }, commitedData)
|
||||||
|
expect(commit).toHaveBeenNthCalledWith(7, 'description', 'Nickelbrille')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('logout', () => {
|
describe('logout', () => {
|
||||||
const commit = jest.fn()
|
const commit = jest.fn()
|
||||||
const state = {}
|
const state = {}
|
||||||
|
|
||||||
it('calls two commits', () => {
|
it('calls six commits', () => {
|
||||||
logout({ commit, state })
|
logout({ commit, state })
|
||||||
expect(commit).toHaveBeenCalledTimes(6)
|
expect(commit).toHaveBeenCalledTimes(6)
|
||||||
})
|
})
|
||||||
@ -87,11 +138,36 @@ describe('Vuex store', () => {
|
|||||||
expect(commit).toHaveBeenNthCalledWith(2, 'email', null)
|
expect(commit).toHaveBeenNthCalledWith(2, 'email', null)
|
||||||
})
|
})
|
||||||
|
|
||||||
// how can I get this working?
|
it('commits username', () => {
|
||||||
it.skip('calls sessionStorage.clear()', () => {
|
|
||||||
logout({ commit, state })
|
logout({ commit, state })
|
||||||
const spy = jest.spyOn(sessionStorage, 'clear')
|
expect(commit).toHaveBeenNthCalledWith(3, 'username', '')
|
||||||
expect(spy).toHaveBeenCalledTimes(1)
|
})
|
||||||
|
|
||||||
|
it('commits firstName', () => {
|
||||||
|
logout({ commit, state })
|
||||||
|
expect(commit).toHaveBeenNthCalledWith(4, 'firstName', '')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('commits lastName', () => {
|
||||||
|
logout({ commit, state })
|
||||||
|
expect(commit).toHaveBeenNthCalledWith(5, 'lastName', '')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('commits description', () => {
|
||||||
|
logout({ commit, state })
|
||||||
|
expect(commit).toHaveBeenNthCalledWith(6, 'description', '')
|
||||||
|
})
|
||||||
|
|
||||||
|
// how to get this working?
|
||||||
|
it.skip('calls sessionStorage.clear()', () => {
|
||||||
|
const clearStorageMock = jest.fn()
|
||||||
|
global.sessionStorage = jest.fn(() => {
|
||||||
|
return {
|
||||||
|
clear: clearStorageMock,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
logout({ commit, state })
|
||||||
|
expect(clearStorageMock).toBeCalled()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user