Skip to content

Commit 8bcbc70

Browse files
committed
Coveo: Added tests to feature
1 parent 7421ca6 commit 8bcbc70

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

assets/js/coveo.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ async function atomicCoveo() {
101101
} catch (error) {
102102
// Handle coveo error from only a LACK of credentials.
103103
// INCORRECT credentials will cause the page to load but spin waiting.
104-
const coveoErrorContainer = document.getElementById(
105-
'coveo-error-container'
106-
);
104+
const coveoErrorContainer = document.getElementById('coveo-error-content');
107105
coveoErrorContainer.style.display = 'block';
108106
}
109107
}

layouts/partials/search-error.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{- $isCoveoDefined := . -}}
22

3-
<div class="content" data-testid="content" id="coveo-error-container" style="{{- if $isCoveoDefined -}}display: none;{{- else -}}{{- end -}}">
3+
<div class="content" data-testid="coveo-error-content" id="coveo-error-content" style="{{- if $isCoveoDefined -}}display: none;{{- else -}}{{- end -}}">
44
<div class="not-found-container" data-testid="not-found-container">
55
<h1 class="info-header">
66
Search functionality is unavailable.

tests/src/constants/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export const TIMEOUT = 4000;
2+
export const COVEO_CREDENTIALS_BASE_URL = 'https://docs-dev.nginx.com';
3+
export const COVEO_CREDENTIALS_ENDPOINT = 'api/v1/auth/search_token';

tests/src/coveo.spec.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect, test } from '@playwright/test';
2+
import { COVEO_CREDENTIALS_ENDPOINT } from './constants';
23
import { mockCoveoCredentials, mockCoveoData } from './mock';
34
import {
45
buildURLFragment,
@@ -21,12 +22,17 @@ test.describe('Coveo test', () => {
2122
await page.goto('/');
2223
await page.waitForLoadState('load');
2324
await waitFor(async () => await handleConsentPopup(page));
24-
await mockCoveoCredentials(page, request);
25+
26+
const excludedTests = ['missing coveo credentials'];
27+
if (!excludedTests.includes(test.info().title)) {
28+
await mockCoveoCredentials(page, request);
29+
}
2530
});
2631

2732
test.afterEach(async ({ page }) => {
2833
// Run basic smoke tests on all valid queries
29-
if (!test.info().title.includes('invalid search query')) {
34+
const excludedTests = ['invalid search query', 'missing coveo credentials'];
35+
if (!excludedTests.includes(test.info().title)) {
3036
await runSmokeTestCoveo(page);
3137
}
3238
});
@@ -57,4 +63,18 @@ test.describe('Coveo test', () => {
5763
await page.reload();
5864
expect(page.url()).toContain(endpoint);
5965
});
66+
67+
test('missing coveo credentials', async ({ page }) => {
68+
const searchEndpoint = 'search.html';
69+
await page.goto(`/${searchEndpoint}`);
70+
await page.route(`**/${COVEO_CREDENTIALS_ENDPOINT}`, async (route) => {
71+
await route.fulfill({
72+
status: 404,
73+
contentType: 'text/html; charset=utf-8',
74+
});
75+
});
76+
77+
const coveoErrorContent = page.getByTestId('coveo-error-content');
78+
await expect(coveoErrorContent).toBeVisible();
79+
});
6080
});

tests/src/mock/coveo.mock.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { expect } from '@playwright/test';
2+
import {
3+
COVEO_CREDENTIALS_BASE_URL,
4+
COVEO_CREDENTIALS_ENDPOINT,
5+
} from '../constants';
26

37
export const mockCoveoData = {
48
validQuery: 'proxy',
@@ -8,24 +12,25 @@ export const mockCoveoData = {
812

913
export async function mockCoveoCredentials(page, request) {
1014
// Get credentials
11-
const tokenBaseURL = 'https://docs-dev.nginx.com';
12-
const tokenEndpoint = '/api/v1/auth/search_token';
1315
const username = process.env.FRONT_DOOR_USERNAME;
1416
const password = process.env.FRONT_DOOR_PASSWORD;
15-
const response = await request.get(tokenBaseURL + tokenEndpoint, {
16-
headers: {
17-
Authorization:
18-
'Basic ' + Buffer.from(`${username}:${password}`).toString('base64'),
19-
},
20-
});
17+
const response = await request.get(
18+
`${COVEO_CREDENTIALS_BASE_URL}/${COVEO_CREDENTIALS_ENDPOINT}`,
19+
{
20+
headers: {
21+
Authorization:
22+
'Basic ' + Buffer.from(`${username}:${password}`).toString('base64'),
23+
},
24+
}
25+
);
2126

2227
expect(response.ok()).toBeTruthy();
2328
expect(response.status()).toBe(200);
2429

2530
const credentials = await response.json();
2631

2732
// Mock the local request to be successful, then reload the page.
28-
await page.route(`**${tokenEndpoint}`, async (route) => {
33+
await page.route(`**/${COVEO_CREDENTIALS_ENDPOINT}`, async (route) => {
2934
await route.fulfill({
3035
status: 200,
3136
contentType: 'application/json',

0 commit comments

Comments
 (0)