cotisationsMenuBuilder.test.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import { describe, test, it, expect } from 'vitest'
  2. import {RuntimeConfig} from "@nuxt/schema";
  3. import {AnyAbility} from "@casl/ability/dist/types";
  4. import {AccessProfile, organizationState} from "~/types/interfaces";
  5. import CotisationsMenuBuilder from "~/services/layout/menuBuilder/cotisationsMenuBuilder";
  6. import {MenuGroup} from "~/types/layout";
  7. import {MENU_LINK_TYPE} from "~/types/enum/layout";
  8. let runtimeConfig: RuntimeConfig
  9. let ability: AnyAbility
  10. let organizationProfile: organizationState
  11. let accessProfile: AccessProfile
  12. let menuBuilder: CotisationsMenuBuilder
  13. beforeEach(()=> {
  14. runtimeConfig = vi.fn() as any as RuntimeConfig
  15. ability = vi.fn() as any as AnyAbility
  16. organizationProfile = vi.fn() as any as organizationState
  17. accessProfile = vi.fn() as any as AccessProfile
  18. runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
  19. menuBuilder = new CotisationsMenuBuilder(runtimeConfig, ability, organizationProfile, accessProfile)
  20. })
  21. describe('getMenuName', () => {
  22. test('validate name', () => {
  23. expect(menuBuilder.getMenuName()).toEqual("Cotisation")
  24. })
  25. })
  26. describe('build', () => {
  27. test('has all items', () => {
  28. ability.can = vi.fn(() => true)
  29. // Should return a MenuGroup
  30. const result = menuBuilder.build() as MenuGroup
  31. expect(result.label).toEqual('cotisations')
  32. expect(result.icon).toEqual({name: 'fas fa-money-bill'})
  33. // @ts-ignore
  34. expect(result.children.length).toEqual(17)
  35. })
  36. test('has no items', () => {
  37. ability.can = vi.fn(() => false)
  38. expect(menuBuilder.build()).toEqual(null)
  39. })
  40. test('has only rights for menu rate_cotisation', () => {
  41. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'rate_cotisation_page')
  42. expect(menuBuilder.build()).toEqual(
  43. {label: 'rate_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/rate', type: MENU_LINK_TYPE.V1, active: false}
  44. )
  45. })
  46. test('has only rights for menu parameters_cotisation', () => {
  47. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'parameters_cotisation_page')
  48. expect(menuBuilder.build()).toEqual(
  49. {label: 'parameters_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/parameter', type: MENU_LINK_TYPE.V1, active: false}
  50. )
  51. })
  52. test('has only rights for menu send_cotisation', () => {
  53. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'send_cotisation_page')
  54. expect(menuBuilder.build()).toEqual(
  55. {label: 'send_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/send', type: MENU_LINK_TYPE.V1, active: false}
  56. )
  57. })
  58. test('has only rights for menu state_cotisation', () => {
  59. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'state_cotisation_page')
  60. expect(menuBuilder.build()).toEqual(
  61. {label: 'state_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/state', type: MENU_LINK_TYPE.V1, active: false}
  62. )
  63. })
  64. test('has only rights for menu pay_cotisation', () => {
  65. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'pay_cotisation_page')
  66. expect(menuBuilder.build()).toEqual(
  67. {label: 'pay_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/pay', type: MENU_LINK_TYPE.V1, active: false}
  68. )
  69. })
  70. test('has only rights for menu check_cotisation', () => {
  71. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'check_cotisation_page')
  72. expect(menuBuilder.build()).toEqual(
  73. {label: 'check_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/check', type: MENU_LINK_TYPE.V1, active: false}
  74. )
  75. })
  76. test('has only rights for menu ledger_cotisation', () => {
  77. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'ledger_cotisation_page')
  78. expect(menuBuilder.build()).toEqual(
  79. {label: 'ledger_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/ledger', type: MENU_LINK_TYPE.V1, active: false}
  80. )
  81. })
  82. test('has only rights for menu magazine_cotisation', () => {
  83. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'magazine_cotisation_page')
  84. expect(menuBuilder.build()).toEqual(
  85. {label: 'magazine_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/magazine', type: MENU_LINK_TYPE.V1, active: false}
  86. )
  87. })
  88. test('has only rights for menu ventilated_cotisation', () => {
  89. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'ventilated_cotisation_page')
  90. expect(menuBuilder.build()).toEqual(
  91. {label: 'ventilated_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/ventilated', type: MENU_LINK_TYPE.V1, active: false}
  92. )
  93. })
  94. test('has only rights for menu pay_erase_cotisation', () => {
  95. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'pay_erase_cotisation_page')
  96. expect(menuBuilder.build()).toEqual(
  97. {label: 'pay_erase_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/payerase', type: MENU_LINK_TYPE.V1, active: false}
  98. )
  99. })
  100. test('has only rights for menu resume_cotisation', () => {
  101. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'resume_cotisation_page')
  102. expect(menuBuilder.build()).toEqual(
  103. {label: 'resume_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/resume', type: MENU_LINK_TYPE.V1, active: false}
  104. )
  105. })
  106. test('has only rights for menu history_cotisation', () => {
  107. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'history_cotisation_page')
  108. expect(menuBuilder.build()).toEqual(
  109. {label: 'history_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/history', type: MENU_LINK_TYPE.V1, active: false}
  110. )
  111. })
  112. test('has only rights for menu call_cotisation', () => {
  113. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'call_cotisation_page')
  114. expect(menuBuilder.build()).toEqual(
  115. {label: 'call_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/call', type: MENU_LINK_TYPE.V1, active: false}
  116. )
  117. })
  118. test('has only rights for menu history_structure_cotisation', () => {
  119. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'history_structure_cotisation_page')
  120. expect(menuBuilder.build()).toEqual(
  121. {label: 'history_structure_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/historystructure', type: MENU_LINK_TYPE.V1, active: false}
  122. )
  123. })
  124. test('has only rights for menu insurance_cotisation', () => {
  125. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'insurance_cotisation_page')
  126. expect(menuBuilder.build()).toEqual(
  127. {label: 'insurance_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/insurance', type: MENU_LINK_TYPE.V1, active: false}
  128. )
  129. })
  130. test('has only rights for menu resume_all_cotisation', () => {
  131. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'resume_all_cotisation_page')
  132. expect(menuBuilder.build()).toEqual(
  133. {label: 'resume_all_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/resumeall', type: MENU_LINK_TYPE.V1, active: false}
  134. )
  135. })
  136. test('has only rights for menu resume_pay_cotisation', () => {
  137. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'resume_pay_cotisation_page')
  138. expect(menuBuilder.build()).toEqual(
  139. {label: 'resume_pay_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/cotisation/resumepay', type: MENU_LINK_TYPE.V1, active: false}
  140. )
  141. })
  142. })