2022-08-06 07:26:43 -07:00
|
|
|
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' }
|
|
|
|
|
2022-08-16 10:00:29 -07:00
|
|
|
mutations.setList(state, { listId: list.id, title: list.title })
|
|
|
|
expect(state.allListsObject[list.id]).to.eql({ title: list.title, accountIds: [] })
|
2022-08-06 07:26:43 -07:00
|
|
|
expect(state.allLists).to.have.length(1)
|
|
|
|
expect(state.allLists[0]).to.eql(list)
|
|
|
|
|
2022-08-16 10:00:29 -07:00
|
|
|
mutations.setList(state, { listId: modList.id, title: modList.title })
|
|
|
|
expect(state.allListsObject[modList.id]).to.eql({ title: modList.title, accountIds: [] })
|
2022-08-06 07:26:43 -07:00
|
|
|
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'] }
|
|
|
|
|
2022-08-16 10:00:29 -07:00
|
|
|
mutations.setListAccounts(state, { listId: list.id, accountIds: list.accountIds })
|
2022-08-06 07:26:43 -07:00
|
|
|
expect(state.allListsObject[list.id]).to.eql({ accountIds: list.accountIds })
|
|
|
|
|
2022-08-16 10:00:29 -07:00
|
|
|
mutations.setListAccounts(state, { listId: modList.id, accountIds: modList.accountIds })
|
2022-08-06 07:26:43 -07:00
|
|
|
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'] }
|
|
|
|
}
|
|
|
|
}
|
2022-08-16 10:00:29 -07:00
|
|
|
const listId = '1'
|
2022-08-06 07:26:43 -07:00
|
|
|
|
2022-08-16 10:00:29 -07:00
|
|
|
mutations.deleteList(state, { listId })
|
2022-08-06 07:26:43 -07:00
|
|
|
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'])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|