aboutsummaryrefslogtreecommitdiff
path: root/test/unit/specs/modules/lists.spec.js
blob: ac9af1b6b4129732258eaf8dd9df9943c696e8fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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, list)
      expect(state.allListsObject[list.id]).to.eql({ title: list.title })
      expect(state.allLists).to.have.length(1)
      expect(state.allLists[0]).to.eql(list)

      mutations.setList(state, modList)
      expect(state.allListsObject[modList.id]).to.eql({ title: modList.title })
      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, list)
      expect(state.allListsObject[list.id]).to.eql({ accountIds: list.accountIds })

      mutations.setListAccounts(state, modList)
      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 id = '1'

      mutations.deleteList(state, { id })
      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'])
    })
  })
})