@@ -60,35 +60,30 @@ test.describe('Doc Routing', () => {
6060
6161 await page . locator ( '.ProseMirror.bn-editor' ) . fill ( 'Hello World' ) ;
6262
63- // Wait for the doc link (via its dynamic title) to be visible
64- const docLink = page . getByRole ( 'link' , { name : docTitle } ) ;
65- await expect ( docLink ) . toBeVisible ( ) ;
66-
67- // Intercept GET/PATCH requests to return 401
68- await page . route ( / .* \/ d o c u m e n t s \/ .* \/ $ | u s e r s \/ m e \/ $ / , async ( route ) => {
69- const request = route . request ( ) ;
70- if (
71- request . method ( ) . includes ( 'PATCH' ) ||
72- request . method ( ) . includes ( 'GET' )
73- ) {
74- await route . fulfill ( {
75- status : 401 ,
76- json : { detail : 'Log in to access the document' } ,
77- } ) ;
78- } else {
79- await route . continue ( ) ;
80- }
81- } ) ;
82-
83- // Explicitly wait for a 401 response after clicking
84- const wait401 = page . waitForResponse (
85- ( resp ) =>
86- resp . status ( ) === 401 &&
87- / \/ ( d o c u m e n t s \/ [ ^ / ] + \/ | u s e r s \/ m e \/ ) $ / . test ( resp . url ( ) ) ,
63+ const responsePromise = page . route (
64+ / .* \/ d o c u m e n t s \/ .* \/ $ | u s e r s \/ m e \/ $ / ,
65+ async ( route ) => {
66+ const request = route . request ( ) ;
67+
68+ if (
69+ request . method ( ) . includes ( 'PATCH' ) ||
70+ request . method ( ) . includes ( 'GET' )
71+ ) {
72+ await route . fulfill ( {
73+ status : 401 ,
74+ json : {
75+ detail : 'Log in to access the document' ,
76+ } ,
77+ } ) ;
78+ } else {
79+ await route . continue ( ) ;
80+ }
81+ } ,
8882 ) ;
8983
90- await docLink . click ( ) ;
91- await wait401 ;
84+ await page . getByRole ( 'link' , { name : '401-doc-parent' } ) . click ( ) ;
85+
86+ await responsePromise ;
9287
9388 await expect ( page . getByText ( 'Log in to access the document.' ) ) . toBeVisible ( {
9489 timeout : 10000 ,
0 commit comments