aboutsummaryrefslogtreecommitdiff
path: root/test/unit/specs/modules/lists.spec.js
diff options
context:
space:
mode:
authorSean King <seanking2919@protonmail.com>2022-08-22 19:08:58 -0600
committerSean King <seanking2919@protonmail.com>2022-08-22 19:08:58 -0600
commitee58e3868c2d58b889d8a32c1b6dfd3732df7584 (patch)
treeda8f8783734740df18cb5c1082d4756bfcf47489 /test/unit/specs/modules/lists.spec.js
parent325930eecb4943bb50344159646a7c62b4bf10b3 (diff)
parentcb6b96b9ba4e71310e823aecc4bb8c22d370397a (diff)
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma-fe into add/edit-status
Diffstat (limited to 'test/unit/specs/modules/lists.spec.js')
-rw-r--r--test/unit/specs/modules/lists.spec.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/test/unit/specs/modules/lists.spec.js b/test/unit/specs/modules/lists.spec.js
new file mode 100644
index 00000000..ac9af1b6
--- /dev/null
+++ b/test/unit/specs/modules/lists.spec.js
@@ -0,0 +1,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'])
+ })
+ })
+})