generated from nginx/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 6
Add coveo e2e tests #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add coveo e2e tests #437
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9cc1a44
Tests: Add e2e tests for Coveo
lamATnginx 2d1a248
Tests: Refactor to make generic
lamATnginx f191ce0
Tests: Enable coveo automatically
lamATnginx f0be340
Tests: Mock coveo credentials
lamATnginx 97a8f2a
Tests: Refactored functions
lamATnginx eb41d6e
Tests: Refactored mocks to new mock folder
lamATnginx 4eefc26
Chore: Merge branch 'main' into feat/coveo-tests
lamATnginx 5406560
Tests: CLI updates + fixed export for coveo mock
lamATnginx 9919021
Tests: Added example env file
lamATnginx 987ee67
Tests: Refactored buildURLFragment
lamATnginx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| FRONT_DOOR_USERNAME= | ||
| FRONT_DOOR_PASSWORD= |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { mockCoveoCredentials, mockCoveoData } from './mock'; | ||
| import { | ||
| buildURLFragment, | ||
| handleConsentPopup, | ||
| runSmokeTestCoveo, | ||
| waitFor, | ||
| } from './utils'; | ||
|
|
||
| async function submitSearchQuery(page, query) { | ||
| const headerSearchBarContainer = page.getByTestId('header__search'); | ||
| const searchBar = headerSearchBarContainer.locator('[part="textarea"]'); | ||
| await searchBar.fill(query); | ||
| await page.keyboard.press('Enter'); | ||
| await page.waitForURL(`**/search.html#q=${query}`); | ||
| await page.waitForSelector('#search-v2'); | ||
| } | ||
|
|
||
| test.describe('Coveo test', () => { | ||
| test.beforeEach(async ({ page, request }) => { | ||
| await page.goto('/'); | ||
| await page.waitForLoadState('load'); | ||
| await waitFor(async () => await handleConsentPopup(page)); | ||
| await mockCoveoCredentials(page, request); | ||
| }); | ||
|
|
||
| test.afterEach(async ({ page }) => { | ||
| // Run basic smoke tests on all valid queries | ||
| if (!test.info().title.includes('invalid search query')) { | ||
| await runSmokeTestCoveo(page); | ||
| } | ||
| }); | ||
|
|
||
| test('valid search query', async ({ page }) => { | ||
| await submitSearchQuery(page, mockCoveoData.validQuery); | ||
| }); | ||
|
|
||
| test('invalid search query', async ({ page }) => { | ||
| await submitSearchQuery(page, mockCoveoData.invalidQuery); | ||
| const resultsPage = page.getByTestId('search-results-page'); | ||
| const main = resultsPage.locator('atomic-layout-section[section="main"]'); | ||
| const noResultsMessage = main.locator('[part="no-results"]'); | ||
| await expect(noResultsMessage).toBeVisible(); | ||
| }); | ||
|
|
||
| test('inbound link do not reset URL', async ({ page }) => { | ||
| // Use ONLY generic filters. Do not add any product specific filters, particularly from the facet. | ||
| // If these basic filters work, then its safe to assume, adding facet filters will not reset the URL. | ||
| const endpoint = `/search.html#q=${mockCoveoData.validQuery}${buildURLFragment(mockCoveoData.filters)}`; | ||
| await page.goto(endpoint); | ||
| await page.waitForSelector('#search-v2'); | ||
|
|
||
| // should retain the same link instead of resetting | ||
| expect(page.url()).toContain(endpoint); | ||
|
|
||
| // reloading should retain the same link instead of resetting | ||
| await page.reload(); | ||
| expect(page.url()).toContain(endpoint); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { expect } from '@playwright/test'; | ||
|
|
||
| export const mockCoveoData = { | ||
| validQuery: 'proxy', | ||
| invalidQuery: 'abcdefghijkl', | ||
| filters: ['numberOfResults=100', 'sortCriteria=date descending'], | ||
| }; | ||
|
|
||
| export async function mockCoveoCredentials(page, request) { | ||
| // Get credentials | ||
| const tokenBaseURL = 'https://docs-dev.nginx.com'; | ||
| const tokenEndpoint = '/api/v1/auth/search_token'; | ||
| const username = process.env.FRONT_DOOR_USERNAME; | ||
| const password = process.env.FRONT_DOOR_PASSWORD; | ||
| const response = await request.get(tokenBaseURL + tokenEndpoint, { | ||
| headers: { | ||
| Authorization: | ||
| 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64'), | ||
| }, | ||
| }); | ||
|
|
||
| expect(response.ok()).toBeTruthy(); | ||
| expect(response.status()).toBe(200); | ||
|
|
||
| const credentials = await response.json(); | ||
|
|
||
| // Mock the local request to be successful, then reload the page. | ||
| await page.route(`**${tokenEndpoint}`, async (route) => { | ||
| await route.fulfill({ | ||
| status: 200, | ||
| contentType: 'application/json', | ||
| body: JSON.stringify(credentials), | ||
| }); | ||
| }); | ||
| await page.reload(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './coveo.mock'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.