@@ -7,6 +7,7 @@ import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
77import type { MockedFunction } from 'vitest'
88import { mount } from '@vue/test-utils'
99import type { VueWrapper } from '@vue/test-utils'
10+ import { ref , nextTick } from 'vue'
1011import type { TranslationFunction } from '../../test-types'
1112
1213type SettingsComponent = typeof import ( '../../../components/Settings/Settings.vue' ) . default
@@ -20,6 +21,7 @@ let auth: AuthModule
2021let initialState : InitialStateModule
2122let getCurrentUserMock : MockedFunction < typeof import ( '@nextcloud/auth' ) . getCurrentUser >
2223let loadStateMock : MockedFunction < typeof import ( '@nextcloud/initial-state' ) . loadState >
24+ const mockPolicies = ref < Record < string , unknown > > ( { } )
2325
2426type SettingsVm = {
2527 getAdminRoute : ( ) => string
@@ -42,6 +44,13 @@ vi.mock('@nextcloud/initial-state', () => ({
4244vi . mock ( '@nextcloud/router' , ( ) => ( {
4345 generateUrl : vi . fn ( ( url ) => `/admin/${ url } ` ) ,
4446} ) )
47+ vi . mock ( '../../../store/policies' , ( ) => ( {
48+ usePoliciesStore : ( ) => ( {
49+ get policies ( ) {
50+ return mockPolicies . value
51+ } ,
52+ } ) ,
53+ } ) )
4554
4655beforeAll ( async ( ) => {
4756 auth = await import ( '@nextcloud/auth' )
@@ -97,19 +106,14 @@ describe('Settings', () => {
97106 ) : SettingsWrapper => {
98107 const user = { isAdmin } as ReturnType < typeof auth . getCurrentUser >
99108 getCurrentUserMock . mockReturnValue ( user )
109+ mockPolicies . value = effectivePolicies
100110 loadStateMock . mockImplementation ( ( app , key , defaults ) => {
101111 if ( key === 'config' ) {
102112 return {
103113 ...( defaults as Record < string , unknown > ) ,
104114 can_manage_group_policies : canManagePolicies ,
105115 }
106116 }
107- if ( key === 'effective_policies' ) {
108- return {
109- ...( defaults as Record < string , unknown > ) ,
110- policies : effectivePolicies ,
111- }
112- }
113117 return defaults
114118 } )
115119
@@ -138,6 +142,7 @@ describe('Settings', () => {
138142 wrapper = null
139143 }
140144 vi . clearAllMocks ( )
145+ mockPolicies . value = { }
141146 loadStateMock . mockImplementation ( ( app , key , defaults ) => defaults )
142147 } )
143148
@@ -392,17 +397,16 @@ describe('Settings', () => {
392397 expect ( policiesItem . props ( 'to' ) ) . toEqual ( { name : 'Policies' } )
393398 } )
394399
395- it ( 'hides Policies for non-admin users with group policy capability but no editable policies' , ( ) => {
400+ it ( 'hides Policies for non-admin users with group policy capability but no delegated policies' , ( ) => {
396401 wrapper = createWrapper ( false , true )
397402 const items = getItems ( )
398403
399404 expect ( findItemByName ( items , 'Policies' ) ) . toBeUndefined ( )
400405 } )
401406
402- it ( 'shows Policies for non-admin users with group policy capability and editable policies' , ( ) => {
407+ it ( 'shows Policies for non-admin users with group policy capability and delegated policies' , ( ) => {
403408 wrapper = createWrapper ( false , true , {
404409 signature_flow : {
405- editableByCurrentActor : true ,
406410 groupCount : 1 ,
407411 userCount : 0 ,
408412 } ,
@@ -413,10 +417,9 @@ describe('Settings', () => {
413417 expect ( policiesItem . props ( 'to' ) ) . toEqual ( { name : 'Policies' } )
414418 } )
415419
416- it ( 'hides Policies for non-admin users when only system-level editable policies exist' , ( ) => {
420+ it ( 'hides Policies for non-admin users when only system-level policies exist' , ( ) => {
417421 wrapper = createWrapper ( false , true , {
418422 docmdp : {
419- editableByCurrentActor : true ,
420423 groupCount : 0 ,
421424 userCount : 0 ,
422425 } ,
@@ -426,6 +429,22 @@ describe('Settings', () => {
426429 expect ( findItemByName ( items , 'Policies' ) ) . toBeUndefined ( )
427430 } )
428431
432+ it ( 'updates Policies visibility after the policies store receives delegated counts' , async ( ) => {
433+ wrapper = createWrapper ( false , true )
434+ expect ( findItemByName ( getItems ( ) , 'Policies' ) ) . toBeUndefined ( )
435+
436+ mockPolicies . value = {
437+ add_footer : {
438+ groupCount : 1 ,
439+ userCount : 0 ,
440+ } ,
441+ }
442+ await nextTick ( )
443+
444+ const policiesItem = expectItem ( findItemByName ( getItems ( ) , 'Policies' ) )
445+ expect ( policiesItem . props ( 'to' ) ) . toEqual ( { name : 'Policies' } )
446+ } )
447+
429448 it ( 'renders the policies icon for admin users' , ( ) => {
430449 wrapper = createWrapper ( true )
431450
0 commit comments