Migrates lists module to store
This commit is contained in:
parent
ad7d47f440
commit
8eff081468
13 changed files with 248 additions and 109 deletions
|
|
@ -1,83 +0,0 @@
|
|||
import { cloneDeep } from 'lodash'
|
||||
import { defaultState, mutations, getters } from '../../../../src/modules/lists.js'
|
||||
|
||||
describe('The lists module', () => {
|
||||
describe('mutations', () => {
|
||||
it('updates array of all lists', () => {
|
||||
const state = cloneDeep(defaultState)
|
||||
const list = { id: '1', title: 'testList' }
|
||||
|
||||
mutations.setLists(state, [list])
|
||||
expect(state.allLists).to.have.length(1)
|
||||
expect(state.allLists).to.eql([list])
|
||||
})
|
||||
|
||||
it('adds a new list with a title, updating the title for existing lists', () => {
|
||||
const state = cloneDeep(defaultState)
|
||||
const list = { id: '1', title: 'testList' }
|
||||
const modList = { id: '1', title: 'anotherTestTitle' }
|
||||
|
||||
mutations.setList(state, { listId: list.id, title: list.title })
|
||||
expect(state.allListsObject[list.id]).to.eql({ title: list.title, accountIds: [] })
|
||||
expect(state.allLists).to.have.length(1)
|
||||
expect(state.allLists[0]).to.eql(list)
|
||||
|
||||
mutations.setList(state, { listId: modList.id, title: modList.title })
|
||||
expect(state.allListsObject[modList.id]).to.eql({ title: modList.title, accountIds: [] })
|
||||
expect(state.allLists).to.have.length(1)
|
||||
expect(state.allLists[0]).to.eql(modList)
|
||||
})
|
||||
|
||||
it('adds a new list with an array of IDs, updating the IDs for existing lists', () => {
|
||||
const state = cloneDeep(defaultState)
|
||||
const list = { id: '1', accountIds: ['1', '2', '3'] }
|
||||
const modList = { id: '1', accountIds: ['3', '4', '5'] }
|
||||
|
||||
mutations.setListAccounts(state, { listId: list.id, accountIds: list.accountIds })
|
||||
expect(state.allListsObject[list.id]).to.eql({ accountIds: list.accountIds })
|
||||
|
||||
mutations.setListAccounts(state, { listId: modList.id, accountIds: modList.accountIds })
|
||||
expect(state.allListsObject[modList.id]).to.eql({ accountIds: modList.accountIds })
|
||||
})
|
||||
|
||||
it('deletes a list', () => {
|
||||
const state = {
|
||||
allLists: [{ id: '1', title: 'testList' }],
|
||||
allListsObject: {
|
||||
1: { title: 'testList', accountIds: ['1', '2', '3'] }
|
||||
}
|
||||
}
|
||||
const listId = '1'
|
||||
|
||||
mutations.deleteList(state, { listId })
|
||||
expect(state.allLists).to.have.length(0)
|
||||
expect(state.allListsObject).to.eql({})
|
||||
})
|
||||
})
|
||||
|
||||
describe('getters', () => {
|
||||
it('returns list title', () => {
|
||||
const state = {
|
||||
allLists: [{ id: '1', title: 'testList' }],
|
||||
allListsObject: {
|
||||
1: { title: 'testList', accountIds: ['1', '2', '3'] }
|
||||
}
|
||||
}
|
||||
const id = '1'
|
||||
|
||||
expect(getters.findListTitle(state)(id)).to.eql('testList')
|
||||
})
|
||||
|
||||
it('returns list accounts', () => {
|
||||
const state = {
|
||||
allLists: [{ id: '1', title: 'testList' }],
|
||||
allListsObject: {
|
||||
1: { title: 'testList', accountIds: ['1', '2', '3'] }
|
||||
}
|
||||
}
|
||||
const id = '1'
|
||||
|
||||
expect(getters.findListAccounts(state)(id)).to.eql(['1', '2', '3'])
|
||||
})
|
||||
})
|
||||
})
|
||||
93
test/unit/specs/stores/lists.spec.js
Normal file
93
test/unit/specs/stores/lists.spec.js
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
import { createPinia, setActivePinia } from 'pinia'
|
||||
import { useListsStore } from '../../../../src/stores/lists.js'
|
||||
import { createStore } from 'vuex'
|
||||
import apiModule from '../../../../src/modules/api.js'
|
||||
|
||||
setActivePinia(createPinia())
|
||||
const store = useListsStore()
|
||||
window.vuex = createStore({
|
||||
modules: {
|
||||
api: apiModule
|
||||
}
|
||||
})
|
||||
|
||||
describe('The lists store', () => {
|
||||
describe('actions', () => {
|
||||
it('updates array of all lists', () => {
|
||||
store.$reset()
|
||||
const list = { id: '1', title: 'testList' }
|
||||
|
||||
store.setLists([list])
|
||||
expect(store.allLists).to.have.length(1)
|
||||
expect(store.allLists).to.eql([list])
|
||||
})
|
||||
|
||||
it('adds a new list with a title, updating the title for existing lists', () => {
|
||||
store.$reset()
|
||||
const list = { id: '1', title: 'testList' }
|
||||
const modList = { id: '1', title: 'anotherTestTitle' }
|
||||
|
||||
store.setList({ listId: list.id, title: list.title })
|
||||
expect(store.allListsObject[list.id]).to.eql({ title: list.title, accountIds: [] })
|
||||
expect(store.allLists).to.have.length(1)
|
||||
expect(store.allLists[0]).to.eql(list)
|
||||
|
||||
store.setList({ listId: modList.id, title: modList.title })
|
||||
expect(store.allListsObject[modList.id]).to.eql({ title: modList.title, accountIds: [] })
|
||||
expect(store.allLists).to.have.length(1)
|
||||
expect(store.allLists[0]).to.eql(modList)
|
||||
})
|
||||
|
||||
it('adds a new list with an array of IDs, updating the IDs for existing lists', () => {
|
||||
store.$reset()
|
||||
const list = { id: '1', accountIds: ['1', '2', '3'] }
|
||||
const modList = { id: '1', accountIds: ['3', '4', '5'] }
|
||||
|
||||
store.setListAccounts({ listId: list.id, accountIds: list.accountIds })
|
||||
expect(store.allListsObject[list.id].accountIds).to.eql(list.accountIds)
|
||||
|
||||
store.setListAccounts({ listId: modList.id, accountIds: modList.accountIds })
|
||||
expect(store.allListsObject[modList.id].accountIds).to.eql(modList.accountIds)
|
||||
})
|
||||
|
||||
it('deletes a list', () => {
|
||||
store.$patch({
|
||||
allLists: [{ id: '1', title: 'testList' }],
|
||||
allListsObject: {
|
||||
1: { title: 'testList', accountIds: ['1', '2', '3'] }
|
||||
}
|
||||
})
|
||||
const listId = '1'
|
||||
|
||||
store.deleteList({ listId })
|
||||
expect(store.allLists).to.have.length(0)
|
||||
expect(store.allListsObject).to.eql({})
|
||||
})
|
||||
})
|
||||
|
||||
describe('getters', () => {
|
||||
it('returns list title', () => {
|
||||
store.$patch({
|
||||
allLists: [{ id: '1', title: 'testList' }],
|
||||
allListsObject: {
|
||||
1: { title: 'testList', accountIds: ['1', '2', '3'] }
|
||||
}
|
||||
})
|
||||
const id = '1'
|
||||
|
||||
expect(store.findListTitle(id)).to.eql('testList')
|
||||
})
|
||||
|
||||
it('returns list accounts', () => {
|
||||
store.$patch({
|
||||
allLists: [{ id: '1', title: 'testList' }],
|
||||
allListsObject: {
|
||||
1: { title: 'testList', accountIds: ['1', '2', '3'] }
|
||||
}
|
||||
})
|
||||
const id = '1'
|
||||
|
||||
expect(store.findListAccounts(id)).to.eql(['1', '2', '3'])
|
||||
})
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue