cotisationsMenuBuilder.test.ts 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. import { describe, test, it, expect } from 'vitest'
  2. import type { RuntimeConfig } from '@nuxt/schema'
  3. import type { AnyAbility } from '@casl/ability/dist/types'
  4. import type { AccessProfile, organizationState } from '~/types/interfaces'
  5. import CotisationsMenuBuilder from '~/services/layout/menuBuilder/cotisationsMenuBuilder'
  6. import type { 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(
  20. runtimeConfig,
  21. ability,
  22. organizationProfile,
  23. accessProfile,
  24. )
  25. })
  26. describe('getMenuName', () => {
  27. test('validate name', () => {
  28. expect(menuBuilder.getMenuName()).toEqual('Cotisation')
  29. })
  30. })
  31. describe('build', () => {
  32. test('has all items', () => {
  33. ability.can = vi.fn(() => true)
  34. // Should return a MenuGroup
  35. const result = menuBuilder.build() as MenuGroup
  36. expect(result.label).toEqual('cotisations')
  37. expect(result.icon).toEqual({ name: 'fas fa-money-bill' })
  38. // @ts-ignore
  39. expect(result.children.length).toEqual(17)
  40. })
  41. test('has no items', () => {
  42. ability.can = vi.fn(() => false)
  43. expect(menuBuilder.build()).toEqual(null)
  44. })
  45. test('has only rights for menu rate_cotisation', () => {
  46. ability.can = vi.fn(
  47. (action: string, subject: string) =>
  48. action === 'display' && subject === 'rate_cotisation_page',
  49. )
  50. expect(menuBuilder.build()).toEqual({
  51. label: 'rate_cotisation',
  52. icon: { name: 'fas fa-euro-sign' },
  53. to: 'https://mydomain.com/#/cotisation/rate',
  54. type: MENU_LINK_TYPE.V1,
  55. active: false,
  56. })
  57. })
  58. test('has only rights for menu parameters_cotisation', () => {
  59. ability.can = vi.fn(
  60. (action: string, subject: string) =>
  61. action === 'display' && subject === 'parameters_cotisation_page',
  62. )
  63. expect(menuBuilder.build()).toEqual({
  64. label: 'parameters_cotisation',
  65. icon: { name: 'fas fa-euro-sign' },
  66. to: 'https://mydomain.com/#/cotisation/parameter',
  67. type: MENU_LINK_TYPE.V1,
  68. active: false,
  69. })
  70. })
  71. test('has only rights for menu send_cotisation', () => {
  72. ability.can = vi.fn(
  73. (action: string, subject: string) =>
  74. action === 'display' && subject === 'send_cotisation_page',
  75. )
  76. expect(menuBuilder.build()).toEqual({
  77. label: 'send_cotisation',
  78. icon: { name: 'fas fa-euro-sign' },
  79. to: 'https://mydomain.com/#/cotisation/send',
  80. type: MENU_LINK_TYPE.V1,
  81. active: false,
  82. })
  83. })
  84. test('has only rights for menu state_cotisation', () => {
  85. ability.can = vi.fn(
  86. (action: string, subject: string) =>
  87. action === 'display' && subject === 'state_cotisation_page',
  88. )
  89. expect(menuBuilder.build()).toEqual({
  90. label: 'state_cotisation',
  91. icon: { name: 'fas fa-euro-sign' },
  92. to: 'https://mydomain.com/#/cotisation/state',
  93. type: MENU_LINK_TYPE.V1,
  94. active: false,
  95. })
  96. })
  97. test('has only rights for menu pay_cotisation', () => {
  98. ability.can = vi.fn(
  99. (action: string, subject: string) =>
  100. action === 'display' && subject === 'pay_cotisation_page',
  101. )
  102. expect(menuBuilder.build()).toEqual({
  103. label: 'pay_cotisation',
  104. icon: { name: 'fas fa-euro-sign' },
  105. to: 'https://mydomain.com/#/cotisation/pay',
  106. type: MENU_LINK_TYPE.V1,
  107. active: false,
  108. })
  109. })
  110. test('has only rights for menu check_cotisation', () => {
  111. ability.can = vi.fn(
  112. (action: string, subject: string) =>
  113. action === 'display' && subject === 'check_cotisation_page',
  114. )
  115. expect(menuBuilder.build()).toEqual({
  116. label: 'check_cotisation',
  117. icon: { name: 'fas fa-euro-sign' },
  118. to: 'https://mydomain.com/#/cotisation/check',
  119. type: MENU_LINK_TYPE.V1,
  120. active: false,
  121. })
  122. })
  123. test('has only rights for menu ledger_cotisation', () => {
  124. ability.can = vi.fn(
  125. (action: string, subject: string) =>
  126. action === 'display' && subject === 'ledger_cotisation_page',
  127. )
  128. expect(menuBuilder.build()).toEqual({
  129. label: 'ledger_cotisation',
  130. icon: { name: 'fas fa-euro-sign' },
  131. to: 'https://mydomain.com/#/cotisation/ledger',
  132. type: MENU_LINK_TYPE.V1,
  133. active: false,
  134. })
  135. })
  136. test('has only rights for menu magazine_cotisation', () => {
  137. ability.can = vi.fn(
  138. (action: string, subject: string) =>
  139. action === 'display' && subject === 'magazine_cotisation_page',
  140. )
  141. expect(menuBuilder.build()).toEqual({
  142. label: 'magazine_cotisation',
  143. icon: { name: 'fas fa-euro-sign' },
  144. to: 'https://mydomain.com/#/cotisation/magazine',
  145. type: MENU_LINK_TYPE.V1,
  146. active: false,
  147. })
  148. })
  149. test('has only rights for menu ventilated_cotisation', () => {
  150. ability.can = vi.fn(
  151. (action: string, subject: string) =>
  152. action === 'display' && subject === 'ventilated_cotisation_page',
  153. )
  154. expect(menuBuilder.build()).toEqual({
  155. label: 'ventilated_cotisation',
  156. icon: { name: 'fas fa-euro-sign' },
  157. to: 'https://mydomain.com/#/cotisation/ventilated',
  158. type: MENU_LINK_TYPE.V1,
  159. active: false,
  160. })
  161. })
  162. test('has only rights for menu pay_erase_cotisation', () => {
  163. ability.can = vi.fn(
  164. (action: string, subject: string) =>
  165. action === 'display' && subject === 'pay_erase_cotisation_page',
  166. )
  167. expect(menuBuilder.build()).toEqual({
  168. label: 'pay_erase_cotisation',
  169. icon: { name: 'fas fa-euro-sign' },
  170. to: 'https://mydomain.com/#/cotisation/payerase',
  171. type: MENU_LINK_TYPE.V1,
  172. active: false,
  173. })
  174. })
  175. test('has only rights for menu resume_cotisation', () => {
  176. ability.can = vi.fn(
  177. (action: string, subject: string) =>
  178. action === 'display' && subject === 'resume_cotisation_page',
  179. )
  180. expect(menuBuilder.build()).toEqual({
  181. label: 'resume_cotisation',
  182. icon: { name: 'fas fa-euro-sign' },
  183. to: 'https://mydomain.com/#/cotisation/resume',
  184. type: MENU_LINK_TYPE.V1,
  185. active: false,
  186. })
  187. })
  188. test('has only rights for menu history_cotisation', () => {
  189. ability.can = vi.fn(
  190. (action: string, subject: string) =>
  191. action === 'display' && subject === 'history_cotisation_page',
  192. )
  193. expect(menuBuilder.build()).toEqual({
  194. label: 'history_cotisation',
  195. icon: { name: 'fas fa-euro-sign' },
  196. to: 'https://mydomain.com/#/cotisation/history',
  197. type: MENU_LINK_TYPE.V1,
  198. active: false,
  199. })
  200. })
  201. test('has only rights for menu call_cotisation', () => {
  202. ability.can = vi.fn(
  203. (action: string, subject: string) =>
  204. action === 'display' && subject === 'call_cotisation_page',
  205. )
  206. expect(menuBuilder.build()).toEqual({
  207. label: 'call_cotisation',
  208. icon: { name: 'fas fa-euro-sign' },
  209. to: 'https://mydomain.com/#/cotisation/call',
  210. type: MENU_LINK_TYPE.V1,
  211. active: false,
  212. })
  213. })
  214. test('has only rights for menu history_structure_cotisation', () => {
  215. ability.can = vi.fn(
  216. (action: string, subject: string) =>
  217. action === 'display' && subject === 'history_structure_cotisation_page',
  218. )
  219. expect(menuBuilder.build()).toEqual({
  220. label: 'history_structure_cotisation',
  221. icon: { name: 'fas fa-euro-sign' },
  222. to: 'https://mydomain.com/#/cotisation/historystructure',
  223. type: MENU_LINK_TYPE.V1,
  224. active: false,
  225. })
  226. })
  227. test('has only rights for menu insurance_cotisation', () => {
  228. ability.can = vi.fn(
  229. (action: string, subject: string) =>
  230. action === 'display' && subject === 'insurance_cotisation_page',
  231. )
  232. expect(menuBuilder.build()).toEqual({
  233. label: 'insurance_cotisation',
  234. icon: { name: 'fas fa-euro-sign' },
  235. to: 'https://mydomain.com/#/cotisation/insurance',
  236. type: MENU_LINK_TYPE.V1,
  237. active: false,
  238. })
  239. })
  240. test('has only rights for menu resume_all_cotisation', () => {
  241. ability.can = vi.fn(
  242. (action: string, subject: string) =>
  243. action === 'display' && subject === 'resume_all_cotisation_page',
  244. )
  245. expect(menuBuilder.build()).toEqual({
  246. label: 'resume_all_cotisation',
  247. icon: { name: 'fas fa-euro-sign' },
  248. to: 'https://mydomain.com/#/cotisation/resumeall',
  249. type: MENU_LINK_TYPE.V1,
  250. active: false,
  251. })
  252. })
  253. test('has only rights for menu resume_pay_cotisation', () => {
  254. ability.can = vi.fn(
  255. (action: string, subject: string) =>
  256. action === 'display' && subject === 'resume_pay_cotisation_page',
  257. )
  258. expect(menuBuilder.build()).toEqual({
  259. label: 'resume_pay_cotisation',
  260. icon: { name: 'fas fa-euro-sign' },
  261. to: 'https://mydomain.com/#/cotisation/resumepay',
  262. type: MENU_LINK_TYPE.V1,
  263. active: false,
  264. })
  265. })
  266. })