| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- import { describe, test, expect, vi, beforeEach } from 'vitest'
- import type { RuntimeConfig } from '@nuxt/schema'
- import type { AnyAbility } from '@casl/ability/dist/types'
- import type { Router } from 'vue-router'
- import type { AccessProfile, organizationState } from '~/types/interfaces'
- import CotisationsMenuBuilder from '~/services/layout/menuBuilder/cotisationsMenuBuilder'
- import type { MenuGroup } from '~/types/layout'
- import { MENU_LINK_TYPE } from '~/types/enum/layout'
- let runtimeConfig: RuntimeConfig
- let ability: AnyAbility
- let organizationProfile: organizationState
- let accessProfile: AccessProfile
- let menuBuilder: CotisationsMenuBuilder
- let router: Router
- beforeEach(() => {
- runtimeConfig = vi.fn() as any as RuntimeConfig
- ability = vi.fn() as any as AnyAbility
- organizationProfile = vi.fn() as any as organizationState
- accessProfile = vi.fn() as any as AccessProfile
- // @ts-ignore
- router = vi.fn() as Router
- runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
- menuBuilder = new CotisationsMenuBuilder(
- runtimeConfig,
- ability,
- organizationProfile,
- accessProfile,
- router,
- )
- })
- describe('getMenuName', () => {
- test('validate name', () => {
- expect(menuBuilder.getMenuName()).toEqual('Cotisation')
- })
- })
- describe('build', () => {
- test('has all items', () => {
- ability.can = vi.fn(() => true)
- // Should return a MenuGroup
- const result = menuBuilder.build() as MenuGroup
- expect(result.label).toEqual('cotisations')
- expect(result.icon).toEqual({ name: 'fas fa-money-bill' })
- // @ts-ignore
- expect(result.children.length).toEqual(17)
- })
- test('has no items', () => {
- ability.can = vi.fn(() => false)
- expect(menuBuilder.build()).toEqual(null)
- })
- test('has only rights for menu rate_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'rate_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'rate_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/rate',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu parameters_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'parameters_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'parameters_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/parameter',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu send_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'send_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'send_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/send',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu state_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'state_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'state_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/state',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu pay_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'pay_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'pay_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/pay',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu check_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'check_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'check_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/check',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu ledger_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'ledger_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'ledger_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/ledger',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu magazine_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'magazine_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'magazine_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/magazine',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu ventilated_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'ventilated_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'ventilated_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/ventilated',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu pay_erase_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'pay_erase_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'pay_erase_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/payerase',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu resume_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'resume_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'resume_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/resume',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu history_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'history_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'history_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/history',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu call_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'call_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'call_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/call',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu history_structure_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'history_structure_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'history_structure_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/historystructure',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu insurance_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'insurance_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'insurance_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/insurance',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu resume_all_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'resume_all_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'resume_all_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/resumeall',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- test('has only rights for menu resume_pay_cotisation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'resume_pay_cotisation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'resume_pay_cotisation',
- icon: { name: 'fas fa-euro-sign' },
- to: 'https://mydomain.com/#/cotisation/resumepay',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- endOfSubsection: false,
- })
- })
- })
|