Browse Source

fix and complete unit tests

Olivier Massot 2 years ago
parent
commit
cd601306f3

+ 0 - 4
services/layout/menuBuilder/statsMenuBuilder.ts

@@ -31,10 +31,6 @@ export default class StatsMenuBuilder extends AbstractMenuBuilder {
       children.push(this.createItem('structure_stats', {name: 'fas fa-chart-bar'}, '/statistic/membersfedeassos', MENU_LINK_TYPE.V1))
     }
 
-    if (this.ability.can('display', 'structure_stats_page')) {
-      children.push(this.createItem('structure_stats', {name: 'fas fa-chart-bar'}, '/statistic/membersfedeassos', MENU_LINK_TYPE.V1))
-    }
-
     if (children.length > 1) {
       // Plusieurs éléments, on retourne un groupe
       return this.createGroup('stats', {name: 'fas fa-chart-bar'}, children)

+ 3 - 2
tests/units/services/layout/menuBuilder/configurationMenuBuilder.test.ts

@@ -52,9 +52,10 @@ describe('build', () => {
 
     test('has only rights for menu organization_page', () => {
         ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'organization_page')
+        organizationProfile.id = 123
 
         expect(menuBuilder.build()).toEqual(
-            {label: 'organization_page', icon: undefined, to: 'https://mydomain.com/#/organization', type: MENU_LINK_TYPE.V1, active: false}
+            {label: 'organization_page', icon: undefined, to: 'https://mydomain.com/#/main/organizations/123/dashboard', type: MENU_LINK_TYPE.V1, active: false}
         )
     })
 
@@ -62,7 +63,7 @@ describe('build', () => {
         ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'cmf_licence_page')
 
         expect(menuBuilder.build()).toEqual(
-            {label: 'cmf_licence_generate', icon: undefined, to: 'https://mydomain.com/#/cmf_licence/organization', type: MENU_LINK_TYPE.V1, active: false}
+            {label: 'cmf_licence_generate', icon: undefined, to: 'https://mydomain.com/#/licence_cmf/organization', type: MENU_LINK_TYPE.V1, active: false}
         )
     })
 

+ 14 - 1
tests/units/services/layout/menuBuilder/statsMenuBuilder.test.ts

@@ -42,7 +42,7 @@ describe('build', () => {
         expect(result.label).toEqual('stats')
         expect(result.icon).toEqual({name: 'fas fa-chart-bar'})
         // @ts-ignore
-        expect(result.children.length).toEqual(4)
+        expect(result.children.length).toEqual(5)
     })
 
     test('has no items', () => {
@@ -58,6 +58,19 @@ describe('build', () => {
         )
     })
 
+    test('has only rights for menu educations_quotas_by_education and accesses_quotas_courses_hebdos', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'education_quotas_page')
+
+        const group = menuBuilder.build() as MenuGroup
+
+        expect(group.children).toEqual(
+          [
+              {label: 'educations_quotas_by_education', icon: {name: 'fas fa-user-circle'}, to: 'https://mydomain.com/#/educations_quotas_by_education_year/list/', type: MENU_LINK_TYPE.V1, active: false},
+             {label: 'accesses_quotas_courses_hebdos', icon: {name: 'fas fa-user-circle'}, to: 'https://mydomain.com/#/accesses_quotas_courses_hebdos/list/', type: MENU_LINK_TYPE.V1, active: false}
+          ]
+        )
+    })
+
     test('has only rights for menu fede_stats', () => {
         ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'fede_stats_page')