| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- 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 BillingMenuBuilder from '~/services/layout/menuBuilder/billingMenuBuilder'
- 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: BillingMenuBuilder
- 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 BillingMenuBuilder(
- runtimeConfig,
- ability,
- organizationProfile,
- accessProfile,
- router,
- )
- })
- describe('getMenuName', () => {
- test('validate name', () => {
- expect(menuBuilder.getMenuName()).toEqual('Billing')
- })
- })
- 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('billing')
- expect(result.icon).toEqual({ name: 'fas fa-euro-sign' })
- // @ts-ignore
- expect(result.children.length).toEqual(9)
- })
- test('has no items', () => {
- ability.can = vi.fn(() => false)
- expect(menuBuilder.build()).toEqual(null)
- })
- test('has only rights for menu billing_product', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'billing_product_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'billing_product',
- icon: { name: 'fas fa-cube' },
- to: 'https://mydomain.com/#/intangibles/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu billing_products_by_student', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'billing_products_by_student_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'billing_products_by_student',
- icon: { name: 'fas fa-cubes' },
- to: 'https://mydomain.com/#/access_intangibles/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu billing_edition', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'billing_edition_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'billing_edition',
- icon: { name: 'fas fa-copy' },
- to: 'https://mydomain.com/#/billing_edition',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu billing_accounting', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'billing_accounting_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'billing_accounting',
- icon: { name: 'fas fa-file-alt' },
- to: 'https://mydomain.com/#/bill_accountings/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu billing_payment_list', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'billing_payment_list_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'billing_payment_list',
- icon: { name: 'fas fa-credit-card' },
- to: 'https://mydomain.com/#/bill_payments_list/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu pes_export', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'pes_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'pes_export',
- icon: { name: 'fas fa-align-justify' },
- to: 'https://mydomain.com/#/pes/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu berger_levrault_export', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'berger_levrault_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'berger_levrault_export',
- icon: { name: 'fas fa-align-justify' },
- to: 'https://mydomain.com/#/berger_levraults/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu jvs_export', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'jvs_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'jvs_export',
- icon: { name: 'fas fa-align-justify' },
- to: 'https://mydomain.com/#/jvs/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu afi_export', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'afi_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'afi_export',
- icon: { name: 'fas fa-align-justify' },
- to: 'https://mydomain.com/#/afis/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- })
|