Skip to content

test(quantic): document suggestion e2e #5176

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 6 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {DocumentSuggestionObject} from './pageObject';
import {quanticBase} from '../../../../../../playwright/fixtures/baseFixture';
import {SearchObject} from '../../../../../../playwright/page-object/searchObject';
import {CaseAssistObject} from '../../../../../../playwright/page-object/caseAssistObject';

const pageUrl = 's/quantic-document-suggestion';

interface DocumentSuggestionOptions {
engineId: string;
searchEngineId: string;
maxDocuments: number;
fetchOnInit: boolean;
withoutQuickview: boolean;
numberOfAutoOpenedDocuments: number;
}

type QuanticDocumentSuggestionE2EFixtures = {
documentSuggestion: DocumentSuggestionObject;
search: SearchObject;
caseAssist: CaseAssistObject;
options: Partial<DocumentSuggestionOptions>;
};

type QuanticDocumentSuggestionE2ESearchFixtures =
QuanticDocumentSuggestionE2EFixtures & {
urlHash: string;
};

export const test =
quanticBase.extend<QuanticDocumentSuggestionE2ESearchFixtures>({
options: {},
urlHash: '',
caseAssist: async ({page}, use) => {
await use(new CaseAssistObject(page));
},
documentSuggestion: async ({page, options, configuration}, use) => {
await page.goto(pageUrl);
await configuration.configure(options);
await use(new DocumentSuggestionObject(page));
},
});

export {expect} from '@playwright/test';
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {Locator, Page, Request} from '@playwright/test';

Check failure on line 1 in packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/pageObject.ts

View workflow job for this annotation

GitHub Actions / Check with linter

Locator not found in '@playwright/test'

Check failure on line 1 in packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/pageObject.ts

View workflow job for this annotation

GitHub Actions / Check with linter

Page not found in '@playwright/test'

Check failure on line 1 in packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/pageObject.ts

View workflow job for this annotation

GitHub Actions / Check with linter

Request not found in '@playwright/test'
import {
isCollectEvent,
isUaEventsEvent,
} from '../../../../../../playwright/utils/requests';

export class DocumentSuggestionObject {
private page: Page;

constructor(page: Page) {
this.page = page;
}

get documentSuggestion() {
return this.page.locator('c-quantic-document-suggestion');
}

get accordion() {
return this.page.locator('lightning-accordion');
}

get sections() {
return this.page.locator('lightning-accordion-section');
}

get noSuggestionsMessage() {
return this.page.getByText('No suggestions', {exact: true});
}

sectionContent(index: number): Locator {
return this.sections.nth(index).locator('div.slds-accordion__content');
}

sectionQuickviewButton(index: number): Locator {
return this.sections
.nth(index)
.locator('c-quantic-result-quickview')
.getByRole('button', {name: /Open.+for preview/});
}

sectionRatingButton(index: number): Locator {
return this.sections.nth(index).getByRole('button', {name: 'Send rating'});
}

async numberOfSuggestions(): Promise<number> {
return this.sections.count();
}

async clickSuggestion(index: number): Promise<void> {
await this.sections.nth(index).click();
}

async waitForSuggestionClickEvent(): Promise<Request> {
return this.page.waitForRequest((request) => {
if (isUaEventsEvent(request)) {
return true;
}
return false;
});
}

async waitForSuggestionCollectEvent(): Promise<Request> {
return this.page.waitForRequest((request) => {

Check failure on line 63 in packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/pageObject.ts

View workflow job for this annotation

GitHub Actions / Run Quantic E2E tests / Run Playwright e2e tests on Quantic

[LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion legacy analytics › should handle clicking on a document suggestion

1) [LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion legacy analytics › should handle clicking on a document suggestion Error: page.waitForRequest: Test timeout of 30000ms exceeded. at main/default/lwc/quanticDocumentSuggestion/e2e/pageObject.ts:63 61 | 62 | async waitForSuggestionCollectEvent(): Promise<Request> { > 63 | return this.page.waitForRequest((request) => { | ^ 64 | if (isCollectEvent(request)) { 65 | const event = request.postDataJSON?.(); 66 | return ( at DocumentSuggestionObject.waitForSuggestionCollectEvent (/home/runner/work/ui-kit/ui-kit/packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/pageObject.ts:63:22) at /home/runner/work/ui-kit/ui-kit/packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:74:30

Check failure on line 63 in packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/pageObject.ts

View workflow job for this annotation

GitHub Actions / Run Quantic E2E tests / Run Playwright e2e tests on Quantic

[LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion legacy analytics › should handle clicking on a document suggestion

1) [LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion legacy analytics › should handle clicking on a document suggestion Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: page.waitForRequest: Test timeout of 30000ms exceeded. at main/default/lwc/quanticDocumentSuggestion/e2e/pageObject.ts:63 61 | 62 | async waitForSuggestionCollectEvent(): Promise<Request> { > 63 | return this.page.waitForRequest((request) => { | ^ 64 | if (isCollectEvent(request)) { 65 | const event = request.postDataJSON?.(); 66 | return ( at DocumentSuggestionObject.waitForSuggestionCollectEvent (/home/runner/work/ui-kit/ui-kit/packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/pageObject.ts:63:22) at /home/runner/work/ui-kit/ui-kit/packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:74:30

Check failure on line 63 in packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/pageObject.ts

View workflow job for this annotation

GitHub Actions / Run Quantic E2E tests / Run Playwright e2e tests on Quantic

[LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion legacy analytics › should handle clicking on a document suggestion

1) [LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion legacy analytics › should handle clicking on a document suggestion Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: page.waitForRequest: Test timeout of 30000ms exceeded. at main/default/lwc/quanticDocumentSuggestion/e2e/pageObject.ts:63 61 | 62 | async waitForSuggestionCollectEvent(): Promise<Request> { > 63 | return this.page.waitForRequest((request) => { | ^ 64 | if (isCollectEvent(request)) { 65 | const event = request.postDataJSON?.(); 66 | return ( at DocumentSuggestionObject.waitForSuggestionCollectEvent (/home/runner/work/ui-kit/ui-kit/packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/pageObject.ts:63:22) at /home/runner/work/ui-kit/ui-kit/packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:74:30
if (isCollectEvent(request)) {
const event = request.postDataJSON?.();
return (
event?.svc_action === 'suggestion_click' && event?.ea === 'click'
);
}
return false;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/* eslint-disable no-await-in-loop */

Check failure on line 1 in packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts

View workflow job for this annotation

GitHub Actions / Run Quantic E2E tests / Run Playwright e2e tests on Quantic

[LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion legacy analytics › should handle clicking on a document suggestion

1) [LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion legacy analytics › should handle clicking on a document suggestion Test timeout of 30000ms exceeded.

Check failure on line 1 in packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts

View workflow job for this annotation

GitHub Actions / Run Quantic E2E tests / Run Playwright e2e tests on Quantic

[LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion legacy analytics › should handle clicking on a document suggestion

1) [LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion legacy analytics › should handle clicking on a document suggestion Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Test timeout of 30000ms exceeded.

Check failure on line 1 in packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts

View workflow job for this annotation

GitHub Actions / Run Quantic E2E tests / Run Playwright e2e tests on Quantic

[LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion legacy analytics › should handle clicking on a document suggestion

1) [LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion legacy analytics › should handle clicking on a document suggestion Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Test timeout of 30000ms exceeded.

Check failure on line 1 in packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts

View workflow job for this annotation

GitHub Actions / Run Quantic E2E tests / Run Playwright e2e tests on Quantic

[LWS-disabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion legacy analytics › should handle clicking on a document suggestion

3) [LWS-disabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion legacy analytics › should handle clicking on a document suggestion Test timeout of 30000ms exceeded.
import {test, expect} from './fixture';

const fakeTrackingId = 'tracking_id_123';

['legacy', 'next'].forEach((mode) => {
test.describe(`quantic document suggestion ${mode} analytics`, () => {
let analyticsMode = 'legacy';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to initialize with the value legacy ?

test.beforeEach(async ({documentSuggestion, page}) => {
analyticsMode = mode;
if (analyticsMode === 'next') {
await page.context().addCookies([
{
name: 'Coveo-Pendragon',
value: fakeTrackingId,
domain: '.my.site.com',
path: '/',
},
{
name: 'LSKey-c$Coveo-Pendragon',
value: fakeTrackingId,
domain: '.my.site.com',
path: '/',
},
]);
}

await expect(documentSuggestion.noSuggestionsMessage).toBeVisible();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this expectation in the beforeEach block?

});

test('should render the component and all parts', async ({
documentSuggestion,
caseAssist,
}) => {
await expect(documentSuggestion.accordion).not.toBeVisible();
await expect(documentSuggestion.noSuggestionsMessage).toBeVisible();

const responsePromise = caseAssist.waitForDocumentSuggestionResponse();
await caseAssist.fetchSuggestions();
const response = await responsePromise;
const responseBody = await response.json();

await expect(documentSuggestion.accordion).toBeVisible();
await expect(documentSuggestion.noSuggestionsMessage).not.toBeVisible();
await expect(documentSuggestion.sections).toHaveCount(3);

for (const [index, section] of (
await documentSuggestion.sections.all()
).entries()) {
await expect(section).toBeVisible();
await expect(section).toHaveText(
new RegExp(responseBody.documents[index].title)
);
}
});

test('should handle clicking on a document suggestion', async ({
page,
documentSuggestion,
caseAssist,
}) => {
const responsePromise = caseAssist.waitForDocumentSuggestionResponse();
await caseAssist.fetchSuggestions();
const response = await responsePromise;
const suggestions = await response.json();

// Hack(?) to have the request payload in the analytics request next.
await page.route('*analytics*', (route) => {
route.continue();
});

if (analyticsMode === 'legacy') {
const analyticsPromise =
documentSuggestion.waitForSuggestionCollectEvent();
await documentSuggestion.clickSuggestion(1);
const analyticsRequest = await analyticsPromise;
const payload = analyticsRequest.postDataJSON?.();

expect(payload).toBeDefined();
expect(payload.t).toBe('event');
expect(payload.ec).toBe('svc');
expect(payload.ea).toBe('click');
expect(payload.svc_action).toBe('suggestion_click');
expect(payload.svc_action_data.suggestionId).toBe(
suggestions.documents[1].uniqueId
);
expect(payload.svc_action_data.suggestion.documentPosition).toBe(2);
expect(payload.svc_action_data.suggestion.documentTitle).toBe(
suggestions.documents[1].title
);
} else {
const analyticsPromise =
documentSuggestion.waitForSuggestionClickEvent();
await documentSuggestion.clickSuggestion(1);
const analyticsRequest = await analyticsPromise;
const payload = analyticsRequest.postDataJSON?.();

expect(payload).toBeDefined();
expect(payload.length).toBe(1);
expect(payload[0].meta.config.trackingId).toBe(fakeTrackingId);
expect(payload[0].meta.type).toBe('caseAssist.documentSuggestionClick');

Check failure on line 101 in packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts

View workflow job for this annotation

GitHub Actions / Run Quantic E2E tests / Run Playwright e2e tests on Quantic

[LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion next analytics › should handle clicking on a document suggestion

2) [LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion next analytics › should handle clicking on a document suggestion Error: expect(received).toBe(expected) // Object.is equality Expected: "caseAssist.documentSuggestionClick" Received: "CaseAssist.DocumentSuggestionClick" 99 | expect(payload.length).toBe(1); 100 | expect(payload[0].meta.config.trackingId).toBe(fakeTrackingId); > 101 | expect(payload[0].meta.type).toBe('caseAssist.documentSuggestionClick'); | ^ 102 | expect(payload[0].documentSuggestion.responseId).toBeDefined(); 103 | expect(payload[0].documentSuggestion.id).toBe( 104 | suggestions.documents[1].uniqueId at /home/runner/work/ui-kit/ui-kit/packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:101:38

Check failure on line 101 in packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts

View workflow job for this annotation

GitHub Actions / Run Quantic E2E tests / Run Playwright e2e tests on Quantic

[LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion next analytics › should handle clicking on a document suggestion

2) [LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion next analytics › should handle clicking on a document suggestion Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBe(expected) // Object.is equality Expected: "caseAssist.documentSuggestionClick" Received: "CaseAssist.DocumentSuggestionClick" 99 | expect(payload.length).toBe(1); 100 | expect(payload[0].meta.config.trackingId).toBe(fakeTrackingId); > 101 | expect(payload[0].meta.type).toBe('caseAssist.documentSuggestionClick'); | ^ 102 | expect(payload[0].documentSuggestion.responseId).toBeDefined(); 103 | expect(payload[0].documentSuggestion.id).toBe( 104 | suggestions.documents[1].uniqueId at /home/runner/work/ui-kit/ui-kit/packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:101:38

Check failure on line 101 in packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts

View workflow job for this annotation

GitHub Actions / Run Quantic E2E tests / Run Playwright e2e tests on Quantic

[LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion next analytics › should handle clicking on a document suggestion

2) [LWS-enabled] › force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:57:9 › quantic document suggestion next analytics › should handle clicking on a document suggestion Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toBe(expected) // Object.is equality Expected: "caseAssist.documentSuggestionClick" Received: "CaseAssist.DocumentSuggestionClick" 99 | expect(payload.length).toBe(1); 100 | expect(payload[0].meta.config.trackingId).toBe(fakeTrackingId); > 101 | expect(payload[0].meta.type).toBe('caseAssist.documentSuggestionClick'); | ^ 102 | expect(payload[0].documentSuggestion.responseId).toBeDefined(); 103 | expect(payload[0].documentSuggestion.id).toBe( 104 | suggestions.documents[1].uniqueId at /home/runner/work/ui-kit/ui-kit/packages/quantic/force-app/main/default/lwc/quanticDocumentSuggestion/e2e/quanticDocumentSuggestion.e2e.ts:101:38
expect(payload[0].documentSuggestion.responseId).toBeDefined();
expect(payload[0].documentSuggestion.id).toBe(
suggestions.documents[1].uniqueId
);
}
});

test.describe('when numberOfAutoOpenedDocuments is set to the same as maxDocument', () => {
test.use({
options: {
maxDocuments: 6,
numberOfAutoOpenedDocuments: 6,
},
});

test('should open all documents', async ({
documentSuggestion,
caseAssist,
}) => {
await caseAssist.fetchSuggestions();
await expect(documentSuggestion.accordion).toBeVisible();
const sections = await documentSuggestion.sections.count();
for (let index = 0; index < sections; index++) {
await expect(documentSuggestion.sectionContent(index)).toBeVisible();
}
});
});
});
});
8 changes: 8 additions & 0 deletions packages/quantic/playwright/page-object/caseAssistObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export class CaseAssistObject {
this.page = page;
}

get fetchSuggestionsButton(): Locator {
return this.page.getByRole('button', {name: 'Fetch suggestions'});
}

get fetchClassificationsButton(): Locator {
return this.page.locator('c-action-fetch-classifications button');
}
Expand All @@ -17,6 +21,10 @@ export class CaseAssistObject {
await this.fetchClassificationsButton.click();
}

async fetchSuggestions(): Promise<void> {
await this.fetchSuggestionsButton.click();
}

async waitForCaseClassificationsResponse(): Promise<Response> {
return this.page.waitForResponse(classifyRequestRegex);
}
Expand Down
11 changes: 11 additions & 0 deletions packages/quantic/playwright/utils/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const analyticsSearchesUrlRegex =
export const analyticsCustomUrlRegex = /\/rest\/v15\/analytics\/custom/;
export const analyticsClickUrlRegex = /\/rest(\/ua)?\/v15\/analytics\/click/;
export const analyticsCollectUrlRegex = /\/rest\/v15\/analytics\/collect/;
export const analyticsEventsUrlRegex = /\/rest\/organizations\/.+?\/events\/v1/;
export const searchQuickviewRequestRegex = /\/rest\/search\/v2\/html.*/;
export const insightQuickviewRequestRegex =
/\/rest\/organizations\/.*\/insight\/v1\/configs\/.*\/quickview/;
Expand Down Expand Up @@ -57,3 +58,13 @@ export function isCollectEvent(request: Request): boolean {
request.method() === 'POST' && analyticsCollectUrlRegex.test(request.url())
);
}

/**
* Indicates whether the specified request corresponds to a Events request.
* @param request The request to check.
*/
export function isUaEventsEvent(request: Request): boolean {
return (
request.method() === 'POST' && analyticsEventsUrlRegex.test(request.url())
);
}
Loading