Skip to content
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

feat(quantic): added E2E and unit tests for insight notify trigger in quantic #4528

Merged
merged 15 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
94 changes: 42 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,41 +1,59 @@
import {configure} from '../../../page-objects/configurator';
SimonMilord marked this conversation as resolved.
Show resolved Hide resolved
import {performSearch} from '../../../page-objects/actions/action-perform-search';
import {
getQueryAlias,
interceptSearch,
mockSearchWithNotifyTrigger,
} from '../../../page-objects/search';
import {NotificationsExpectations as Expect} from './notifications-expectations';

import {
useCaseParamTest,
useCaseEnum,
InsightInterfaceExpectations as InsightInterfaceExpect,
} from '../../../page-objects/use-case';
const exampleNotifications = ['Notification one', 'Notification two'];

interface NotificationsOptions {
useCase: string;
}

describe('quantic-notifications', () => {
const pageUrl = 's/quantic-notifications';

function visitNotifications() {
function visitNotifications(options: Partial<NotificationsOptions>) {
interceptSearch();
cy.visit(pageUrl);
configure();
configure(options);
if (options.useCase === useCaseEnum.insight) {
InsightInterfaceExpect.isInitialized();
performSearch();
}
}

describe('when no notification is fired by the pipeline trigger', () => {
it('should not render any notification', () => {
visitNotifications();
useCaseParamTest.forEach((param) => {
describe(param.label, () => {
describe('when no notification is fired by the pipeline trigger', () => {
it('should not render any notification', () => {
visitNotifications({useCase: param.useCase});
mockSearchWithNotifyTrigger(param.useCase, []);

cy.wait(getQueryAlias());
Expect.displayNotifications(false);
});
});
cy.wait(getQueryAlias(param.useCase));
Expect.displayNotifications(false);
});
});

describe('when some notifications are fired by the pipeline trigger', () => {
it('should render the notifications', () => {
visitNotifications();
mockSearchWithNotifyTrigger('search', exampleNotifications);
describe('when some notifications are fired by the pipeline trigger', () => {
it('should render the notifications', () => {
mockSearchWithNotifyTrigger(param.useCase, exampleNotifications);
visitNotifications({useCase: param.useCase});

cy.wait(getQueryAlias());
Expect.displayNotifications(true);
Expect.logQueryPipelineTriggersNotification(exampleNotifications);
exampleNotifications.forEach((notification, index) => {
Expect.notificationContains(index, notification);
cy.wait(getQueryAlias(param.useCase));
Expect.displayNotifications(true);
Expect.logQueryPipelineTriggersNotification(exampleNotifications);
exampleNotifications.forEach((notification, index) => {
Expect.notificationContains(index, notification);
});
});
});
});
});
Expand Down
9 changes: 7 additions & 2 deletions packages/quantic/cypress/page-objects/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,15 +645,20 @@ export function mockSearchWithNotifyTrigger(
useCase: string,
notifications: string[]
) {
const InterceptAliasesToUse =
useCase === useCaseEnum.insight
? InterceptAliases.Insight
: InterceptAliases.Search;

cy.intercept(getRoute(useCase), (req) => {
req.continue((res) => {
res.body.triggers = notifications.map((notification) => ({
res.body.triggers = notifications?.map((notification) => ({
type: 'notify',
content: notification,
}));
res.send();
});
}).as(InterceptAliases.Search.substring(1));
}).as(InterceptAliasesToUse.substring(1));
}

export function mockQuerySuggestions(suggestions: string[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

<div slot="configuration">
<c-configurator options={options} ontryitnow={handleTryItNow}>
<c-action-perform-search slot="actions" disabled={notConfigured} engine-id={engineId} with-input></c-action-perform-search>
</c-configurator>
</div>

<c-quantic-search-interface slot="preview" engine-id={engineId}>
<c-example-use-case slot="preview" use-case={config.useCase} engine-id={engineId}>
<c-quantic-notifications engine-id={engineId}></c-quantic-notifications>
</c-quantic-search-interface>
</c-example-use-case>
</c-example-layout>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ export default class ExampleQuanticNotifications extends LightningElement {
pageTitle = 'Quantic Notifications';
pageDescription =
'component is responsible for displaying notifications generated by the Coveo Search API.';
options = [];
options = [
{
attribute: 'useCase',
label: 'Use Case',
description:
'Define which use case to test. Possible values are: search, insights',
defaultValue: 'search',
},
];

get notConfigured() {
return !this.isConfigured;
Expand Down
Loading
Loading