@@ -22,38 +22,33 @@ test.describe('Multi-field search', () => {
2222 await searchPage . ebolaSudan ( ) ;
2323 await searchPage . waitForSequencesInSearch ( 3 ) ;
2424
25- // Search using identifier field (matches submissionId 'foobar-readonly-*')
2625 const identifierField = page . getByRole ( 'textbox' , { name : 'Identifier' , exact : true } ) ;
2726 await identifierField . fill ( 'foobar-readonly' ) ;
2827 await identifierField . press ( 'Enter' ) ;
29- await page . waitForTimeout ( 500 ) ;
28+ await page . waitForFunction (
29+ ( ) =>
30+ new URL ( window . location . href ) . searchParams . get ( 'identifier' ) === 'foobar-readonly' ,
31+ ) ;
3032
31- // Verify URL contains identifier parameter
3233 let urlParams = new URL ( page . url ( ) ) . searchParams ;
3334 expect ( urlParams . get ( 'identifier' ) ) . toBe ( 'foobar-readonly' ) ;
34-
35- // Should still show all 3 sequences (all have foobar-readonly-* submissionId)
3635 await expect ( page . getByText ( / S e a r c h r e t u r n e d 3 s e q u e n c e / ) ) . toBeVisible ( ) ;
3736
38- // Now also search using contributor field (matches authorAffiliations 'Patho Institute, Paris')
3937 const contributorField = page . getByRole ( 'textbox' , { name : 'Contributor' , exact : true } ) ;
4038 await contributorField . fill ( 'Paris' ) ;
4139 await contributorField . press ( 'Enter' ) ;
42- await page . waitForTimeout ( 500 ) ;
40+ await page . waitForFunction (
41+ ( ) => new URL ( window . location . href ) . searchParams . get ( 'contributor' ) === 'Paris' ,
42+ ) ;
4343
44- // Verify URL contains both parameters
4544 urlParams = new URL ( page . url ( ) ) . searchParams ;
4645 expect ( urlParams . get ( 'identifier' ) ) . toBe ( 'foobar-readonly' ) ;
4746 expect ( urlParams . get ( 'contributor' ) ) . toBe ( 'Paris' ) ;
48-
49- // Should now show only 1 sequence (the one from Paris)
5047 await expect ( page . getByText ( / S e a r c h r e t u r n e d 1 s e q u e n c e / ) ) . toBeVisible ( ) ;
5148
52- // Verify the active filter chips are displayed
5349 await expect ( page . getByText ( / I d e n t i f i e r : \s * f o o b a r - r e a d o n l y / ) ) . toBeVisible ( ) ;
5450 await expect ( page . getByText ( / C o n t r i b u t o r : \s * P a r i s / ) ) . toBeVisible ( ) ;
5551
56- // Test the download functionality with the filtered results
5752 await page . getByRole ( 'button' , { name : 'Download all entries' } ) . click ( ) ;
5853 await page . getByLabel ( 'I agree to the data use terms.' ) . check ( ) ;
5954
@@ -64,10 +59,11 @@ test.describe('Multi-field search', () => {
6459 const downloadPath = await download . path ( ) ;
6560 expect ( downloadPath ) . toBeTruthy ( ) ;
6661
67- // Verify downloaded file contains exactly 1 sequence (header + 1 data row)
6862 const fileContent = fs . readFileSync ( downloadPath , 'utf8' ) ;
6963 const lines = fileContent . split ( '\n' ) . filter ( ( line ) => line . trim ( ) !== '' ) ;
70- expect ( lines ) . toHaveLength ( 2 ) ; // header + 1 data row
64+ expect ( lines . length ) . toBeGreaterThanOrEqual ( 2 ) ;
65+ expect ( lines . length ) . toBeLessThanOrEqual ( 2 ) ;
66+ expect ( fileContent ) . toContain ( 'Paris' ) ;
7167 } ) ;
7268
7369 test ( 'identifier filter can be removed by clicking the X' , async ( { page } ) => {
@@ -76,18 +72,18 @@ test.describe('Multi-field search', () => {
7672 const identifierField = page . getByRole ( 'textbox' , { name : 'Identifier' , exact : true } ) ;
7773 await identifierField . fill ( 'foobar' ) ;
7874 await identifierField . press ( 'Enter' ) ;
79- await page . waitForTimeout ( 500 ) ;
75+ await page . waitForFunction (
76+ ( ) => new URL ( window . location . href ) . searchParams . get ( 'identifier' ) === 'foobar' ,
77+ ) ;
8078
8179 await expect ( page . getByText ( / I d e n t i f i e r : \s * f o o b a r / ) ) . toBeVisible ( ) ;
8280
83- // Remove the filter by clicking the X
8481 const filterChip = page . locator ( 'text=/Identifier:\\s*foobar/' ) . locator ( '..' ) ;
8582 await filterChip . getByRole ( 'button' ) . click ( ) ;
8683
8784 await expect ( page . getByText ( / I d e n t i f i e r : \s * f o o b a r / ) ) . toBeHidden ( ) ;
8885 await expect ( identifierField ) . toHaveValue ( '' ) ;
8986
90- // Verify the URL no longer contains the identifier param
9187 const urlParams = new URL ( page . url ( ) ) . searchParams ;
9288 expect ( urlParams . has ( 'identifier' ) ) . toBe ( false ) ;
9389 } ) ;
@@ -98,18 +94,18 @@ test.describe('Multi-field search', () => {
9894 const contributorField = page . getByRole ( 'textbox' , { name : 'Contributor' , exact : true } ) ;
9995 await contributorField . fill ( 'Institute' ) ;
10096 await contributorField . press ( 'Enter' ) ;
101- await page . waitForTimeout ( 500 ) ;
97+ await page . waitForFunction (
98+ ( ) => new URL ( window . location . href ) . searchParams . get ( 'contributor' ) === 'Institute' ,
99+ ) ;
102100
103101 await expect ( page . getByText ( / C o n t r i b u t o r : \s * I n s t i t u t e / ) ) . toBeVisible ( ) ;
104102
105- // Remove the filter by clicking the X
106103 const filterChip = page . locator ( 'text=/Contributor:\\s*Institute/' ) . locator ( '..' ) ;
107104 await filterChip . getByRole ( 'button' ) . click ( ) ;
108105
109106 await expect ( page . getByText ( / C o n t r i b u t o r : \s * I n s t i t u t e / ) ) . toBeHidden ( ) ;
110107 await expect ( contributorField ) . toHaveValue ( '' ) ;
111108
112- // Verify the URL no longer contains the contributor param
113109 const urlParams = new URL ( page . url ( ) ) . searchParams ;
114110 expect ( urlParams . has ( 'contributor' ) ) . toBe ( false ) ;
115111 } ) ;
0 commit comments