@@ -151,4 +151,67 @@ describe('TopBarComponent', () => {
151151 )
152152 } )
153153 } )
154+
155+ /*
156+ * PD-5692. A record that has to reset its password gets here through a
157+ * linked institutional account, and the notice takes it straight to the
158+ * Account password panel.
159+ */
160+ describe ( 'mandatory password reset notice' , ( ) => {
161+ const notice = ( ) : HTMLElement =>
162+ fixture . nativeElement . querySelector (
163+ '[id="cy-force-password-reset-notice"]'
164+ )
165+
166+ it ( 'shows above everything else and links to the password panel' , ( ) => {
167+ component . userInfo = { FORCE_PASSWORD_RESET : 'true' } as any
168+ component . userRecord = {
169+ names : {
170+ givenNames : { value : 'Given' } ,
171+ familyName : { value : 'Family' } ,
172+ visibility : { visibility : 'PUBLIC' } ,
173+ } ,
174+ } as any
175+ fixture . detectChanges ( )
176+
177+ expect ( notice ( ) ) . toBeTruthy ( )
178+ const link : HTMLAnchorElement = notice ( ) . querySelector (
179+ '#cy-force-password-reset-link'
180+ )
181+ expect ( link . getAttribute ( 'href' ) ) . toBe ( '/account#password' )
182+ expect ( link . textContent . trim ( ) ) . toBe ( 'Reset your account password now' )
183+ // The first thing in the signed-in part of the page, ahead of every
184+ // other notice and of the names panel, as the frame draws it
185+ const host : HTMLElement = fixture . nativeElement
186+ const children = Array . from ( host . children )
187+ const previous = children [ children . indexOf ( notice ( ) ) - 1 ]
188+ expect ( previous . tagName . toLowerCase ( ) ) . toBe (
189+ 'app-top-bar-verification-email'
190+ )
191+ const names = host . querySelector ( '#names' )
192+ expect ( names ) . toBeTruthy ( )
193+ expect (
194+ notice ( ) . compareDocumentPosition ( names ) &
195+ Node . DOCUMENT_POSITION_FOLLOWING
196+ ) . toBeTruthy ( )
197+ } )
198+
199+ it ( 'is absent when no reset is owed' , ( ) => {
200+ component . userInfo = { FORCE_PASSWORD_RESET : 'false' } as any
201+ fixture . detectChanges ( )
202+ expect ( notice ( ) ) . toBeNull ( )
203+
204+ component . userInfo = { } as any
205+ fixture . detectChanges ( )
206+ expect ( notice ( ) ) . toBeNull ( )
207+ } )
208+
209+ it ( 'is absent on a public record' , ( ) => {
210+ component . isPublicRecord = 'true' as any
211+ component . userInfo = { FORCE_PASSWORD_RESET : 'true' } as any
212+ fixture . detectChanges ( )
213+
214+ expect ( notice ( ) ) . toBeNull ( )
215+ } )
216+ } )
154217} )
0 commit comments