logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

lists.spec.js (2938B)


  1. import { cloneDeep } from 'lodash'
  2. import { defaultState, mutations, getters } from '../../../../src/modules/lists.js'
  3. describe('The lists module', () => {
  4. describe('mutations', () => {
  5. it('updates array of all lists', () => {
  6. const state = cloneDeep(defaultState)
  7. const list = { id: '1', title: 'testList' }
  8. mutations.setLists(state, [list])
  9. expect(state.allLists).to.have.length(1)
  10. expect(state.allLists).to.eql([list])
  11. })
  12. it('adds a new list with a title, updating the title for existing lists', () => {
  13. const state = cloneDeep(defaultState)
  14. const list = { id: '1', title: 'testList' }
  15. const modList = { id: '1', title: 'anotherTestTitle' }
  16. mutations.setList(state, { listId: list.id, title: list.title })
  17. expect(state.allListsObject[list.id]).to.eql({ title: list.title, accountIds: [] })
  18. expect(state.allLists).to.have.length(1)
  19. expect(state.allLists[0]).to.eql(list)
  20. mutations.setList(state, { listId: modList.id, title: modList.title })
  21. expect(state.allListsObject[modList.id]).to.eql({ title: modList.title, accountIds: [] })
  22. expect(state.allLists).to.have.length(1)
  23. expect(state.allLists[0]).to.eql(modList)
  24. })
  25. it('adds a new list with an array of IDs, updating the IDs for existing lists', () => {
  26. const state = cloneDeep(defaultState)
  27. const list = { id: '1', accountIds: ['1', '2', '3'] }
  28. const modList = { id: '1', accountIds: ['3', '4', '5'] }
  29. mutations.setListAccounts(state, { listId: list.id, accountIds: list.accountIds })
  30. expect(state.allListsObject[list.id]).to.eql({ accountIds: list.accountIds })
  31. mutations.setListAccounts(state, { listId: modList.id, accountIds: modList.accountIds })
  32. expect(state.allListsObject[modList.id]).to.eql({ accountIds: modList.accountIds })
  33. })
  34. it('deletes a list', () => {
  35. const state = {
  36. allLists: [{ id: '1', title: 'testList' }],
  37. allListsObject: {
  38. 1: { title: 'testList', accountIds: ['1', '2', '3'] }
  39. }
  40. }
  41. const listId = '1'
  42. mutations.deleteList(state, { listId })
  43. expect(state.allLists).to.have.length(0)
  44. expect(state.allListsObject).to.eql({})
  45. })
  46. })
  47. describe('getters', () => {
  48. it('returns list title', () => {
  49. const state = {
  50. allLists: [{ id: '1', title: 'testList' }],
  51. allListsObject: {
  52. 1: { title: 'testList', accountIds: ['1', '2', '3'] }
  53. }
  54. }
  55. const id = '1'
  56. expect(getters.findListTitle(state)(id)).to.eql('testList')
  57. })
  58. it('returns list accounts', () => {
  59. const state = {
  60. allLists: [{ id: '1', title: 'testList' }],
  61. allListsObject: {
  62. 1: { title: 'testList', accountIds: ['1', '2', '3'] }
  63. }
  64. }
  65. const id = '1'
  66. expect(getters.findListAccounts(state)(id)).to.eql(['1', '2', '3'])
  67. })
  68. })
  69. })