Skip to content

Commit ebfb629

Browse files
authored
Merge branch 'master' into SFINT-6015
2 parents 1b1514b + ea7abaf commit ebfb629

File tree

26 files changed

+1554
-216
lines changed

26 files changed

+1554
-216
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import {describe, it, expect, beforeEach, vi} from 'vitest';
2+
import {
3+
createBaseStore,
4+
setLoadingFlag,
5+
unsetLoadingFlag,
6+
} from '../../common/interface/store';
7+
import {
8+
createCommerceRecommendationStore,
9+
CommerceRecommendationStore,
10+
} from './store';
11+
12+
vi.mock('../../common/interface/store', {spy: true});
13+
14+
describe('#createCommerceRecommendationStore', () => {
15+
let store: CommerceRecommendationStore;
16+
17+
beforeEach(() => {
18+
store = createCommerceRecommendationStore();
19+
});
20+
21+
it('should call #createBaseStore with the correct arguments', () => {
22+
expect(store).toBeDefined();
23+
expect(createBaseStore).toHaveBeenCalledExactlyOnceWith({
24+
loadingFlags: [],
25+
iconAssetsPath: '',
26+
resultList: undefined,
27+
});
28+
});
29+
30+
it('should return an object that includes all properties and methods from the base store', () => {
31+
const createBaseStoreSpy = vi.mocked(createBaseStore);
32+
const baseStore = createBaseStoreSpy.mock.results[0].value;
33+
34+
expect(store).toEqual({
35+
...baseStore,
36+
unsetLoadingFlag: expect.any(Function),
37+
setLoadingFlag: expect.any(Function),
38+
});
39+
});
40+
41+
it('should delegate its #setLoadingFlag to the core #setLoadingFlag with the correct arguments', () => {
42+
const createBaseStoreSpy = vi.mocked(createBaseStore);
43+
const baseStore = createBaseStoreSpy.mock.results[0].value;
44+
45+
store.setLoadingFlag('testFlag');
46+
47+
expect(setLoadingFlag).toHaveBeenCalledExactlyOnceWith(
48+
baseStore,
49+
'testFlag'
50+
);
51+
});
52+
53+
it('should delegate its #unsetLoadingFlag to the core #unsetLoadingFlag with the correct arguments', () => {
54+
const createBaseStoreSpy = vi.mocked(createBaseStore);
55+
const baseStore = createBaseStoreSpy.mock.results[0].value;
56+
57+
store.unsetLoadingFlag('testFlag');
58+
59+
expect(unsetLoadingFlag).toHaveBeenCalledExactlyOnceWith(
60+
baseStore,
61+
'testFlag'
62+
);
63+
});
64+
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import {describe, it, expect, vi, beforeEach, afterEach} from 'vitest';
2+
import * as env from './environment';
3+
4+
vi.mock('@coveo/headless', () => ({VERSION: 'HEADLESS_VERSION'}));
5+
6+
describe('environment', () => {
7+
const globalWindow = window as Record<string, unknown>;
8+
const originalCoveoAtomic = globalWindow['COVEO_ATOMIC'];
9+
const originalEnv = process.env.VERSION;
10+
11+
beforeEach(() => {
12+
delete globalWindow['COVEO_ATOMIC'];
13+
process.env.VERSION = 'ATOMIC_VERSION';
14+
});
15+
16+
afterEach(() => {
17+
globalWindow['COVEO_ATOMIC'] = originalCoveoAtomic;
18+
if (originalEnv !== undefined) {
19+
process.env.VERSION = originalEnv;
20+
} else {
21+
delete process.env.VERSION;
22+
}
23+
});
24+
25+
describe('#getAtomicEnvironment', () => {
26+
it('should return correct versions', () => {
27+
const result = env.getAtomicEnvironment();
28+
29+
expect(result).toEqual({
30+
version: 'ATOMIC_VERSION',
31+
headlessVersion: 'HEADLESS_VERSION',
32+
});
33+
});
34+
});
35+
36+
describe('#setCoveoGlobal', () => {
37+
it('should set the COVEO_ATOMIC global variable when not already set', () => {
38+
expect(
39+
(window as Record<string, unknown>)['COVEO_ATOMIC']
40+
).toBeUndefined();
41+
42+
env.setCoveoGlobal('COVEO_ATOMIC');
43+
44+
expect((window as Record<string, unknown>)['COVEO_ATOMIC']).toEqual({
45+
version: 'ATOMIC_VERSION',
46+
headlessVersion: 'HEADLESS_VERSION',
47+
});
48+
});
49+
50+
it('should not overwrite the COVEO_ATOMIC global variable when already set', () => {
51+
(window as Record<string, unknown>)['COVEO_ATOMIC'] = {
52+
version: 'EXISTING',
53+
headlessVersion: 'EXISTING',
54+
};
55+
56+
env.setCoveoGlobal('COVEO_ATOMIC');
57+
58+
expect((window as Record<string, unknown>)['COVEO_ATOMIC']).toEqual({
59+
version: 'EXISTING',
60+
headlessVersion: 'EXISTING',
61+
});
62+
});
63+
});
64+
});

packages/quantic/cypress/e2e/default-2/search-box/search-box-selectors.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export interface SearchBoxSelector extends ComponentSelector {
1616
export const SearchBoxSelectors: SearchBoxSelector = {
1717
get: () => cy.get(standaloneSearchBoxComponent),
1818
quanticSearchBoxInput: () =>
19-
SearchBoxSelectors.get().find('[data-cy="quantic-search-box-input"]'),
19+
SearchBoxSelectors.get().find('[data-testid="quantic-search-box-input"]'),
2020
input: (textarea = false) =>
2121
SearchBoxSelectors.get().find(
22-
`c-quantic-search-box-input [data-cy="${textarea ? 'search-box-textarea' : 'search-box-input'}"]`
22+
`c-quantic-search-box-input [data-testid="${textarea ? 'search-box-textarea' : 'search-box-input'}"]`
2323
),
2424
suggestionList: () =>
2525
SearchBoxSelectors.get().find(
@@ -31,18 +31,18 @@ export const SearchBoxSelectors: SearchBoxSelector = {
3131
),
3232
clearRecentQueriesButton: () =>
3333
SearchBoxSelectors.get().find(
34-
'c-quantic-search-box-input [data-cy="clear-recent-queries"]'
34+
'c-quantic-search-box-input [data-testid="clear-recent-queries-button"]'
3535
),
3636
querySuggestions: () =>
3737
SearchBoxSelectors.get().find(
38-
'c-quantic-search-box-input [data-cy="suggestions-option"]'
38+
'c-quantic-search-box-input [data-testid="suggestions-option"]'
3939
),
4040
querySuggestionByIndex: (index: number) =>
4141
SearchBoxSelectors.querySuggestions().eq(index),
4242
querySuggestionContentByIndex: (index: number) =>
4343
SearchBoxSelectors.get()
4444
.find(
45-
'c-quantic-search-box-input [data-cy="suggestions-option"] lightning-formatted-rich-text'
45+
'c-quantic-search-box-input [data-testid="suggestions-option"] lightning-formatted-rich-text'
4646
)
4747
.eq(index),
4848
};

packages/quantic/cypress/e2e/default-2/standalone-search-box/standalone-search-box-selectors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export const StandaloneSearchBoxSelectors: StandaloneSearchBoxSelector = {
1515
get: () => cy.get(standaloneSearchBoxComponent),
1616
quanticSearchBoxInput: () =>
1717
StandaloneSearchBoxSelectors.get().find(
18-
'[data-cy="quantic-search-box-input"]'
18+
'[data-testid="quantic-search-box-input"]'
1919
),
2020
input: (textarea = false) =>
2121
StandaloneSearchBoxSelectors.get().find(
2222
textarea
23-
? 'c-quantic-search-box-input [data-cy="search-box-textarea"]'
24-
: 'c-quantic-search-box-input [data-cy="search-box-input"]'
23+
? 'c-quantic-search-box-input [data-testid="search-box-textarea"]'
24+
: 'c-quantic-search-box-input [data-testid="search-box-input"]'
2525
),
2626
suggestionList: () =>
2727
StandaloneSearchBoxSelectors.get().find(
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<div>
3+
<lightning-input
4+
label={inputLabel}
5+
value={inputValue}
6+
data-testid="localstorage-input"
7+
onchange={handleInputChange}
8+
></lightning-input>
9+
<lightning-button
10+
label="Set Value"
11+
onclick={handleSetValue}
12+
class="slds-var-m-top_small"
13+
data-testid="localstorage-set-button"
14+
></lightning-button>
15+
16+
<lightning-button
17+
label="Print Value"
18+
onclick={handlePrintValue}
19+
class="slds-var-m-top_small slds-var-m-left_small"
20+
data-testid="localstorage-get-button"
21+
></lightning-button>
22+
23+
<p class="slds-var-m-top_medium" data-testid="localstorage-output">
24+
{outputValue}
25+
</p>
26+
</div>
27+
</template>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {api, LightningElement} from 'lwc';
2+
3+
export default class ActionLocalStorage extends LightningElement {
4+
@api storageKey;
5+
6+
inputValue = '';
7+
outputValue = '';
8+
9+
handleInputChange(event) {
10+
this.inputValue = event.target.value;
11+
}
12+
13+
handleSetValue() {
14+
if (this.storageKey) {
15+
localStorage.setItem(this.storageKey, this.inputValue);
16+
}
17+
}
18+
19+
handlePrintValue() {
20+
if (this.storageKey) {
21+
this.outputValue = localStorage.getItem(this.storageKey) || '';
22+
}
23+
}
24+
25+
get inputLabel() {
26+
return `Set value for key "${this.storageKey}":`;
27+
}
28+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>52.0</apiVersion>
4+
<isExposed>false</isExposed>
5+
</LightningComponentBundle>

packages/quantic/force-app/examples/main/lwc/exampleQuanticSearchBox/exampleQuanticSearchBox.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<div slot="configuration">
88
<c-configurator options={options} ontryitnow={handleTryItNow}>
9+
<c-action-local-storage slot="actions" storage-key={recentQueriesStorageKey}></c-action-local-storage>
910
</c-configurator>
1011
</div>
1112

packages/quantic/force-app/examples/main/lwc/exampleQuanticSearchBox/exampleQuanticSearchBox.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import {LightningElement, track} from 'lwc';
22

3+
const DEFAULT_ENGINE_ID = 'quantic-search-box-engine';
4+
const RECENT_QUERIES_STORAGE_KEY_SUFFIX = '_quantic-recent-queries';
5+
36
export default class ExampleQuanticSearchBox extends LightningElement {
4-
@track config = {};
7+
@track config = {
8+
engineId: DEFAULT_ENGINE_ID,
9+
};
510
isConfigured = false;
611

712
pageTitle = 'Quantic Search Box';
@@ -12,7 +17,7 @@ export default class ExampleQuanticSearchBox extends LightningElement {
1217
attribute: 'engineId',
1318
label: 'Engine id',
1419
description: 'The ID of the engine instance the component registers to.',
15-
defaultValue: 'quantic-search-box-engine',
20+
defaultValue: DEFAULT_ENGINE_ID,
1621
},
1722
{
1823
attribute: 'useCase',
@@ -61,4 +66,8 @@ export default class ExampleQuanticSearchBox extends LightningElement {
6166
this.config = evt.detail;
6267
this.isConfigured = true;
6368
}
69+
70+
get recentQueriesStorageKey() {
71+
return `${this.config.engineId}${RECENT_QUERIES_STORAGE_KEY_SUFFIX}`;
72+
}
6473
}

packages/quantic/force-app/main/default/lwc/quanticPager/e2e/fixture.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ export const testSearch = quanticBase.extend<QuanticPagerE2ESearchFixtures>({
3535
},
3636
pager: async ({page, options, configuration, search, urlHash}, use) => {
3737
await page.goto(urlHash ? `${pageUrl}#${urlHash}` : pageUrl);
38+
const searchResponsePromise = search.waitForSearchResponse();
3839
configuration.configure(options);
39-
await search.waitForSearchResponse();
40+
await searchResponsePromise;
4041

4142
await use(new PagerObject(page));
4243
},
@@ -54,8 +55,9 @@ export const testInsight = quanticBase.extend<QuanticPagerE2EInsightFixtures>({
5455
await page.goto(pageUrl);
5556
configuration.configure({...options, useCase: useCaseEnum.insight});
5657
await insightSetup.waitForInsightInterfaceInitialization();
58+
const searchResponsePromise = search.waitForSearchResponse();
5759
await search.performSearch();
58-
await search.waitForSearchResponse();
60+
await searchResponsePromise;
5961
await use(new PagerObject(page));
6062
},
6163
});

packages/quantic/force-app/main/default/lwc/quanticPager/e2e/quanticPager.e2e.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ useCaseTestCases.forEach((useCase) => {
1818
search,
1919
}) => {
2020
const searchResponsePromise = search.waitForSearchResponse();
21+
const pagerNextUaAnalyticsPromise = pager.waitForPagerNextUaAnalytics();
2122
await pager.clickNextPageButton();
2223
const searchResponse = await searchResponsePromise;
2324
const {firstResult} = searchResponse.request().postDataJSON();
2425
expect(firstResult).toBe(numberOfResultsPerPage);
25-
await pager.waitForPagerNextUaAnalytics();
26+
await pagerNextUaAnalyticsPromise;
2627
});
2728
});
2829

@@ -36,11 +37,13 @@ useCaseTestCases.forEach((useCase) => {
3637
await initialSearchResponsePromise;
3738

3839
const searchResponsePromise = search.waitForSearchResponse();
40+
const pagerPreviousUaAnalyticsPromise =
41+
pager.waitForPagerPreviousUaAnalytics();
3942
await pager.clickPreviousPageButton();
4043
const searchResponse = await searchResponsePromise;
4144
const {firstResult} = searchResponse.request().postDataJSON();
4245
expect(firstResult).toBe(0);
43-
await pager.waitForPagerPreviousUaAnalytics();
46+
await pagerPreviousUaAnalyticsPromise;
4447
});
4548
});
4649

@@ -51,11 +54,13 @@ useCaseTestCases.forEach((useCase) => {
5154
}) => {
5255
const examplePage = 3;
5356
const searchResponsePromise = search.waitForSearchResponse();
57+
const pagerPageUaAnalyticsPromise =
58+
pager.waitForPagerNumberUaAnalytics();
5459
await pager.clickPageNumberButton(examplePage);
5560
const searchResponse = await searchResponsePromise;
5661
const {firstResult} = searchResponse.request().postDataJSON();
5762
expect(firstResult).toBe(numberOfResultsPerPage * (examplePage - 1));
58-
await pager.waitForPagerNumberUaAnalytics();
63+
await pagerPageUaAnalyticsPromise;
5964
});
6065
});
6166

packages/quantic/force-app/main/default/lwc/quanticResultList/e2e/fixture.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const testSearch =
3535
await page.goto(pageUrl);
3636
configuration.configure(options);
3737
await search.waitForSearchResponse();
38+
await search.waitForSearchResultsVisible();
3839
await use(new ResultListObject(page));
3940
},
4041
});
@@ -57,6 +58,7 @@ export const testInsight =
5758
await insightSetup.waitForInsightInterfaceInitialization();
5859
await search.performSearch();
5960
await search.waitForSearchResponse();
61+
await search.waitForSearchResultsVisible();
6062
await use(new ResultListObject(page));
6163
},
6264
});

0 commit comments

Comments
 (0)