@@ -31,58 +31,71 @@ jest.mock("@src/app/_components/hub/PregnancyHubContent", () => ({
3131 . mockImplementation ( ( ) => < p data-testid = { "pregnancy-hub-content" } > Pregnancy hub content test</ p > ) ,
3232} ) ) ;
3333
34- const mockAgeGroup = AgeGroup . AGE_25_to_64 ;
35-
36- const mockSessionValue : Partial < Session > = {
37- expires : new Date ( Date . now ( ) + 60000 ) . toISOString ( ) ,
38- user : {
39- nhs_number : "" as NhsNumber ,
40- age_group : mockAgeGroup ,
41- } ,
34+ const mockSessionDataForAgeGroup = ( ageGroup : AgeGroup ) : Partial < Session > => {
35+ return {
36+ expires : new Date ( Date . now ( ) + 60000 ) . toISOString ( ) ,
37+ user : {
38+ nhs_number : "" as NhsNumber ,
39+ age_group : ageGroup ,
40+ } ,
41+ } ;
4242} ;
4343
44- const mockSession = { data : mockSessionValue , status : "authenticated" } ;
44+ describe ( "Vaccination Hub Page" , ( ) => {
45+ describe ( "for all ages" , ( ) => {
46+ const mockAgeGroup = AgeGroup . AGE_25_to_64 ;
4547
46- jest . mock ( "next-auth/react" , ( ) => ( {
47- useSession : ( ) => mockSession ,
48- } ) ) ;
48+ beforeEach ( async ( ) => {
49+ ( auth as jest . Mock ) . mockResolvedValue ( mockSessionDataForAgeGroup ( mockAgeGroup ) ) ;
4950
50- describe ( "Vaccination Hub Page" , ( ) => {
51- beforeEach ( async ( ) => {
52- ( auth as jest . Mock ) . mockResolvedValue ( mockSessionValue ) ;
51+ render ( await VaccinationsHub ( ) ) ;
52+ } ) ;
5353
54- render ( await VaccinationsHub ( ) ) ;
55- } ) ;
54+ it ( "renders main heading" , async ( ) => {
55+ expectHeadingToBeRendered ( ) ;
56+ } ) ;
5657
57- it ( "renders main heading" , async ( ) => {
58- expectHeadingToBeRendered ( ) ;
59- } ) ;
58+ it ( "renders age based cards for user" , ( ) => {
59+ const ageBasedHubCards : HTMLElement = screen . getByTestId ( "age-based-hub-cards" ) ;
6060
61- it ( "renders age based cards for user" , ( ) => {
62- const ageBasedHubCards : HTMLElement = screen . getByTestId ( "age-based-hub-cards" ) ;
61+ expect ( ageBasedHubCards ) . toBeVisible ( ) ;
62+ expect ( AgeBasedHubCards ) . toHaveBeenCalledWith (
63+ {
64+ ageGroup : mockAgeGroup ,
65+ } ,
66+ undefined ,
67+ ) ;
68+ } ) ;
6369
64- expect ( ageBasedHubCards ) . toBeVisible ( ) ;
65- expect ( AgeBasedHubCards ) . toHaveBeenCalledWith (
66- {
67- ageGroup : mockAgeGroup ,
68- } ,
69- undefined ,
70- ) ;
71- } ) ;
70+ it ( "should show at risk expander " , ( ) => {
71+ const atRiskHubExpander : HTMLElement = screen . getByTestId ( "at-risk-hub-expander" ) ;
72+ expect ( atRiskHubExpander ) . toBeVisible ( ) ;
73+ } ) ;
7274
73- it ( "should show at risk expander " , ( ) => {
74- const atRiskHubExpander : HTMLElement = screen . getByTestId ( "at-risk-hub-expander" ) ;
75- expect ( atRiskHubExpander ) . toBeVisible ( ) ;
76- } ) ;
75+ it ( "should show pregnancy hub content " , ( ) => {
76+ const pregnancyHubContent : HTMLElement = screen . getByTestId ( "pregnancy-hub-content" ) ;
7777
78- it ( "should show pregnancy hub content " , ( ) => {
79- const pregnancyHubContent : HTMLElement = screen . getByTestId ( "pregnancy-hub-content" ) ;
78+ expect ( pregnancyHubContent ) . toBeVisible ( ) ;
79+ } ) ;
8080
81- expect ( pregnancyHubContent ) . toBeVisible ( ) ;
81+ it ( "renders vaccines for all ages button" , async ( ) => {
82+ expectLinkToBeRendered ( "View vaccines for all ages" , "/vaccines-for-all-ages" ) ;
83+ } ) ;
8284 } ) ;
8385
84- it ( "renders vaccines for all ages button" , async ( ) => {
85- expectLinkToBeRendered ( "View vaccines for all ages" , "/vaccines-for-all-ages" ) ;
86+ describe ( "pregnancy hub content" , ( ) => {
87+ it . each ( [
88+ { description : "hide" , ageGroup : AgeGroup . AGE_65_to_74 , shouldShowPregnancyContent : false } ,
89+ { description : "show" , ageGroup : AgeGroup . UNKNOWN_AGE_GROUP , shouldShowPregnancyContent : true } ,
90+ ] ) ( `$ageGroup should $description pregnancy content` , async ( { ageGroup, shouldShowPregnancyContent } ) => {
91+ ( auth as jest . Mock ) . mockResolvedValue ( mockSessionDataForAgeGroup ( ageGroup ) ) ;
92+
93+ render ( await VaccinationsHub ( ) ) ;
94+
95+ const pregnancyHubContent : HTMLElement | null = screen . queryByTestId ( "pregnancy-hub-content" ) ;
96+
97+ shouldShowPregnancyContent ? expect ( pregnancyHubContent ) . toBeVisible ( ) : expect ( pregnancyHubContent ) . toBeNull ( ) ;
98+ } ) ;
8699 } ) ;
87100} ) ;
88101
0 commit comments