@coveo/quantic 3.16.0 → 3.16.1-pre.1a6fc4649f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/out/quantic-docs.json +2 -2
- package/force-app/main/default/lwc/quanticNumberButton/quanticNumberButton.html +1 -1
- package/force-app/main/default/lwc/quanticResultsPerPage/quanticResultsPerPage.js +27 -17
- package/force-app/main/default/staticresources/coveoheadless/case-assist/headless.js +6 -6
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/recent-queries-list/headless-recent-queries-list.d.ts +5 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/core/search-parameter-manager/headless-core-search-parameter-manager.d.ts +0 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/recent-queries-list/headless-recent-queries-list.d.ts +5 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/parameter-manager/parameter-manager-selectors.d.ts +5 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/search-parameters/search-parameter-actions-loader.d.ts +36 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/search-parameters/search-parameter-actions.d.ts +6 -0
- package/force-app/main/default/staticresources/coveoheadless/headless.js +10 -10
- package/force-app/main/default/staticresources/coveoheadless/insight/headless.js +9 -9
- package/force-app/main/default/staticresources/coveoheadless/recommendation/headless.js +5 -5
- package/package.json +6 -4
- package/force-app/main/default/lwc/quanticBreadcrumbManager/__tests__/quanticBreadcrumbManager.test.js +0 -604
- package/force-app/main/default/lwc/quanticBreadcrumbManager/e2e/fixture.ts +0 -76
- package/force-app/main/default/lwc/quanticBreadcrumbManager/e2e/pageObject.ts +0 -282
- package/force-app/main/default/lwc/quanticBreadcrumbManager/e2e/quanticBreadcrumbManager.e2e.ts +0 -167
- package/force-app/main/default/lwc/quanticCarousel/__tests__/quanticCarousel.test.js +0 -262
- package/force-app/main/default/lwc/quanticCaseClassification/__tests__/quanticCaseClassification.test.js +0 -819
- package/force-app/main/default/lwc/quanticCaseClassification/e2e/data.ts +0 -23
- package/force-app/main/default/lwc/quanticCaseClassification/e2e/fixture.ts +0 -51
- package/force-app/main/default/lwc/quanticCaseClassification/e2e/pageObject.ts +0 -152
- package/force-app/main/default/lwc/quanticCaseClassification/e2e/quanticCaseClassification.e2e.ts +0 -269
- package/force-app/main/default/lwc/quanticCategoryFacet/__tests__/quanticCategoryFacet.test.js +0 -327
- package/force-app/main/default/lwc/quanticCitation/__tests__/quanticCitation.test.js +0 -269
- package/force-app/main/default/lwc/quanticColoredResultBadge/__tests__/quanticColoredResultBadge.test.js +0 -212
- package/force-app/main/default/lwc/quanticDateFacet/__tests__/quanticDateFacet.test.js +0 -321
- package/force-app/main/default/lwc/quanticDidYouMean/__tests__/quanticDidYouMean.test.js +0 -199
- package/force-app/main/default/lwc/quanticFacet/__tests__/quanticFacet.test.js +0 -341
- package/force-app/main/default/lwc/quanticFacetCaption/__tests__/quanticFacetCaption.test.js +0 -28
- package/force-app/main/default/lwc/quanticFacetManager/__tests__/quanticFacetManager.test.js +0 -178
- package/force-app/main/default/lwc/quanticFacetManager/e2e/fixture.ts +0 -63
- package/force-app/main/default/lwc/quanticFacetManager/e2e/pageObject.ts +0 -23
- package/force-app/main/default/lwc/quanticFacetManager/e2e/quanticFacetManager.e2e.ts +0 -82
- package/force-app/main/default/lwc/quanticFeedback/__tests__/quanticFeedback.test.js +0 -392
- package/force-app/main/default/lwc/quanticFeedbackModal/__tests__/quanticFeedbackModal.test.js +0 -448
- package/force-app/main/default/lwc/quanticFeedbackModalQna/__tests__/quanticFeedbackModalQna.test.js +0 -298
- package/force-app/main/default/lwc/quanticGeneratedAnswer/__tests__/quanticGeneratedAnswer.test.js +0 -814
- package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/data.ts +0 -56
- package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/fixture.ts +0 -87
- package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/pageObject.ts +0 -283
- package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/quanticGeneratedAnswer.e2e.ts +0 -199
- package/force-app/main/default/lwc/quanticGeneratedAnswerContent/__tests__/quanticGeneratedAnswerContent.test.js +0 -151
- package/force-app/main/default/lwc/quanticHeading/__tests__/quanticHeading.test.js +0 -71
- package/force-app/main/default/lwc/quanticHeadlessLoader/__tests__/quanticHeadlessLoader.test.js +0 -651
- package/force-app/main/default/lwc/quanticNotifications/__tests__/quanticNotifications.test.js +0 -335
- package/force-app/main/default/lwc/quanticNumericFacet/__tests__/quanticNumericFacet.test.js +0 -343
- package/force-app/main/default/lwc/quanticPager/e2e/fixture.ts +0 -63
- package/force-app/main/default/lwc/quanticPager/e2e/pageObject.ts +0 -69
- package/force-app/main/default/lwc/quanticPager/e2e/quanticPager.e2e.ts +0 -101
- package/force-app/main/default/lwc/quanticQuickviewContent/__tests__/data/defaultTestCase.json +0 -13
- package/force-app/main/default/lwc/quanticQuickviewContent/__tests__/data/youtubeTestCase.json +0 -14
- package/force-app/main/default/lwc/quanticQuickviewContent/__tests__/quanticQuickviewContent.test.js +0 -82
- package/force-app/main/default/lwc/quanticRadioButtonsGroup/__tests__/quanticRadioButtonsGroup.test.js +0 -273
- package/force-app/main/default/lwc/quanticRefineModalContent/__tests__/quanticRefineModalContent.test.js +0 -501
- package/force-app/main/default/lwc/quanticResultAction/__tests__/quanticResultAction.test.js +0 -262
- package/force-app/main/default/lwc/quanticResultActionBar/__tests__/quanticResultActionBar.test.js +0 -141
- package/force-app/main/default/lwc/quanticResultChildren/__tests__/quanticResultChildren.test.js +0 -340
- package/force-app/main/default/lwc/quanticResultDate/__tests__/quanticResultDate.test.js +0 -144
- package/force-app/main/default/lwc/quanticResultField/__tests__/quanticResultField.test.js +0 -120
- package/force-app/main/default/lwc/quanticResultHighlightedTextField/__tests__/quanticResultHighlightedTextField.test.js +0 -209
- package/force-app/main/default/lwc/quanticResultLink/__tests__/quanticResultLink.test.js +0 -261
- package/force-app/main/default/lwc/quanticResultMultiValueText/__tests__/quanticResultMultiValueText.test.js +0 -235
- package/force-app/main/default/lwc/quanticResultNumber/__tests__/quanticResultNumber.test.js +0 -144
- package/force-app/main/default/lwc/quanticResultPrintableUri/__tests__/quanticResultPrintableUri.test.js +0 -324
- package/force-app/main/default/lwc/quanticResultQuickview/__tests__/quanticResultQuickview.test.js +0 -171
- package/force-app/main/default/lwc/quanticResultText/__tests__/quanticResultText.test.js +0 -155
- package/force-app/main/default/lwc/quanticResultsPerPage/__tests__/quanticResultsPerPage.test.js +0 -404
- package/force-app/main/default/lwc/quanticResultsPerPage/e2e/fixture.ts +0 -74
- package/force-app/main/default/lwc/quanticResultsPerPage/e2e/pageObject.ts +0 -85
- package/force-app/main/default/lwc/quanticResultsPerPage/e2e/quanticResultsPerPage.e2e.ts +0 -97
- package/force-app/main/default/lwc/quanticSearchBox/__tests__/quanticSearchBox.test.js +0 -168
- package/force-app/main/default/lwc/quanticSearchBoxInput/__tests__/quanticSearchBoxInput.test.js +0 -823
- package/force-app/main/default/lwc/quanticSmartSnippet/__tests__/quanticSmartSnippet.test.js +0 -341
- package/force-app/main/default/lwc/quanticSmartSnippet/e2e/data.ts +0 -21
- package/force-app/main/default/lwc/quanticSmartSnippet/e2e/fixture.ts +0 -91
- package/force-app/main/default/lwc/quanticSmartSnippet/e2e/pageObject.ts +0 -196
- package/force-app/main/default/lwc/quanticSmartSnippet/e2e/quanticSmartSnippet.e2e.ts +0 -168
- package/force-app/main/default/lwc/quanticSmartSnippetAnswer/__tests__/quanticSmartSnippetAnswer.test.js +0 -126
- package/force-app/main/default/lwc/quanticSmartSnippetSource/__tests__/quanticSmartSnippetSource.test.js +0 -290
- package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/__tests__/quanticSmartSnippetSuggestions.test.js +0 -329
- package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/data.ts +0 -31
- package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/fixture.ts +0 -93
- package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/pageObject.ts +0 -160
- package/force-app/main/default/lwc/quanticSmartSnippetSuggestions/e2e/quanticSmartSnippetSuggestions.e2e.ts +0 -127
- package/force-app/main/default/lwc/quanticSort/__tests__/quanticSort.test.js +0 -416
- package/force-app/main/default/lwc/quanticSort/e2e/fixture.ts +0 -61
- package/force-app/main/default/lwc/quanticSort/e2e/pageObject.ts +0 -89
- package/force-app/main/default/lwc/quanticSort/e2e/quanticSort.e2e.ts +0 -91
- package/force-app/main/default/lwc/quanticSourceCitations/__tests__/quanticSourceCitations.test.js +0 -123
- package/force-app/main/default/lwc/quanticStandaloneSearchBox/__tests__/quanticStandaloneSearchBox.test.js +0 -186
- package/force-app/main/default/lwc/quanticStatefulButton/__tests__/quanticStatefulButton.test.js +0 -222
- package/force-app/main/default/lwc/quanticTab/__tests__/quanticTab.test.js +0 -287
- package/force-app/main/default/lwc/quanticTab/e2e/fixture.ts +0 -62
- package/force-app/main/default/lwc/quanticTab/e2e/pageObject.ts +0 -67
- package/force-app/main/default/lwc/quanticTab/e2e/quanticTab.e2e.ts +0 -77
- package/force-app/main/default/lwc/quanticTabBar/__tests__/quanticTabBar.test.js +0 -331
- package/force-app/main/default/lwc/quanticTabBar/e2e/fixture.ts +0 -61
- package/force-app/main/default/lwc/quanticTabBar/e2e/pageObject.ts +0 -80
- package/force-app/main/default/lwc/quanticTabBar/e2e/quanticTabBar.e2e.ts +0 -173
- package/force-app/main/default/lwc/quanticTimeframeFacet/__tests__/quanticTimeframeFacet.test.js +0 -339
- package/force-app/main/default/lwc/quanticTooltip/__tests__/quanticTooltip.test.js +0 -107
- package/force-app/main/default/lwc/quanticUserAction/__tests__/quanticUserAction.test.js +0 -427
- package/force-app/main/default/lwc/quanticUserActionsSession/__tests__/quanticUserActionsSession.test.js +0 -269
- package/force-app/main/default/lwc/quanticUserActionsTimeline/__tests__/data/userActionsState.json +0 -89
- package/force-app/main/default/lwc/quanticUserActionsTimeline/__tests__/quanticUserActionsTimeline.test.js +0 -511
- package/force-app/main/default/lwc/quanticUserActionsToggle/__tests__/quanticUserActionsToggle.test.js +0 -229
- package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/data.ts +0 -32
- package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/fixture.ts +0 -32
- package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/pageObject.ts +0 -71
- package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/quanticUserActionsToggle.e2e.ts +0 -39
- package/force-app/main/default/lwc/quanticUtils/__tests__/facetDependenciesUtils.test.js +0 -92
- package/force-app/main/default/lwc/quanticUtils/__tests__/markdownUtils.test.js +0 -71
- package/force-app/main/default/lwc/quanticUtils/__tests__/quanticUtils.test.js +0 -223
- package/force-app/main/default/lwc/quanticViewedByCustomerBadge/__tests__/quanticViewedByCustomerBadge.test.js +0 -131
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import {testSearch, testInsight, expect} from './fixture';
|
|
2
|
-
import {
|
|
3
|
-
useCaseEnum,
|
|
4
|
-
useCaseTestCases,
|
|
5
|
-
} from '../../../../../../playwright/utils/useCase';
|
|
6
|
-
|
|
7
|
-
const fixtures = {
|
|
8
|
-
search: testSearch as typeof testSearch,
|
|
9
|
-
insight: testInsight as typeof testInsight,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
useCaseTestCases.forEach((useCase) => {
|
|
13
|
-
let test;
|
|
14
|
-
let sortArrOptions;
|
|
15
|
-
let sortLabelWithValue;
|
|
16
|
-
if (useCase.value === useCaseEnum.search) {
|
|
17
|
-
test = fixtures[useCase.value] as typeof testSearch;
|
|
18
|
-
} else {
|
|
19
|
-
test = fixtures[useCase.value] as typeof testInsight;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
test.describe(`quantic sort ${useCase.label}`, () => {
|
|
23
|
-
test.beforeEach(async ({sort}) => {
|
|
24
|
-
await sort.clickSortDropDown();
|
|
25
|
-
sortArrOptions = await sort.allSortLabelOptions();
|
|
26
|
-
sortLabelWithValue = await sort.getSortLabelValue();
|
|
27
|
-
await sort.clickSortDropDown();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test.describe(`when changing sort option to 2nd position`, () => {
|
|
31
|
-
test('should trigger a new search and log analytics', async ({
|
|
32
|
-
sort,
|
|
33
|
-
search,
|
|
34
|
-
}) => {
|
|
35
|
-
const {label: expectedSortName, value: expectedSortValue} =
|
|
36
|
-
sortLabelWithValue[1]; // Assuming 0 is the first sort option, 1 should be the 2nd one after that.
|
|
37
|
-
|
|
38
|
-
const searchResponsePromise = search.waitForSearchResponse();
|
|
39
|
-
await sort.clickSortDropDown();
|
|
40
|
-
await sort.clickSortButton(expectedSortName);
|
|
41
|
-
|
|
42
|
-
const searchResponse = await searchResponsePromise;
|
|
43
|
-
const {sortCriteria} = searchResponse.request().postDataJSON();
|
|
44
|
-
expect(sortCriteria).toBe(expectedSortValue);
|
|
45
|
-
await sort.waitForSortUaAnalytics(expectedSortValue);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test.describe('when testing accessibility', () => {
|
|
50
|
-
test('should be accessible to keyboard', async ({sort, page}) => {
|
|
51
|
-
let selectedSortLabel = await sort.sortDropDown.textContent();
|
|
52
|
-
expect(selectedSortLabel).toEqual(sortArrOptions[0]);
|
|
53
|
-
|
|
54
|
-
// Selecting the next sort using Enter to open dropdown, the ArrowDown, then ENTER key
|
|
55
|
-
await sort.focusSortDropDown();
|
|
56
|
-
await sort.openSortDropdownUsingKeyboardEnter();
|
|
57
|
-
await page.keyboard.press('ArrowDown');
|
|
58
|
-
await page.keyboard.press('Enter');
|
|
59
|
-
selectedSortLabel = await sort.sortDropDown.textContent();
|
|
60
|
-
expect(selectedSortLabel).toEqual(sortArrOptions[1]);
|
|
61
|
-
|
|
62
|
-
// Selecting the next sort using Space to open dropdown, the ArrowDown, then ENTER key
|
|
63
|
-
await sort.focusSortDropDown();
|
|
64
|
-
await sort.openSortDropdownUsingKeyboardEnter(false);
|
|
65
|
-
await page.keyboard.press('ArrowDown');
|
|
66
|
-
await page.keyboard.press('Enter');
|
|
67
|
-
selectedSortLabel = await sort.sortDropDown.textContent();
|
|
68
|
-
expect(selectedSortLabel).toEqual(sortArrOptions[2]);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
if (useCase.value === 'search') {
|
|
73
|
-
test.describe('when loading options from the url', () => {
|
|
74
|
-
test('should reflect the options of url in the component', async ({
|
|
75
|
-
sort,
|
|
76
|
-
page,
|
|
77
|
-
}) => {
|
|
78
|
-
const {label: expectedSortName, value: expectedSortValue} =
|
|
79
|
-
sortLabelWithValue[2]; // Assuming 0 is the first sort option
|
|
80
|
-
|
|
81
|
-
const currentUrl = await page.url();
|
|
82
|
-
const urlHash = `#sortCriteria=${encodeURI(expectedSortValue)}`;
|
|
83
|
-
|
|
84
|
-
await page.goto(`${currentUrl}/${urlHash}`);
|
|
85
|
-
await page.getByRole('button', {name: 'Try it now'}).click();
|
|
86
|
-
await expect(sort.sortDropDown).toContainText(expectedSortName);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
});
|
package/force-app/main/default/lwc/quanticSourceCitations/__tests__/quanticSourceCitations.test.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-import-assign */
|
|
2
|
-
import * as mockHeadlessLoader from 'c/quanticHeadlessLoader';
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import {createElement} from 'lwc';
|
|
5
|
-
import QuanticSourceCitations from '../quanticSourceCitations';
|
|
6
|
-
|
|
7
|
-
jest.mock('c/quanticHeadlessLoader');
|
|
8
|
-
|
|
9
|
-
let isInitialized = false;
|
|
10
|
-
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
mockHeadlessLoader.initializeWithHeadless = (element, engineId, initialize) => {
|
|
13
|
-
if (element instanceof QuanticSourceCitations) {
|
|
14
|
-
if (!isInitialized) {
|
|
15
|
-
isInitialized = true;
|
|
16
|
-
initialize();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
mockHeadlessLoader.getHeadlessBundle = () => {
|
|
23
|
-
return {
|
|
24
|
-
buildInteractiveCitation: jest.fn((engine, {options}) => options.citation),
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const mockCitations = [
|
|
29
|
-
{
|
|
30
|
-
id: '1',
|
|
31
|
-
title: 'Example title 1',
|
|
32
|
-
uri: 'https://example.com/',
|
|
33
|
-
clickUri: 'https://example.com/',
|
|
34
|
-
permanentid: '1',
|
|
35
|
-
text: 'text 01',
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
id: '2',
|
|
39
|
-
title: 'Example title 2',
|
|
40
|
-
uri: 'https://example.com/',
|
|
41
|
-
clickUri: 'https://example.com/',
|
|
42
|
-
permanentid: '2',
|
|
43
|
-
text: 'text 02',
|
|
44
|
-
},
|
|
45
|
-
];
|
|
46
|
-
|
|
47
|
-
const defaultOptions = {
|
|
48
|
-
citations: mockCitations,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const selectors = {
|
|
52
|
-
citation: 'c-quantic-citation',
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
function createTestComponent(options = defaultOptions) {
|
|
56
|
-
const element = createElement('c-quantic-source-citations', {
|
|
57
|
-
is: QuanticSourceCitations,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
for (const [key, value] of Object.entries(options)) {
|
|
61
|
-
element[key] = value;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
document.body.appendChild(element);
|
|
65
|
-
return element;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Helper function to wait until the microtask queue is empty.
|
|
69
|
-
function flushPromises() {
|
|
70
|
-
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
describe('c-quantic-source-citations', () => {
|
|
74
|
-
function cleanup() {
|
|
75
|
-
// The jsdom instance is shared across test cases in a single file so reset the DOM
|
|
76
|
-
while (document.body.firstChild) {
|
|
77
|
-
document.body.removeChild(document.body.firstChild);
|
|
78
|
-
}
|
|
79
|
-
isInitialized = false;
|
|
80
|
-
jest.clearAllMocks();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
afterEach(() => {
|
|
84
|
-
cleanup();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('when there are citations found', () => {
|
|
88
|
-
it('should properly display the citations', async () => {
|
|
89
|
-
const element = createTestComponent();
|
|
90
|
-
await flushPromises();
|
|
91
|
-
|
|
92
|
-
const citations = element.shadowRoot.querySelectorAll(selectors.citation);
|
|
93
|
-
expect(citations).not.toBeNull();
|
|
94
|
-
expect(citations.length).toEqual(mockCitations.length);
|
|
95
|
-
|
|
96
|
-
citations.forEach((citationElement, index) => {
|
|
97
|
-
expect(citationElement.citation).toEqual({
|
|
98
|
-
...mockCitations[index],
|
|
99
|
-
index: index + 1,
|
|
100
|
-
});
|
|
101
|
-
expect(citationElement.interactiveCitation).toEqual(
|
|
102
|
-
mockCitations[index]
|
|
103
|
-
);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe('when there are no citations found', () => {
|
|
109
|
-
it('should not display citations', async () => {
|
|
110
|
-
const element = createTestComponent({
|
|
111
|
-
...defaultOptions,
|
|
112
|
-
citations: null,
|
|
113
|
-
});
|
|
114
|
-
await flushPromises();
|
|
115
|
-
|
|
116
|
-
const citations = element.shadowRoot.querySelector(
|
|
117
|
-
selectors.sourceCitation
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
expect(citations).toBeNull();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-import-assign */
|
|
2
|
-
import QuanticStandaloneSearchBox from 'c/quanticStandaloneSearchBox';
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import {createElement} from 'lwc';
|
|
5
|
-
import * as mockHeadlessLoader from 'c/quanticHeadlessLoader';
|
|
6
|
-
import {CurrentPageReference} from 'lightning/navigation';
|
|
7
|
-
import getHeadlessConfiguration from '@salesforce/apex/HeadlessController.getHeadlessConfiguration';
|
|
8
|
-
|
|
9
|
-
const nonStandaloneURL = 'https://www.example.com/global-search/%40uri';
|
|
10
|
-
const defaultHeadlessConfiguration = JSON.stringify({
|
|
11
|
-
organization: 'testOrgId',
|
|
12
|
-
accessToken: 'testAccessToken',
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
jest.mock('c/quanticHeadlessLoader');
|
|
16
|
-
|
|
17
|
-
jest.mock(
|
|
18
|
-
'@salesforce/apex/HeadlessController.getHeadlessConfiguration',
|
|
19
|
-
() => ({
|
|
20
|
-
default: jest.fn(),
|
|
21
|
-
}),
|
|
22
|
-
{virtual: true}
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
mockHeadlessLoader.loadDependencies = () =>
|
|
26
|
-
new Promise((resolve) => {
|
|
27
|
-
resolve();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
let isInitialized = false;
|
|
31
|
-
|
|
32
|
-
const exampleEngine = {
|
|
33
|
-
id: 'engineId',
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const functionsMocks = {
|
|
37
|
-
buildStandaloneSearchBox: jest.fn(() => ({
|
|
38
|
-
state: {},
|
|
39
|
-
subscribe: functionsMocks.subscribe,
|
|
40
|
-
})),
|
|
41
|
-
subscribe: jest.fn((cb) => {
|
|
42
|
-
cb();
|
|
43
|
-
return functionsMocks.unsubscribe;
|
|
44
|
-
}),
|
|
45
|
-
unsubscribe: jest.fn(() => {}),
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const defaultOptions = {
|
|
49
|
-
engineId: exampleEngine.id,
|
|
50
|
-
placeholder: null,
|
|
51
|
-
withoutSubmitButton: false,
|
|
52
|
-
numberOfSuggestions: 7,
|
|
53
|
-
textarea: false,
|
|
54
|
-
disableRecentQueries: false,
|
|
55
|
-
keepFiltersOnSearch: false,
|
|
56
|
-
redirectUrl: '/global-search/%40uri',
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
function createTestComponent(options = defaultOptions) {
|
|
60
|
-
prepareHeadlessState();
|
|
61
|
-
const element = createElement('c-quantic-standalone-search-box', {
|
|
62
|
-
is: QuanticStandaloneSearchBox,
|
|
63
|
-
});
|
|
64
|
-
for (const [key, value] of Object.entries(options)) {
|
|
65
|
-
element[key] = value;
|
|
66
|
-
}
|
|
67
|
-
document.body.appendChild(element);
|
|
68
|
-
return element;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function prepareHeadlessState() {
|
|
72
|
-
// @ts-ignore
|
|
73
|
-
global.CoveoHeadless = {
|
|
74
|
-
buildStandaloneSearchBox: functionsMocks.buildStandaloneSearchBox,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Helper function to wait until the microtask queue is empty.
|
|
79
|
-
function flushPromises() {
|
|
80
|
-
// eslint-disable-next-line @lwc/lwc/no-async-operation
|
|
81
|
-
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function mockSuccessfulHeadlessInitialization() {
|
|
85
|
-
// @ts-ignore
|
|
86
|
-
mockHeadlessLoader.initializeWithHeadless = (element, _, initialize) => {
|
|
87
|
-
if (element instanceof QuanticStandaloneSearchBox && !isInitialized) {
|
|
88
|
-
isInitialized = true;
|
|
89
|
-
initialize(exampleEngine);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function cleanup() {
|
|
95
|
-
// The jsdom instance is shared across test cases in a single file so reset the DOM
|
|
96
|
-
while (document.body.firstChild) {
|
|
97
|
-
document.body.removeChild(document.body.firstChild);
|
|
98
|
-
}
|
|
99
|
-
jest.clearAllMocks();
|
|
100
|
-
isInitialized = false;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
describe('c-quantic-standalone-search-box', () => {
|
|
104
|
-
beforeEach(() => {
|
|
105
|
-
getHeadlessConfiguration.mockResolvedValue(defaultHeadlessConfiguration);
|
|
106
|
-
mockSuccessfulHeadlessInitialization();
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
afterEach(() => {
|
|
110
|
-
cleanup();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe('controller initialization', () => {
|
|
114
|
-
it('should subscribe to the headless state changes', async () => {
|
|
115
|
-
createTestComponent();
|
|
116
|
-
await flushPromises();
|
|
117
|
-
|
|
118
|
-
expect(functionsMocks.subscribe).toHaveBeenCalledTimes(1);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('when the current page reference changes', () => {
|
|
122
|
-
beforeAll(() => {
|
|
123
|
-
// This is needed to mock the window.location.href property to test the keepFiltersOnSearch property in the quanticSearchBox.
|
|
124
|
-
// https://stackoverflow.com/questions/54021037/how-to-mock-window-location-href-with-jest-vuejs
|
|
125
|
-
Object.defineProperty(window, 'location', {
|
|
126
|
-
writable: true,
|
|
127
|
-
value: {href: nonStandaloneURL},
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should properly pass the keepFiltersOnSearch property to the quanticSearchBox', async () => {
|
|
132
|
-
const element = createTestComponent({
|
|
133
|
-
...defaultOptions,
|
|
134
|
-
keepFiltersOnSearch: false,
|
|
135
|
-
});
|
|
136
|
-
// eslint-disable-next-line @lwc/lwc/no-unexpected-wire-adapter-usages
|
|
137
|
-
CurrentPageReference.emit({url: nonStandaloneURL});
|
|
138
|
-
await flushPromises();
|
|
139
|
-
|
|
140
|
-
const searchBox = element.shadowRoot.querySelector(
|
|
141
|
-
'c-quantic-search-box'
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
expect(searchBox).not.toBeNull();
|
|
145
|
-
expect(searchBox.keepFiltersOnSearch).toEqual(false);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe('when keepFiltersOnSearch is false (default)', () => {
|
|
150
|
-
it('should properly initialize the controller with clear filters enabled', async () => {
|
|
151
|
-
createTestComponent();
|
|
152
|
-
await flushPromises();
|
|
153
|
-
|
|
154
|
-
expect(functionsMocks.buildStandaloneSearchBox).toHaveBeenCalledTimes(
|
|
155
|
-
1
|
|
156
|
-
);
|
|
157
|
-
expect(functionsMocks.buildStandaloneSearchBox).toHaveBeenCalledWith(
|
|
158
|
-
exampleEngine,
|
|
159
|
-
expect.objectContaining({
|
|
160
|
-
options: expect.objectContaining({clearFilters: true}),
|
|
161
|
-
})
|
|
162
|
-
);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
describe('when keepFiltersOnSearch is true', () => {
|
|
167
|
-
it('should properly initialize the controller with clear filters disabled', async () => {
|
|
168
|
-
createTestComponent({
|
|
169
|
-
...defaultOptions,
|
|
170
|
-
keepFiltersOnSearch: true,
|
|
171
|
-
});
|
|
172
|
-
await flushPromises();
|
|
173
|
-
|
|
174
|
-
expect(functionsMocks.buildStandaloneSearchBox).toHaveBeenCalledTimes(
|
|
175
|
-
1
|
|
176
|
-
);
|
|
177
|
-
expect(functionsMocks.buildStandaloneSearchBox).toHaveBeenCalledWith(
|
|
178
|
-
exampleEngine,
|
|
179
|
-
expect.objectContaining({
|
|
180
|
-
options: expect.objectContaining({clearFilters: false}),
|
|
181
|
-
})
|
|
182
|
-
);
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
});
|
package/force-app/main/default/lwc/quanticStatefulButton/__tests__/quanticStatefulButton.test.js
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
import {createElement} from 'lwc';
|
|
3
|
-
import QuanticStatefulButton from '../quanticStatefulButton';
|
|
4
|
-
|
|
5
|
-
const functionsMocks = {
|
|
6
|
-
exampleHandleSelect: jest.fn(),
|
|
7
|
-
exampleHandleDeselect: jest.fn(),
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const exampleLabel = 'Example label';
|
|
11
|
-
const exampleIcon = 'utility:clear';
|
|
12
|
-
const exampleTooltip = 'Example tooltip';
|
|
13
|
-
|
|
14
|
-
const selectors = {
|
|
15
|
-
statefulButton: '.stateful-button',
|
|
16
|
-
icon: '.stateful-button__container lightning-icon',
|
|
17
|
-
tooltip: '.stateful-button__container > c-quantic-tooltip',
|
|
18
|
-
tooltipContent:
|
|
19
|
-
'.stateful-button__container > c-quantic-tooltip > div[slot="content"]',
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
function setupEventListeners(element) {
|
|
23
|
-
element.addEventListener(
|
|
24
|
-
'quantic__select',
|
|
25
|
-
functionsMocks.exampleHandleSelect
|
|
26
|
-
);
|
|
27
|
-
element.addEventListener(
|
|
28
|
-
'quantic__deselect',
|
|
29
|
-
functionsMocks.exampleHandleDeselect
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const exampleOptions = {
|
|
34
|
-
label: exampleLabel,
|
|
35
|
-
iconName: exampleIcon,
|
|
36
|
-
tooltip: exampleTooltip,
|
|
37
|
-
selected: false,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
function createTestComponent(options = exampleOptions) {
|
|
41
|
-
const element = createElement('c-quantic-stateful-button', {
|
|
42
|
-
is: QuanticStatefulButton,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
for (const [key, value] of Object.entries(options)) {
|
|
46
|
-
element[key] = value;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
document.body.appendChild(element);
|
|
50
|
-
return element;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Helper function to wait until the microtask queue is empty.
|
|
54
|
-
function flushPromises() {
|
|
55
|
-
// eslint-disable-next-line @lwc/lwc/no-async-operation
|
|
56
|
-
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
describe('c-quantic-stateful-button', () => {
|
|
60
|
-
function cleanup() {
|
|
61
|
-
// The jsdom instance is shared across test cases in a single file so reset the DOM
|
|
62
|
-
while (document.body.firstChild) {
|
|
63
|
-
document.body.removeChild(document.body.firstChild);
|
|
64
|
-
}
|
|
65
|
-
jest.clearAllMocks();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
afterEach(() => {
|
|
69
|
-
cleanup();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('when the stateful button is in the selected state', () => {
|
|
73
|
-
it('should properly display the selected stateful button', async () => {
|
|
74
|
-
const element = createTestComponent({...exampleOptions, selected: true});
|
|
75
|
-
await flushPromises();
|
|
76
|
-
|
|
77
|
-
const button = element.shadowRoot.querySelector(selectors.statefulButton);
|
|
78
|
-
const icon = element.shadowRoot.querySelector(selectors.icon);
|
|
79
|
-
const tooltip = element.shadowRoot.querySelector(selectors.tooltip);
|
|
80
|
-
const tooltipContent = element.shadowRoot.querySelector(
|
|
81
|
-
selectors.tooltipContent
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
expect(button).not.toBeNull();
|
|
85
|
-
expect(icon).not.toBeNull();
|
|
86
|
-
expect(tooltip).not.toBeNull();
|
|
87
|
-
expect(tooltipContent).not.toBeNull();
|
|
88
|
-
expect(button.ariaLabel).toBe(exampleTooltip);
|
|
89
|
-
expect(button.textContent).toBe(exampleLabel);
|
|
90
|
-
expect(icon.iconName).toBe(exampleIcon);
|
|
91
|
-
expect(button.classList.contains('stateful-button--selected')).toBe(true);
|
|
92
|
-
expect(button.classList.contains('stateful-button--unselected')).toBe(
|
|
93
|
-
false
|
|
94
|
-
);
|
|
95
|
-
expect(
|
|
96
|
-
button.classList.contains('stateful-button--without-borders')
|
|
97
|
-
).toBe(false);
|
|
98
|
-
expect(tooltipContent.textContent).toBe(exampleTooltip);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('when the selected stateful button is clicked', () => {
|
|
102
|
-
it('should dispatch the "unselect" event', async () => {
|
|
103
|
-
const element = createTestComponent({
|
|
104
|
-
...exampleOptions,
|
|
105
|
-
selected: true,
|
|
106
|
-
});
|
|
107
|
-
setupEventListeners(element);
|
|
108
|
-
await flushPromises();
|
|
109
|
-
|
|
110
|
-
const button = element.shadowRoot.querySelector(
|
|
111
|
-
selectors.statefulButton
|
|
112
|
-
);
|
|
113
|
-
await button.click();
|
|
114
|
-
|
|
115
|
-
expect(functionsMocks.exampleHandleDeselect).toHaveBeenCalledTimes(1);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe('when the withoutBorders property is set to true', () => {
|
|
120
|
-
it('should display the button without border', async () => {
|
|
121
|
-
const element = createTestComponent({
|
|
122
|
-
...exampleOptions,
|
|
123
|
-
selected: true,
|
|
124
|
-
withoutBorders: true,
|
|
125
|
-
});
|
|
126
|
-
setupEventListeners(element);
|
|
127
|
-
await flushPromises();
|
|
128
|
-
|
|
129
|
-
const button = element.shadowRoot.querySelector(
|
|
130
|
-
selectors.statefulButton
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
expect(
|
|
134
|
-
button.classList.contains('stateful-button--without-borders')
|
|
135
|
-
).toBe(true);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
describe('when a vlue of the selectedStateColor property is provided', () => {
|
|
140
|
-
it('should display the button with the correct colors', async () => {
|
|
141
|
-
const exampleColor = '#FFF';
|
|
142
|
-
const element = createTestComponent({
|
|
143
|
-
...exampleOptions,
|
|
144
|
-
selectedStateColor: exampleColor,
|
|
145
|
-
});
|
|
146
|
-
setupEventListeners(element);
|
|
147
|
-
await flushPromises();
|
|
148
|
-
|
|
149
|
-
expect(element.shadowRoot.host?.style?._values).toEqual({
|
|
150
|
-
'--selected-state-color': exampleColor,
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe('when the stateful button is in the unselected state', () => {
|
|
157
|
-
it('should properly display the unselected stateful button', async () => {
|
|
158
|
-
const element = createTestComponent();
|
|
159
|
-
await flushPromises();
|
|
160
|
-
|
|
161
|
-
const button = element.shadowRoot.querySelector(selectors.statefulButton);
|
|
162
|
-
const icon = element.shadowRoot.querySelector(selectors.icon);
|
|
163
|
-
const tooltip = element.shadowRoot.querySelector(selectors.tooltip);
|
|
164
|
-
const tooltipContent = element.shadowRoot.querySelector(
|
|
165
|
-
selectors.tooltipContent
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
expect(button).not.toBeNull();
|
|
169
|
-
expect(icon).not.toBeNull();
|
|
170
|
-
expect(tooltip).not.toBeNull();
|
|
171
|
-
expect(tooltipContent).not.toBeNull();
|
|
172
|
-
expect(button.ariaLabel).toBe(exampleTooltip);
|
|
173
|
-
expect(button.textContent).toBe(exampleLabel);
|
|
174
|
-
expect(icon.iconName).toBe(exampleIcon);
|
|
175
|
-
expect(button.classList.contains('stateful-button--selected')).toBe(
|
|
176
|
-
false
|
|
177
|
-
);
|
|
178
|
-
expect(button.classList.contains('stateful-button--unselected')).toBe(
|
|
179
|
-
true
|
|
180
|
-
);
|
|
181
|
-
expect(
|
|
182
|
-
button.classList.contains('stateful-button--without-borders')
|
|
183
|
-
).toBe(false);
|
|
184
|
-
expect(tooltipContent.textContent).toBe(exampleTooltip);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
describe('when the unselected stateful button is clicked', () => {
|
|
188
|
-
it('should dispatch the "select" event', async () => {
|
|
189
|
-
const element = createTestComponent();
|
|
190
|
-
setupEventListeners(element);
|
|
191
|
-
await flushPromises();
|
|
192
|
-
|
|
193
|
-
const button = element.shadowRoot.querySelector(
|
|
194
|
-
selectors.statefulButton
|
|
195
|
-
);
|
|
196
|
-
await button.click();
|
|
197
|
-
|
|
198
|
-
expect(functionsMocks.exampleHandleSelect).toHaveBeenCalledTimes(1);
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
describe('when the withoutBorders property is set to true', () => {
|
|
203
|
-
it('should display the button without border', async () => {
|
|
204
|
-
const element = createTestComponent({
|
|
205
|
-
...exampleOptions,
|
|
206
|
-
selected: true,
|
|
207
|
-
withoutBorders: true,
|
|
208
|
-
});
|
|
209
|
-
setupEventListeners(element);
|
|
210
|
-
await flushPromises();
|
|
211
|
-
|
|
212
|
-
const button = element.shadowRoot.querySelector(
|
|
213
|
-
selectors.statefulButton
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
expect(
|
|
217
|
-
button.classList.contains('stateful-button--without-borders')
|
|
218
|
-
).toBe(true);
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
});
|