@@ -39,10 +39,12 @@ describe('NhsNotifyHeaderWithAccount', () => {
3939 setAuthStatus ( 'unauthenticated' ) ;
4040 } ) ;
4141
42- it ( 'renders the logo and service name with the correct url' , ( ) => {
42+ it ( 'renders the logo and service name with the correct url' , async ( ) => {
4343 render ( < NhsNotifyHeaderWithAccount /> ) ;
4444
45- const logoServiceLink = screen . getByTestId ( 'header-logo-service-link' ) ;
45+ const logoServiceLink = await screen . findByTestId (
46+ 'header-logo-service-link'
47+ ) ;
4648
4749 expect ( logoServiceLink ) . toContainElement (
4850 screen . getByRole ( 'img' , { name : 'NHS logo' } )
@@ -51,24 +53,28 @@ describe('NhsNotifyHeaderWithAccount', () => {
5153 expect ( logoServiceLink ) . toHaveTextContent ( 'Notify' ) ;
5254 } ) ;
5355
54- it ( `renders the authentication link as 'sign in'` , ( ) => {
56+ it ( `renders the authentication link as 'sign in'` , async ( ) => {
5557 render ( < NhsNotifyHeaderWithAccount /> ) ;
5658
57- expect ( screen . getByTestId ( 'auth-link' ) ) . toHaveTextContent ( 'Sign in' ) ;
59+ expect ( await screen . findByTestId ( 'auth-link' ) ) . toHaveTextContent (
60+ 'Sign in'
61+ ) ;
5862 } ) ;
5963
6064 it ( 'does not fetch session or claims' , async ( ) => {
6165 render ( < NhsNotifyHeaderWithAccount /> ) ;
6266
63- await Promise . resolve ( ) ;
67+ await screen . findByTestId ( 'page-header' ) ;
6468
6569 expect ( mockFetchAuthSession ) . not . toHaveBeenCalled ( ) ;
6670 expect ( mockGetIdTokenClaims ) . not . toHaveBeenCalled ( ) ;
6771 } ) ;
6872
69- it ( 'matches snapshot (unauthenticated)' , ( ) => {
73+ it ( 'matches snapshot (unauthenticated)' , async ( ) => {
7074 const container = render ( < NhsNotifyHeaderWithAccount /> ) ;
7175
76+ await screen . findByTestId ( 'page-header' ) ;
77+
7278 expect ( container . asFragment ( ) ) . toMatchSnapshot ( ) ;
7379 } ) ;
7480 } ) ;
@@ -94,29 +100,25 @@ describe('NhsNotifyHeaderWithAccount', () => {
94100 it ( 'renders the users display name' , async ( ) => {
95101 render ( < NhsNotifyHeaderWithAccount /> ) ;
96102
97- await waitFor ( ( ) => {
98- expect ( screen . getByTestId ( 'account-display-name' ) ) . toHaveTextContent (
99- 'Dr Test Example'
100- ) ;
101- } ) ;
103+ expect (
104+ await screen . findByTestId ( 'account-display-name' )
105+ ) . toHaveTextContent ( 'Dr Test Example' ) ;
102106 } ) ;
103107
104108 it ( 'renders the client name' , async ( ) => {
105109 render ( < NhsNotifyHeaderWithAccount /> ) ;
106110
107- await waitFor ( ( ) => {
108- expect ( screen . getByTestId ( 'account-client-name' ) ) . toHaveTextContent (
109- 'NHS England'
110- ) ;
111- } ) ;
111+ expect (
112+ await screen . findByTestId ( 'account-client-name' )
113+ ) . toHaveTextContent ( 'NHS England' ) ;
112114 } ) ;
113115
114116 it ( `renders auth link as 'Sign out'` , async ( ) => {
115117 render ( < NhsNotifyHeaderWithAccount /> ) ;
116118
117- await waitFor ( ( ) => {
118- expect ( screen . getByTestId ( 'auth-link' ) ) . toHaveTextContent ( ' Sign out') ;
119- } ) ;
119+ expect ( await screen . findByTestId ( 'auth-link' ) ) . toHaveTextContent (
120+ ' Sign out'
121+ ) ;
120122 } ) ;
121123
122124 it ( 'handles missing id token by clearing names' , async ( ) => {
@@ -129,34 +131,38 @@ describe('NhsNotifyHeaderWithAccount', () => {
129131
130132 render ( < NhsNotifyHeaderWithAccount /> ) ;
131133
132- await waitFor ( ( ) => {
133- expect ( screen . queryByTestId ( 'account-display-name' ) ) . toBeNull ( ) ;
134- expect ( screen . queryByTestId ( 'account-client -name' ) ) . toBeNull ( ) ;
135- } ) ;
134+ await screen . findByTestId ( 'page-header' ) ;
135+
136+ expect ( screen . queryByTestId ( 'account-display -name' ) ) . toBeNull ( ) ;
137+ expect ( screen . queryByTestId ( 'account-client-name' ) ) . toBeNull ( ) ;
136138 } ) ;
137139
138140 it ( 'handles fetchAuthSession errors by clearing names' , async ( ) => {
139141 mockFetchAuthSession . mockRejectedValueOnce ( new Error ( 'boom' ) ) ;
140142
141143 render ( < NhsNotifyHeaderWithAccount /> ) ;
142144
143- await waitFor ( ( ) => {
144- expect ( screen . queryByTestId ( 'account-display-name' ) ) . toBeNull ( ) ;
145- expect ( screen . queryByTestId ( 'account-client -name' ) ) . toBeNull ( ) ;
146- } ) ;
145+ await screen . findByTestId ( 'page-header' ) ;
146+
147+ expect ( screen . queryByTestId ( 'account-display -name' ) ) . toBeNull ( ) ;
148+ expect ( screen . queryByTestId ( 'account-client-name' ) ) . toBeNull ( ) ;
147149 } ) ;
148150
149- it ( 'matches snapshot (authenticated)' , ( ) => {
151+ it ( 'matches snapshot (authenticated)' , async ( ) => {
150152 const container = render ( < NhsNotifyHeaderWithAccount /> ) ;
151153
154+ await screen . findByTestId ( 'page-header' ) ;
155+
152156 expect ( container . asFragment ( ) ) . toMatchSnapshot ( ) ;
153157 } ) ;
154158 } ) ;
155159
156160 describe ( `with 'routing' flag enabled` , ( ) => {
157- it ( 'renders both the navigation links with correct hrefs' , ( ) => {
161+ it ( 'renders both the navigation links with correct hrefs' , async ( ) => {
158162 render ( < NhsNotifyHeaderWithAccount features = { { routing : true } } /> ) ;
159163
164+ await screen . findByTestId ( 'page-header' ) ;
165+
160166 const nav = screen . getByTestId ( 'navigation-links' ) ;
161167
162168 const templatesLink = within ( nav ) . getByRole ( 'link' , {
@@ -175,9 +181,11 @@ describe('NhsNotifyHeaderWithAccount', () => {
175181 } ) ;
176182
177183 describe ( `with 'routing' flag disabled` , ( ) => {
178- it ( 'renders the templates link with correct href' , ( ) => {
184+ it ( 'renders the templates link with correct href' , async ( ) => {
179185 render ( < NhsNotifyHeaderWithAccount features = { { routing : false } } /> ) ;
180186
187+ await screen . findByTestId ( 'page-header' ) ;
188+
181189 const nav = screen . getByTestId ( 'navigation-links' ) ;
182190
183191 const templatesLink = within ( nav ) . getByRole ( 'link' , {
@@ -186,9 +194,11 @@ describe('NhsNotifyHeaderWithAccount', () => {
186194 expect ( templatesLink ) . toHaveAttribute ( 'href' , '/message-templates' ) ;
187195 } ) ;
188196
189- it ( 'should not render the message plans link' , ( ) => {
197+ it ( 'should not render the message plans link' , async ( ) => {
190198 render ( < NhsNotifyHeaderWithAccount features = { { routing : false } } /> ) ;
191199
200+ await screen . findByTestId ( 'page-header' ) ;
201+
192202 const nav = screen . getByTestId ( 'navigation-links' ) ;
193203
194204 const plansLink = within ( nav ) . queryByRole ( 'link' , {
0 commit comments