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' ;
75import { routes } from '../../types/generic/routes' ;
@@ -16,9 +14,7 @@ vi.mock('react-router-dom', async () => {
1614 } ;
1715} ) ;
1816
19- vi . mock ( '../../helpers/hooks/useRole' ) ;
2017vi . mock ( '../../helpers/hooks/useConfig' ) ;
21- const mockUseRole = useRole as Mock ;
2218const mockUseConfig = useConfig as Mock ;
2319
2420describe ( 'HomePage' , ( ) => {
@@ -28,39 +24,20 @@ describe('HomePage', () => {
2824 afterEach ( ( ) => {
2925 vi . clearAllMocks ( ) ;
3026 } ) ;
31- const gpRoles = [ REPOSITORY_ROLE . GP_ADMIN , REPOSITORY_ROLE . GP_CLINICAL ] ;
3227
33- const validateHomePageRendered = ( ) => {
34- render ( < HomePage /> ) ;
35-
36- const searchPatientButton = screen . getByTestId ( 'search-patient-btn' ) as HTMLAnchorElement ;
37- const downloadReportButton = screen . getByTestId ( 'download-report-btn' ) as HTMLAnchorElement ;
38- expect ( searchPatientButton ) . toBeInTheDocument ( ) ;
39- expect ( downloadReportButton ) . toBeInTheDocument ( ) ;
40- } ;
41-
42- describe ( 'Rendering for GP roles' , ( ) => {
43- it . each ( gpRoles ) (
44- '[%s] render home page with patient search and download report' ,
45- async ( role ) => {
46- mockUseRole . mockReturnValue ( role ) ;
47-
48- validateHomePageRendered ( ) ;
49- } ,
50- ) ;
51- } ) ;
52-
53- describe ( 'PCSE Rendering' , ( ) => {
28+ describe ( 'Rendering' , ( ) => {
5429 it ( 'should render home page with patient search and download report' , async ( ) => {
55- mockUseRole . mockReturnValue ( REPOSITORY_ROLE . PCSE ) ;
30+ render ( < HomePage /> ) ;
5631
57- validateHomePageRendered ( ) ;
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 ( ) ;
5836 } ) ;
5937 } ) ;
6038
6139 describe ( 'Admin Console button' , ( ) => {
62- it ( 'renders admin console button when feature flag is enabled and user is GP_ADMIN' , ( ) => {
63- mockUseRole . mockReturnValue ( REPOSITORY_ROLE . GP_ADMIN ) ;
40+ it ( 'renders admin console button when feature flag is enabled' , ( ) => {
6441 mockUseConfig . mockReturnValue (
6542 buildConfig ( undefined , { uploadDocumentIteration3Enabled : true } ) ,
6643 ) ;
@@ -74,7 +51,6 @@ describe('HomePage', () => {
7451 } ) ;
7552
7653 it ( 'does not render admin console button when feature flag is disabled' , ( ) => {
77- mockUseRole . mockReturnValue ( REPOSITORY_ROLE . GP_ADMIN ) ;
7854 mockUseConfig . mockReturnValue (
7955 buildConfig ( undefined , { uploadDocumentIteration3Enabled : false } ) ,
8056 ) ;
@@ -83,27 +59,5 @@ describe('HomePage', () => {
8359
8460 expect ( screen . queryByTestId ( 'admin-console-btn' ) ) . not . toBeInTheDocument ( ) ;
8561 } ) ;
86-
87- it ( 'does not render admin console button when user is GP_CLINICAL' , ( ) => {
88- mockUseRole . mockReturnValue ( REPOSITORY_ROLE . GP_CLINICAL ) ;
89- mockUseConfig . mockReturnValue (
90- buildConfig ( undefined , { uploadDocumentIteration3Enabled : true } ) ,
91- ) ;
92-
93- render ( < HomePage /> ) ;
94-
95- expect ( screen . queryByTestId ( 'admin-console-btn' ) ) . not . toBeInTheDocument ( ) ;
96- } ) ;
97-
98- it ( 'does not render admin console button when user is PCSE' , ( ) => {
99- mockUseRole . mockReturnValue ( REPOSITORY_ROLE . PCSE ) ;
100- mockUseConfig . mockReturnValue (
101- buildConfig ( undefined , { uploadDocumentIteration3Enabled : true } ) ,
102- ) ;
103-
104- render ( < HomePage /> ) ;
105-
106- expect ( screen . queryByTestId ( 'admin-console-btn' ) ) . not . toBeInTheDocument ( ) ;
107- } ) ;
10862 } ) ;
10963} ) ;
0 commit comments