| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- import { describe, expect, test, beforeEach, vi } 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 AccountMenuBuilder from '~/services/layout/menuBuilder/accountMenuBuilder'
- import type { MenuGroup } from '~/types/layout'
- import { MENU_LINK_TYPE } from '~/types/enum/layout'
- import { GENDER } from '~/types/enum/enums'
- let runtimeConfig: RuntimeConfig
- let ability: AnyAbility
- let organizationProfile: organizationState
- let accessProfile: AccessProfile
- let menuBuilder: AccountMenuBuilder
- 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 any as AccessProfile
- runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
- accessProfile.id = 123
- menuBuilder = new AccountMenuBuilder(
- runtimeConfig,
- ability,
- organizationProfile,
- accessProfile,
- router,
- )
- })
- describe('getMenuName', () => {
- test('validate name', () => {
- expect(menuBuilder.getMenuName()).toEqual('Account')
- })
- })
- describe('build', () => {
- test('has all items (mister)', () => {
- ability.can = vi.fn(() => true)
- // @ts-ignore
- router.resolve = vi.fn(() => {
- return { href: 'foo ' }
- })
- // Should return a MenuGroup
- const result = menuBuilder.build() as MenuGroup
- expect(result.label).toEqual('my_account')
- // @ts-ignore
- expect(result.children.length).toEqual(14)
- // @ts-ignore
- expect(result.actions.length).toEqual(1)
- // Has the logout action
- // @ts-ignore
- expect(result.actions).toEqual([
- {
- label: 'logout',
- icon: undefined,
- to: 'https://mydomain.com/#/logout',
- type: MENU_LINK_TYPE.V1,
- active: false,
- },
- ])
- })
- test('has profile icon : mister)', () => {
- ability.can = vi.fn(() => false)
- accessProfile.avatarId = 100
- accessProfile.gender = GENDER.MISTER
- const result = menuBuilder.build() as MenuGroup
- expect(result.icon).toEqual({
- avatarId: 100,
- avatarByDefault: '/images/default/men-1.png',
- })
- })
- test('has profile icon : miss)', () => {
- ability.can = vi.fn(() => false)
- accessProfile.avatarId = 100
- accessProfile.gender = GENDER.MISS
- const result = menuBuilder.build() as MenuGroup
- expect(result.icon).toEqual({
- avatarId: 100,
- avatarByDefault: '/images/default/women-1.png',
- })
- })
- test('has no items', () => {
- ability.can = vi.fn(() => false)
- const group = menuBuilder.build()
- // AccountMenuBuilder retourne toujours un groupe
- // @ts-ignore
- expect(group.children).toEqual([])
- // Still has the logout action
- // @ts-ignore
- expect(group.actions).toEqual([
- {
- label: 'logout',
- icon: undefined,
- to: 'https://mydomain.com/#/logout',
- type: MENU_LINK_TYPE.V1,
- active: false,
- },
- ])
- })
- test('has only rights for menu my_schedule_page', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'my_schedule_page',
- )
- // @ts-ignore
- expect(menuBuilder.build().children[0]).toEqual({
- label: 'my_schedule_page',
- icon: undefined,
- to: 'https://mydomain.com/#/my_calendar',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu attendance_bookings_menu', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'attendance_bookings_page',
- )
- // @ts-ignore
- expect(menuBuilder.build().children[0]).toEqual({
- label: 'attendance_bookings_menu',
- icon: undefined,
- to: 'https://mydomain.com/#/own_attendance',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu my_attendance', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'my_attendance_page',
- )
- // @ts-ignore
- expect(menuBuilder.build().children[0]).toEqual({
- label: 'my_attendance',
- icon: undefined,
- to: 'https://mydomain.com/#/my_attendances/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu my_invitation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'my_invitation_page',
- )
- // @ts-ignore
- expect(menuBuilder.build().children[0]).toEqual({
- label: 'my_invitation',
- icon: undefined,
- to: 'https://mydomain.com/#/my_invitations/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu my_students', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'my_students_page',
- )
- // @ts-ignore
- expect(menuBuilder.build().children[0]).toEqual({
- label: 'my_students',
- icon: undefined,
- to: 'https://mydomain.com/#/my_students/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu my_students_education_students', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' &&
- subject === 'my_students_education_students_page',
- )
- // @ts-ignore
- expect(menuBuilder.build().children[0]).toEqual({
- label: 'my_students_education_students',
- icon: undefined,
- to: 'https://mydomain.com/#/my_students_education_students/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu my_education_students', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'my_education_students_page',
- )
- // @ts-ignore
- expect(menuBuilder.build().children[0]).toEqual({
- label: 'my_education_students',
- icon: undefined,
- to: 'https://mydomain.com/#/main/my_profile/123/dashboard/my_education_students/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu send_an_email', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'send_an_email_page',
- )
- // @ts-ignore
- expect(menuBuilder.build().children[0]).toEqual({
- label: 'send_an_email',
- icon: undefined,
- to: 'https://mydomain.com/#/list/create/emails',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu my_documents', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'my_documents_page',
- )
- // @ts-ignore
- expect(menuBuilder.build().children[0]).toEqual({
- label: 'my_documents',
- icon: undefined,
- to: 'https://mydomain.com/#/main/my_profile/123/dashboard/show/my_access_file',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu my_profile', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'my_profile_page',
- )
- // @ts-ignore
- expect(menuBuilder.build().children[0]).toEqual({
- label: 'my_profile',
- icon: undefined,
- to: 'https://mydomain.com/#/main/my_profile/123/dashboard',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu adherent_list', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'adherent_list_page',
- )
- // @ts-ignore
- expect(menuBuilder.build().children[0]).toEqual({
- label: 'adherent_list',
- icon: undefined,
- to: 'https://mydomain.com/#/adherent_contacts/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu subscription', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'subscription_page',
- )
- // @ts-ignore
- router.resolve = vi.fn(() => {
- return { href: 'subscription' }
- })
- // @ts-ignore
- expect(menuBuilder.build().children[0]).toEqual({
- label: 'subscription_page',
- icon: undefined,
- to: 'subscription',
- type: MENU_LINK_TYPE.INTERNAL,
- active: false,
- })
- expect(router.resolve).toHaveBeenCalledWith({ name: 'subscription_page' })
- })
- test('has only rights for menu my_bills', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'my_bills_page',
- )
- // @ts-ignore
- expect(menuBuilder.build().children[0]).toEqual({
- label: 'my_bills',
- icon: undefined,
- to: 'https://mydomain.com/#/main/my_profile/123/dashboard/show/my_bills',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu print_my_licence', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'cmf_licence_person_page',
- )
- // @ts-ignore
- expect(menuBuilder.build().children[0]).toEqual({
- label: 'print_my_licence',
- icon: undefined,
- to: 'https://mydomain.com/#/licence_cmf/user',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- })
|