|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | +import { mockCoveoCredentials, mockCoveoData } from './mock'; |
| 3 | +import { |
| 4 | + buildURLFragment, |
| 5 | + handleConsentPopup, |
| 6 | + runSmokeTestCoveo, |
| 7 | + waitFor, |
| 8 | +} from './utils'; |
| 9 | + |
| 10 | +async function submitSearchQuery(page, query) { |
| 11 | + const headerSearchBarContainer = page.getByTestId('header__search'); |
| 12 | + const searchBar = headerSearchBarContainer.locator('[part="textarea"]'); |
| 13 | + await searchBar.fill(query); |
| 14 | + await page.keyboard.press('Enter'); |
| 15 | + await page.waitForURL(`**/search.html#q=${query}`); |
| 16 | + await page.waitForSelector('#search-v2'); |
| 17 | +} |
| 18 | + |
| 19 | +test.describe('Coveo test', () => { |
| 20 | + test.beforeEach(async ({ page, request }) => { |
| 21 | + await page.goto('/'); |
| 22 | + await page.waitForLoadState('load'); |
| 23 | + await waitFor(async () => await handleConsentPopup(page)); |
| 24 | + await mockCoveoCredentials(page, request); |
| 25 | + }); |
| 26 | + |
| 27 | + test.afterEach(async ({ page }) => { |
| 28 | + // Run basic smoke tests on all valid queries |
| 29 | + if (!test.info().title.includes('invalid search query')) { |
| 30 | + await runSmokeTestCoveo(page); |
| 31 | + } |
| 32 | + }); |
| 33 | + |
| 34 | + test('valid search query', async ({ page }) => { |
| 35 | + await submitSearchQuery(page, mockCoveoData.validQuery); |
| 36 | + }); |
| 37 | + |
| 38 | + test('invalid search query', async ({ page }) => { |
| 39 | + await submitSearchQuery(page, mockCoveoData.invalidQuery); |
| 40 | + const resultsPage = page.getByTestId('search-results-page'); |
| 41 | + const main = resultsPage.locator('atomic-layout-section[section="main"]'); |
| 42 | + const noResultsMessage = main.locator('[part="no-results"]'); |
| 43 | + await expect(noResultsMessage).toBeVisible(); |
| 44 | + }); |
| 45 | + |
| 46 | + test('inbound link do not reset URL', async ({ page }) => { |
| 47 | + // Use ONLY generic filters. Do not add any product specific filters, particularly from the facet. |
| 48 | + // If these basic filters work, then its safe to assume, adding facet filters will not reset the URL. |
| 49 | + const endpoint = `/search.html#q=${mockCoveoData.validQuery}${buildURLFragment(mockCoveoData.filters)}`; |
| 50 | + await page.goto(endpoint); |
| 51 | + await page.waitForSelector('#search-v2'); |
| 52 | + |
| 53 | + // should retain the same link instead of resetting |
| 54 | + expect(page.url()).toContain(endpoint); |
| 55 | + |
| 56 | + // reloading should retain the same link instead of resetting |
| 57 | + await page.reload(); |
| 58 | + expect(page.url()).toContain(endpoint); |
| 59 | + }); |
| 60 | +}); |
0 commit comments