-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove admin undefined access (#857)
- Loading branch information
1 parent
1d4c256
commit a9951d5
Showing
4 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; | ||
import { render, screen } from '@testing-library/react'; | ||
import Admin from '@/pages/admin/admin'; | ||
import '@testing-library/jest-dom'; | ||
import React from 'react'; | ||
import { AllProviders } from '@/mocks/setup-tests'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
describe('Test Admin Undefined', () => { | ||
beforeEach(() => { | ||
vi.mock('@azure/msal-react', async () => { | ||
return { | ||
useMsal: () => { | ||
return { | ||
instance: { | ||
getActiveAccount: () => { | ||
return { | ||
idTokenClaims: { | ||
}, | ||
}; | ||
}, | ||
}, | ||
}; | ||
}, | ||
}; | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
test('Does not show menu items', async () => { | ||
render(<Admin></Admin>, { wrapper: AllProviders }); | ||
expect(screen.queryByText('Users Menu Item')).toBeNull(); | ||
expect(screen.queryByText('Data Sources Menu Item')).toBeNull(); | ||
expect(screen.queryByText('Plugins Menu Item')).toBeNull(); | ||
expect(screen.queryByText('Configuration Menu Item')).toBeNull(); | ||
}); | ||
|
||
test('Shows unauthorised page', async () => { | ||
const route = '/admin'; | ||
|
||
render( | ||
<MemoryRouter initialEntries={[route]}> | ||
<Admin></Admin> | ||
</MemoryRouter> | ||
); | ||
expect(await screen.findByText('You are unauthorized to view this page.')).toBeInTheDocument(); | ||
expect(await screen.findByText('Please contact your administrator.')).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters