diff --git a/ui/src/layout/AppBar.test.jsx b/ui/src/layout/AppBar.test.jsx index 3b3015f2f..d3bae0635 100644 --- a/ui/src/layout/AppBar.test.jsx +++ b/ui/src/layout/AppBar.test.jsx @@ -8,11 +8,12 @@ import AppBar from './AppBar' import config from '../config' let store +let mockPermissions = 'admin' vi.mock('react-admin', () => ({ AppBar: ({ userMenu }) =>
{userMenu}
, useTranslate: () => (x) => x, - usePermissions: () => ({ permissions: 'admin' }), + usePermissions: () => ({ permissions: mockPermissions }), getResources: () => [], })) @@ -40,6 +41,7 @@ describe('', () => { config.devActivityPanel = true config.enableNowPlaying = true config.nowPlayingAdminOnly = true + mockPermissions = 'admin' store = createStore(combineReducers({ activity: activityReducer }), { activity: { nowPlayingCount: 0 }, }) @@ -73,4 +75,67 @@ describe('', () => { ) expect(screen.getByTestId('now-playing-panel')).toBeInTheDocument() }) + + describe('admin-only mode', () => { + beforeEach(() => { + config.nowPlayingAdminOnly = true + }) + + it('shows NowPlayingPanel to admin users', () => { + mockPermissions = 'admin' + render( + + + , + ) + expect(screen.getByTestId('now-playing-panel')).toBeInTheDocument() + }) + + it('hides NowPlayingPanel from non-admin users', () => { + mockPermissions = 'user' + render( + + + , + ) + expect(screen.queryByTestId('now-playing-panel')).toBeNull() + }) + }) + + describe('non-admin users', () => { + beforeEach(() => { + mockPermissions = 'user' + }) + + it('cannot see NowPlayingPanel when adminOnly is true', () => { + config.nowPlayingAdminOnly = true + render( + + + , + ) + expect(screen.queryByTestId('now-playing-panel')).toBeNull() + }) + + it('can see NowPlayingPanel when adminOnly is false', () => { + config.nowPlayingAdminOnly = false + render( + + + , + ) + expect(screen.getByTestId('now-playing-panel')).toBeInTheDocument() + }) + + it('cannot see NowPlayingPanel when feature is disabled', () => { + config.enableNowPlaying = false + config.nowPlayingAdminOnly = false + render( + + + , + ) + expect(screen.queryByTestId('now-playing-panel')).toBeNull() + }) + }) })