11import { render , screen } from '@testing-library/react' ;
22import HomePage from './HomePage' ;
3- import useRole from '../../helpers/hooks/useRole' ;
4- import { REPOSITORY_ROLE } from '../../types/generic/authRole' ;
53import { buildConfig } from '../../helpers/test/testBuilders' ;
64import useConfig from '../../helpers/hooks/useConfig' ;
5+ import { routes } from '../../types/generic/routes' ;
76import { afterEach , beforeEach , describe , expect , it , vi , Mock } from 'vitest' ;
87
98const mockedUseNavigate = vi . fn ( ) ;
@@ -15,9 +14,7 @@ vi.mock('react-router-dom', async () => {
1514 } ;
1615} ) ;
1716
18- vi . mock ( '../../helpers/hooks/useRole' ) ;
1917vi . mock ( '../../helpers/hooks/useConfig' ) ;
20- const mockUseRole = useRole as Mock ;
2118const mockUseConfig = useConfig as Mock ;
2219
2320describe ( 'HomePage' , ( ) => {
@@ -27,33 +24,40 @@ describe('HomePage', () => {
2724 afterEach ( ( ) => {
2825 vi . clearAllMocks ( ) ;
2926 } ) ;
30- const gpRoles = [ REPOSITORY_ROLE . GP_ADMIN , REPOSITORY_ROLE . GP_CLINICAL ] ;
3127
32- const validateHomePageRendered = ( ) => {
33- render ( < HomePage /> ) ;
28+ describe ( 'Rendering' , ( ) => {
29+ it ( 'should render home page with patient search and download report' , async ( ) => {
30+ render ( < HomePage /> ) ;
3431
35- const searchPatientButton = screen . getByTestId ( 'search-patient-btn' ) as HTMLAnchorElement ;
36- const downloadReportButton = screen . getByTestId ( 'download-report-btn' ) as HTMLAnchorElement ;
37- expect ( searchPatientButton ) . toBeInTheDocument ( ) ;
38- expect ( downloadReportButton ) . toBeInTheDocument ( ) ;
39- } ;
32+ const searchPatientButton = screen . getByTestId ( 'search-patient-btn' ) as HTMLAnchorElement ;
33+ const downloadReportButton = screen . getByTestId ( 'download-report-btn' ) as HTMLAnchorElement ;
34+ expect ( searchPatientButton ) . toBeInTheDocument ( ) ;
35+ expect ( downloadReportButton ) . toBeInTheDocument ( ) ;
36+ } ) ;
37+ } ) ;
4038
41- describe ( 'Rendering for GP roles ' , ( ) => {
42- it . each ( gpRoles ) (
43- '[%s] render home page with patient search and download report' ,
44- async ( role ) => {
45- mockUseRole . mockReturnValue ( role ) ;
39+ describe ( 'Admin Console button ' , ( ) => {
40+ it ( 'renders admin console button when feature flag is enabled' , ( ) => {
41+ mockUseConfig . mockReturnValue (
42+ buildConfig ( undefined , { uploadDocumentIteration3Enabled : true } ) ,
43+ ) ;
4644
47- validateHomePageRendered ( ) ;
48- } ,
49- ) ;
50- } ) ;
45+ render ( < HomePage /> ) ;
5146
52- describe ( 'PCSE Rendering' , ( ) => {
53- it ( 'should render home page with patient search and download report' , async ( ) => {
54- mockUseRole . mockReturnValue ( REPOSITORY_ROLE . PCSE ) ;
47+ const adminConsoleButton = screen . getByTestId ( 'admin-console-btn' ) as HTMLAnchorElement ;
48+ expect ( adminConsoleButton ) . toBeInTheDocument ( ) ;
49+ expect ( adminConsoleButton ) . toHaveTextContent ( 'Admin console' ) ;
50+ expect ( adminConsoleButton ) . toHaveAttribute ( 'href' , routes . ADMIN_ROUTE ) ;
51+ } ) ;
52+
53+ it ( 'does not render admin console button when feature flag is disabled' , ( ) => {
54+ mockUseConfig . mockReturnValue (
55+ buildConfig ( undefined , { uploadDocumentIteration3Enabled : false } ) ,
56+ ) ;
57+
58+ render ( < HomePage /> ) ;
5559
56- validateHomePageRendered ( ) ;
60+ expect ( screen . queryByTestId ( 'admin-console-btn' ) ) . not . toBeInTheDocument ( ) ;
5761 } ) ;
5862 } ) ;
5963} ) ;
0 commit comments