@coveo/quantic 3.11.0 → 3.12.0
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/README.md +1 -1
- package/docs/out/quantic-docs.json +27 -0
- package/force-app/main/default/lwc/quanticBreadcrumbManager/__tests__/quanticBreadcrumbManager.test.js +610 -0
- package/force-app/main/default/lwc/quanticBreadcrumbManager/e2e/fixture.ts +76 -0
- package/force-app/main/default/lwc/quanticBreadcrumbManager/e2e/pageObject.ts +282 -0
- package/force-app/main/default/lwc/quanticBreadcrumbManager/e2e/quanticBreadcrumbManager.e2e.ts +167 -0
- package/force-app/main/default/lwc/quanticBreadcrumbManager/quanticBreadcrumbManager.html +10 -10
- package/force-app/main/default/lwc/quanticBreadcrumbManager/quanticBreadcrumbManager.js +8 -8
- package/force-app/main/default/lwc/quanticFeedbackModalQna/templates/quanticFeedbackModalQna.html +1 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswer/__tests__/quanticGeneratedAnswer.test.js +538 -21
- package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/data.ts +56 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/fixture.ts +87 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/pageObject.ts +279 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/quanticGeneratedAnswer.e2e.ts +178 -0
- package/force-app/main/default/lwc/quanticGeneratedAnswer/templates/generatedAnswer.html +24 -10
- package/force-app/main/default/lwc/quanticGeneratedAnswer/templates/retryPrompt.html +2 -2
- package/force-app/main/default/lwc/quanticGeneratedAnswerToggle/quanticGeneratedAnswerToggle.html +1 -1
- package/force-app/main/default/lwc/quanticPager/e2e/fixture.ts +4 -4
- package/force-app/main/default/lwc/quanticPager/e2e/{pagerObject.ts → pageObject.ts} +1 -1
- package/force-app/main/default/lwc/quanticTab/__tests__/quanticTab.test.js +287 -0
- package/force-app/main/default/lwc/quanticTab/e2e/fixture.ts +62 -0
- package/force-app/main/default/lwc/quanticTab/e2e/pageObject.ts +67 -0
- package/force-app/main/default/lwc/quanticTab/e2e/quanticTab.e2e.ts +77 -0
- package/force-app/main/default/lwc/quanticTab/quanticTab.html +1 -1
- package/force-app/main/default/lwc/quanticTabBar/__tests__/quanticTabBar.test.js +331 -0
- package/force-app/main/default/lwc/quanticTabBar/e2e/fixture.ts +61 -0
- package/force-app/main/default/lwc/quanticTabBar/e2e/pageObject.ts +80 -0
- package/force-app/main/default/lwc/quanticTabBar/e2e/quanticTabBar.e2e.ts +173 -0
- package/force-app/main/default/lwc/quanticTabBar/quanticTabBar.html +30 -8
- package/force-app/main/default/lwc/quanticTabBar/quanticTabBar.js +5 -4
- package/force-app/main/default/lwc/quanticUserActionsToggle/e2e/pageObject.ts +1 -1
- package/force-app/main/default/lwc/quanticUserActionsToggle/quanticUserActionsToggle.js +4 -0
- package/force-app/main/default/lwc/quanticUtils/__tests__/markdownUtils.test.js +1 -1
- package/force-app/main/default/staticresources/coveobueno/browser/bueno.js +4 -4
- package/force-app/main/default/staticresources/coveoheadless/case-assist/headless.js +8 -10
- package/force-app/main/default/staticresources/coveoheadless/definitions/api/analytics/instant-result-analytics.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/api/analytics/search-analytics.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/api/commerce/common/request.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/api/knowledge/stream-answer-api.d.ts +4 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/api/search/search-api-params.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/api/service/case-assist/case-assist-params.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/api/service/insight/insight-params.d.ts +2 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-engine/commerce-engine.ssr.d.ts +2 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-ssr-engine/factories/build-factory.d.ts +2 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-ssr-engine/factories/utils/recommendation-filter.d.ts +11 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-ssr-engine/types/common.d.ts +12 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/commerce-ssr-engine/types/kind.d.ts +9 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/app/undoable.d.ts +0 -3
- package/force-app/main/default/staticresources/coveoheadless/definitions/commerce.index.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/breadcrumb-manager/headless-core-breadcrumb-manager.ssr.d.ts +1 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/facets/generator/headless-commerce-facet-generator.ssr.d.ts +3 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/parameter-manager/headless-core-parameter-manager.d.ts +7 -6
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/parameter-manager/headless-core-parameter-manager.ssr.d.ts +3 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/sub-controller/headless-sub-controller.d.ts +1 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/sub-controller/headless-sub-controller.ssr.d.ts +2 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/core/url-manager/headless-core-url-manager.d.ts +11 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/product-list/headless-product-list.ssr.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/product-view/headless-product-view.ssr.d.ts +1 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/commerce/recommendations/headless-recommendations.d.ts +1 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/controllers/core/context/example-deleteme-headless-case-context.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/actions-history/ipx-actions-history-actions.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/analytics/analytics-utils.d.ts +3 -3
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/parameters/parameters-actions.d.ts +22 -6
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/parameters/parameters-schema.d.ts +4 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/parameters/parameters-selectors.d.ts +0 -11
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/parameters/parameters-serializer.d.ts +8 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/parameters/parameters-serializer.ssr.d.ts +44 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/parameters/parameters-slice.d.ts +4 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/parameters/parameters-state.d.ts +4 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/recommendations/recommendations-actions.d.ts +1 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/recommendations/recommendations-state.d.ts +1 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/search/search-selectors.d.ts +0 -12
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/debug/debug-selectors.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/generated-answer/generated-answer-analytics-actions.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/history/history-actions.d.ts +3 -3
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/pipeline/select-pipeline.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/query/query-selectors.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/question-answering/question-answering-document-id.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/question-answering/question-answering-selectors.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/search/legacy/search-actions.d.ts +42 -42
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/search/legacy/search-request.d.ts +44 -44
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/search/search-actions.d.ts +42 -43
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/search/search-mappings.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/search/search-request.d.ts +44 -44
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/search/search-selectors.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/search-hub/search-hub-selectors.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/features/search-parameters/search-parameter-serializer.d.ts +5 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/selectors/commerce-selectors.index.d.ts +2 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/ssr-commerce.index.d.ts +4 -3
- package/force-app/main/default/staticresources/coveoheadless/definitions/state/commerce-app-state.d.ts +2 -2
- package/force-app/main/default/staticresources/coveoheadless/definitions/state/state-sections.d.ts +4 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/test/mock-search-request.d.ts +44 -44
- package/force-app/main/default/staticresources/coveoheadless/definitions/tsdoc-metadata.json +1 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/utils/compare-utils.d.ts +2 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/utils/errors.d.ts +3 -0
- package/force-app/main/default/staticresources/coveoheadless/definitions/utils/utils.d.ts +0 -1
- package/force-app/main/default/staticresources/coveoheadless/definitions/utils/validate-payload.d.ts +1 -1
- package/force-app/main/default/staticresources/coveoheadless/headless.js +10 -12
- package/force-app/main/default/staticresources/coveoheadless/insight/headless.js +9 -11
- package/force-app/main/default/staticresources/coveoheadless/recommendation/headless.js +8 -10
- package/force-app/main/default/staticresources/dompurify/purify.min.js +2 -1339
- package/force-app/main/default/staticresources/marked/marked.min.js +3 -3
- package/package.json +12 -16
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/* eslint-disable jest/no-conditional-expect */
|
|
2
|
+
/* eslint-disable no-import-assign */
|
|
3
|
+
import QuanticTab from '../quanticTab';
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import {createElement} from 'lwc';
|
|
6
|
+
import * as mockHeadlessLoader from 'c/quanticHeadlessLoader';
|
|
7
|
+
|
|
8
|
+
jest.mock('c/quanticHeadlessLoader');
|
|
9
|
+
|
|
10
|
+
let isInitialized = false;
|
|
11
|
+
|
|
12
|
+
const exampleEngine = {
|
|
13
|
+
id: 'exampleEngineId',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const defaultOptions = {
|
|
17
|
+
engineId: exampleEngine.id,
|
|
18
|
+
label: 'Example Tab',
|
|
19
|
+
expression: 'exampleExpression',
|
|
20
|
+
isActive: false,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const selectors = {
|
|
24
|
+
initializationError: 'c-quantic-component-error',
|
|
25
|
+
tabButton: 'button',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const defaultSearchStatusState = {
|
|
29
|
+
hasResults: true,
|
|
30
|
+
firstSearchExecuted: true,
|
|
31
|
+
};
|
|
32
|
+
let searchStatusState = defaultSearchStatusState;
|
|
33
|
+
|
|
34
|
+
const defaultTabState = {
|
|
35
|
+
isActive: false,
|
|
36
|
+
};
|
|
37
|
+
let tabState = defaultTabState;
|
|
38
|
+
|
|
39
|
+
const functionsMocks = {
|
|
40
|
+
buildTab: jest.fn(() => ({
|
|
41
|
+
state: tabState,
|
|
42
|
+
subscribe: functionsMocks.tabStateSubscriber,
|
|
43
|
+
select: functionsMocks.select,
|
|
44
|
+
})),
|
|
45
|
+
buildSearchStatus: jest.fn(() => ({
|
|
46
|
+
state: searchStatusState,
|
|
47
|
+
subscribe: functionsMocks.searchStatusStateSubscriber,
|
|
48
|
+
})),
|
|
49
|
+
tabStateSubscriber: jest.fn((cb) => {
|
|
50
|
+
cb();
|
|
51
|
+
return functionsMocks.tabStateUnsubscriber;
|
|
52
|
+
}),
|
|
53
|
+
searchStatusStateSubscriber: jest.fn((cb) => {
|
|
54
|
+
cb();
|
|
55
|
+
return functionsMocks.searchStatusStateUnsubscriber;
|
|
56
|
+
}),
|
|
57
|
+
tabStateUnsubscriber: jest.fn(),
|
|
58
|
+
searchStatusStateUnsubscriber: jest.fn(),
|
|
59
|
+
exampleTabRendered: jest.fn(),
|
|
60
|
+
select: jest.fn(),
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const expectedActiveTabClass = 'slds-is-active';
|
|
64
|
+
|
|
65
|
+
function createTestComponent(options = defaultOptions) {
|
|
66
|
+
const element = createElement('c-quantic-tab', {
|
|
67
|
+
is: QuanticTab,
|
|
68
|
+
});
|
|
69
|
+
for (const [key, value] of Object.entries(options)) {
|
|
70
|
+
element[key] = value;
|
|
71
|
+
}
|
|
72
|
+
document.body.appendChild(element);
|
|
73
|
+
return element;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function prepareHeadlessState() {
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
mockHeadlessLoader.getHeadlessBundle = () => {
|
|
79
|
+
return {
|
|
80
|
+
buildTab: functionsMocks.buildTab,
|
|
81
|
+
buildSearchStatus: functionsMocks.buildSearchStatus,
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Helper function to wait until the microtask queue is empty.
|
|
87
|
+
function flushPromises() {
|
|
88
|
+
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function mockSuccessfulHeadlessInitialization() {
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
mockHeadlessLoader.initializeWithHeadless = (element, _, initialize) => {
|
|
94
|
+
if (element instanceof QuanticTab && !isInitialized) {
|
|
95
|
+
isInitialized = true;
|
|
96
|
+
initialize(exampleEngine);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function mockErroneousHeadlessInitialization() {
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
mockHeadlessLoader.initializeWithHeadless = (element) => {
|
|
104
|
+
if (element instanceof QuanticTab) {
|
|
105
|
+
element.setInitializationError();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function setupEventListeners(element) {
|
|
111
|
+
element.addEventListener(
|
|
112
|
+
'quantic__tabrendered',
|
|
113
|
+
functionsMocks.exampleTabRendered
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function cleanup() {
|
|
118
|
+
// The jsdom instance is shared across test cases in a single file so reset the DOM
|
|
119
|
+
while (document.body.firstChild) {
|
|
120
|
+
document.body.removeChild(document.body.firstChild);
|
|
121
|
+
}
|
|
122
|
+
jest.clearAllMocks();
|
|
123
|
+
isInitialized = false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
describe('c-quantic-tab', () => {
|
|
127
|
+
beforeEach(() => {
|
|
128
|
+
mockSuccessfulHeadlessInitialization();
|
|
129
|
+
prepareHeadlessState();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
afterEach(() => {
|
|
133
|
+
tabState = defaultTabState;
|
|
134
|
+
searchStatusState = defaultSearchStatusState;
|
|
135
|
+
cleanup();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('component initialization', () => {
|
|
139
|
+
it('should build the tab and search status controllers with the proper parameters', async () => {
|
|
140
|
+
createTestComponent();
|
|
141
|
+
await flushPromises();
|
|
142
|
+
|
|
143
|
+
expect(functionsMocks.buildTab).toHaveBeenCalledTimes(1);
|
|
144
|
+
expect(functionsMocks.buildTab).toHaveBeenCalledWith(exampleEngine, {
|
|
145
|
+
options: {
|
|
146
|
+
expression: defaultOptions.expression,
|
|
147
|
+
id: defaultOptions.label,
|
|
148
|
+
},
|
|
149
|
+
initialState: {
|
|
150
|
+
isActive: defaultOptions.isActive,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
expect(functionsMocks.buildSearchStatus).toHaveBeenCalledTimes(1);
|
|
154
|
+
expect(functionsMocks.buildSearchStatus).toHaveBeenCalledWith(
|
|
155
|
+
exampleEngine
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should subscribe to the headless tab and search status state changes', async () => {
|
|
160
|
+
createTestComponent();
|
|
161
|
+
await flushPromises();
|
|
162
|
+
|
|
163
|
+
expect(functionsMocks.tabStateSubscriber).toHaveBeenCalledTimes(1);
|
|
164
|
+
expect(functionsMocks.searchStatusStateSubscriber).toHaveBeenCalledTimes(
|
|
165
|
+
1
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('should dispatch the quantic__tabrendered event', async () => {
|
|
170
|
+
const element = createTestComponent();
|
|
171
|
+
setupEventListeners(element);
|
|
172
|
+
await flushPromises();
|
|
173
|
+
|
|
174
|
+
expect(functionsMocks.exampleTabRendered).toHaveBeenCalledTimes(1);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe('when an initialization error occurs', () => {
|
|
179
|
+
beforeEach(() => {
|
|
180
|
+
mockErroneousHeadlessInitialization();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
afterAll(() => {
|
|
184
|
+
mockSuccessfulHeadlessInitialization();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('should display the initialization error component', async () => {
|
|
188
|
+
const element = createTestComponent();
|
|
189
|
+
await flushPromises();
|
|
190
|
+
|
|
191
|
+
const initializationError = element.shadowRoot.querySelector(
|
|
192
|
+
selectors.initializationError
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
expect(initializationError).not.toBeNull();
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe('component behavior during the initial search', () => {
|
|
200
|
+
describe('when the initial search is not yet executed', () => {
|
|
201
|
+
beforeAll(() => {
|
|
202
|
+
searchStatusState = {...searchStatusState, firstSearchExecuted: false};
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('should not show the tab before the initial search completes', async () => {
|
|
206
|
+
const element = createTestComponent();
|
|
207
|
+
await flushPromises();
|
|
208
|
+
|
|
209
|
+
const tab = element.shadowRoot.querySelector(selectors.tabButton);
|
|
210
|
+
|
|
211
|
+
expect(tab).toBeNull();
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe('when the initial search is executed', () => {
|
|
216
|
+
beforeAll(() => {
|
|
217
|
+
searchStatusState = {...searchStatusState, firstSearchExecuted: true};
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('should show the tab after the initial search completes', async () => {
|
|
221
|
+
const element = createTestComponent();
|
|
222
|
+
await flushPromises();
|
|
223
|
+
|
|
224
|
+
const tab = element.shadowRoot.querySelector(selectors.tabButton);
|
|
225
|
+
|
|
226
|
+
expect(tab).not.toBeNull();
|
|
227
|
+
expect(tab.textContent).toBe(defaultOptions.label);
|
|
228
|
+
expect(tab.title).toEqual(defaultOptions.label);
|
|
229
|
+
expect(tab.getAttribute('aria-pressed')).toBe('false');
|
|
230
|
+
expect(tab.getAttribute('aria-label')).toBe(defaultOptions.label);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe('when the tab is not active', () => {
|
|
236
|
+
beforeAll(() => {
|
|
237
|
+
tabState = {...tabState, isActive: false};
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('should not display the tab as an active tab', async () => {
|
|
241
|
+
const element = createTestComponent();
|
|
242
|
+
await flushPromises();
|
|
243
|
+
|
|
244
|
+
const tab = element.shadowRoot.querySelector(selectors.tabButton);
|
|
245
|
+
expect(tab).not.toBeNull();
|
|
246
|
+
|
|
247
|
+
expect(tab.classList).not.toContain(expectedActiveTabClass);
|
|
248
|
+
expect(element.isActive).toBe(false);
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe('when the tab is active', () => {
|
|
253
|
+
beforeAll(() => {
|
|
254
|
+
tabState = {...tabState, isActive: true};
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it('should display the tab as an active tab', async () => {
|
|
258
|
+
const element = createTestComponent();
|
|
259
|
+
await flushPromises();
|
|
260
|
+
|
|
261
|
+
const tab = element.shadowRoot.querySelector(selectors.tabButton);
|
|
262
|
+
|
|
263
|
+
expect(tab.classList).toContain(expectedActiveTabClass);
|
|
264
|
+
expect(element.isActive).toBe(true);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe('when the tab is clicked or the select method is called', () => {
|
|
269
|
+
it('should call the select method of the tab controller', async () => {
|
|
270
|
+
const element = createTestComponent();
|
|
271
|
+
await flushPromises();
|
|
272
|
+
|
|
273
|
+
const tab = element.shadowRoot.querySelector(selectors.tabButton);
|
|
274
|
+
expect(tab).not.toBeNull();
|
|
275
|
+
|
|
276
|
+
await tab.click();
|
|
277
|
+
await flushPromises();
|
|
278
|
+
|
|
279
|
+
expect(functionsMocks.select).toHaveBeenCalledTimes(1);
|
|
280
|
+
|
|
281
|
+
await element.select();
|
|
282
|
+
await flushPromises();
|
|
283
|
+
|
|
284
|
+
expect(functionsMocks.select).toHaveBeenCalledTimes(2);
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {TabObject} from './pageObject';
|
|
2
|
+
import {SearchObject} from '../../../../../../playwright/page-object/searchObject';
|
|
3
|
+
import {quanticBase} from '../../../../../../playwright/fixtures/baseFixture';
|
|
4
|
+
import {useCaseEnum} from '../../../../../../playwright/utils/useCase';
|
|
5
|
+
import {InsightSetupObject} from '../../../../../../playwright/page-object/insightSetupObject';
|
|
6
|
+
import {
|
|
7
|
+
searchRequestRegex,
|
|
8
|
+
insightSearchRequestRegex,
|
|
9
|
+
} from '../../../../../../playwright/utils/requests';
|
|
10
|
+
|
|
11
|
+
const pageUrl = 's/quantic-tab';
|
|
12
|
+
|
|
13
|
+
interface TabOptions {}
|
|
14
|
+
|
|
15
|
+
type QuanticTabE2EFixtures = {
|
|
16
|
+
tab: TabObject;
|
|
17
|
+
search: SearchObject;
|
|
18
|
+
options: Partial<TabOptions>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type QuanticTabE2ESearchFixtures = QuanticTabE2EFixtures & {
|
|
22
|
+
urlHash: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type QuanticTabE2EInsightFixtures = QuanticTabE2EFixtures & {
|
|
26
|
+
insightSetup: InsightSetupObject;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const testSearch = quanticBase.extend<QuanticTabE2ESearchFixtures>({
|
|
30
|
+
options: {},
|
|
31
|
+
urlHash: '',
|
|
32
|
+
search: async ({page}, use) => {
|
|
33
|
+
await use(new SearchObject(page, searchRequestRegex));
|
|
34
|
+
},
|
|
35
|
+
tab: async ({page, options, configuration, search, urlHash}, use) => {
|
|
36
|
+
await page.goto(urlHash ? `${pageUrl}#${urlHash}` : pageUrl);
|
|
37
|
+
configuration.configure(options);
|
|
38
|
+
await search.waitForSearchResponse();
|
|
39
|
+
|
|
40
|
+
await use(new TabObject(page));
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const testInsight = quanticBase.extend<QuanticTabE2EInsightFixtures>({
|
|
45
|
+
options: {},
|
|
46
|
+
search: async ({page}, use) => {
|
|
47
|
+
await use(new SearchObject(page, insightSearchRequestRegex));
|
|
48
|
+
},
|
|
49
|
+
insightSetup: async ({page}, use) => {
|
|
50
|
+
await use(new InsightSetupObject(page));
|
|
51
|
+
},
|
|
52
|
+
tab: async ({page, options, search, configuration, insightSetup}, use) => {
|
|
53
|
+
await page.goto(pageUrl);
|
|
54
|
+
configuration.configure({...options, useCase: useCaseEnum.insight});
|
|
55
|
+
await insightSetup.waitForInsightInterfaceInitialization();
|
|
56
|
+
await search.performSearch();
|
|
57
|
+
await search.waitForSearchResponse();
|
|
58
|
+
await use(new TabObject(page));
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export {expect} from '@playwright/test';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type {Locator, Page, Request, Response} from '@playwright/test';
|
|
2
|
+
import {isUaSearchEvent} from '../../../../../../playwright/utils/requests';
|
|
3
|
+
|
|
4
|
+
export class TabObject {
|
|
5
|
+
constructor(public page: Page) {
|
|
6
|
+
this.page = page;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get tab(): Locator {
|
|
10
|
+
return this.page.locator('c-quantic-tab');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
tabButton(tabLabel): Locator {
|
|
14
|
+
return this.tab.getByRole('button', {name: new RegExp(`^${tabLabel}$`)});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get activeTabLabel(): Promise<string | null> {
|
|
18
|
+
return this.tab.locator('button.slds-is-active').textContent();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async clickTabButton(tabLabel: string): Promise<void> {
|
|
22
|
+
await this.tabButton(tabLabel).click();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async waitForTabSearchUaAnalytics(
|
|
26
|
+
actionCause,
|
|
27
|
+
customChecker?: Function
|
|
28
|
+
): Promise<Request> {
|
|
29
|
+
const uaRequest = this.page.waitForRequest((request) => {
|
|
30
|
+
if (isUaSearchEvent(request)) {
|
|
31
|
+
const requestBody = request.postDataJSON?.();
|
|
32
|
+
const {customData} = requestBody;
|
|
33
|
+
|
|
34
|
+
const expectedFields = {
|
|
35
|
+
actionCause: actionCause,
|
|
36
|
+
originContext: 'Search',
|
|
37
|
+
};
|
|
38
|
+
const matchesExpectedFields = Object.keys(expectedFields).every(
|
|
39
|
+
(key) => requestBody?.[key] === expectedFields[key]
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
matchesExpectedFields &&
|
|
44
|
+
(customChecker ? customChecker(customData) : true)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
});
|
|
49
|
+
return uaRequest;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async waitForTabSelectUaAnalytics(expectedFields: object): Promise<Request> {
|
|
53
|
+
return this.waitForTabSearchUaAnalytics(
|
|
54
|
+
'interfaceChange',
|
|
55
|
+
(customData: object) => {
|
|
56
|
+
return Object.keys(expectedFields).every(
|
|
57
|
+
(key) => customData?.[key] === expectedFields[key]
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
extractActionCauseFromSearchResponse(response: Response) {
|
|
64
|
+
const {analytics} = response.request().postDataJSON();
|
|
65
|
+
return analytics.actionCause;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
const expectedActionCause = 'interfaceChange';
|
|
13
|
+
const exampleTabs = ['All', 'Case', 'Knowledge'];
|
|
14
|
+
|
|
15
|
+
useCaseTestCases.forEach((useCase) => {
|
|
16
|
+
let test;
|
|
17
|
+
if (useCase.value === useCaseEnum.search) {
|
|
18
|
+
test = fixtures[useCase.value] as typeof testSearch;
|
|
19
|
+
} else {
|
|
20
|
+
test = fixtures[useCase.value] as typeof testInsight;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
test.describe(`quantic tab ${useCase.label}`, () => {
|
|
24
|
+
test.describe('when clicking on a tab', () => {
|
|
25
|
+
test('should trigger a new search and send the correct UA analytics event', async ({
|
|
26
|
+
tab,
|
|
27
|
+
search,
|
|
28
|
+
}) => {
|
|
29
|
+
const selectedTabIndex = 0;
|
|
30
|
+
const searchResponsePromise = search.waitForSearchResponse();
|
|
31
|
+
const uaRequestPromise = tab.waitForTabSelectUaAnalytics({
|
|
32
|
+
interfaceChangeTo: exampleTabs[selectedTabIndex],
|
|
33
|
+
});
|
|
34
|
+
await tab.clickTabButton(exampleTabs[selectedTabIndex]);
|
|
35
|
+
|
|
36
|
+
const searchResponse = await searchResponsePromise;
|
|
37
|
+
await uaRequestPromise;
|
|
38
|
+
|
|
39
|
+
const actionCause =
|
|
40
|
+
tab.extractActionCauseFromSearchResponse(searchResponse);
|
|
41
|
+
expect(actionCause).toEqual(expectedActionCause);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (useCase.value === useCaseEnum.search) {
|
|
46
|
+
test.describe('when loading selected tab from URL', () => {
|
|
47
|
+
const expectedTab = exampleTabs[2];
|
|
48
|
+
test.use({
|
|
49
|
+
urlHash: `tab=${expectedTab}`,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('should make the right tab active', async ({tab}) => {
|
|
53
|
+
expect(await tab.activeTabLabel).toBe(expectedTab);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
test.describe('when testing accessibility', () => {
|
|
59
|
+
test('should be accessible to keyboard', async ({tab, page}) => {
|
|
60
|
+
await tab.clickTabButton(exampleTabs[0]);
|
|
61
|
+
|
|
62
|
+
let activeTabLabel = await tab.activeTabLabel;
|
|
63
|
+
expect(activeTabLabel).toEqual(exampleTabs[0]);
|
|
64
|
+
|
|
65
|
+
await page.keyboard.press('Tab');
|
|
66
|
+
await page.keyboard.press('Enter');
|
|
67
|
+
activeTabLabel = await tab.activeTabLabel;
|
|
68
|
+
expect(activeTabLabel).toEqual(exampleTabs[1]);
|
|
69
|
+
|
|
70
|
+
await page.keyboard.press('Shift+Tab');
|
|
71
|
+
await page.keyboard.press('Space');
|
|
72
|
+
activeTabLabel = await tab.activeTabLabel;
|
|
73
|
+
expect(activeTabLabel).toEqual(exampleTabs[0]);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|