cotisationsMenuBuilder.test.ts 9.2 KB

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