Skip to content

Commit affc28b

Browse files
committed
improve test
1 parent 8fed763 commit affc28b

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

integration-tests/tests/specs/features/search/multi-field-search.dependent.spec.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/Search returned 3 sequence/)).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(/Search returned 1 sequence/)).toBeVisible();
5148

52-
// Verify the active filter chips are displayed
5349
await expect(page.getByText(/Identifier:\s*foobar-readonly/)).toBeVisible();
5450
await expect(page.getByText(/Contributor:\s*Paris/)).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(/Identifier:\s*foobar/)).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(/Identifier:\s*foobar/)).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(/Contributor:\s*Institute/)).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(/Contributor:\s*Institute/)).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

Comments
 (0)