@coveo/quantic 3.12.1 → 3.13.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.
Files changed (26) hide show
  1. package/force-app/main/default/lwc/quanticFeedback/__tests__/quanticFeedback.test.js +2 -2
  2. package/force-app/main/default/lwc/quanticFeedback/quanticFeedback.html +3 -3
  3. package/force-app/main/default/lwc/quanticFeedbackModal/error.html +1 -1
  4. package/force-app/main/default/lwc/quanticFeedbackModal/feedbackForm.html +2 -2
  5. package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/data.ts +1 -1
  6. package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/pageObject.ts +4 -0
  7. package/force-app/main/default/lwc/quanticGeneratedAnswer/e2e/quanticGeneratedAnswer.e2e.ts +22 -1
  8. package/force-app/main/default/lwc/quanticGeneratedAnswer/quanticGeneratedAnswer.js +19 -7
  9. package/force-app/main/default/lwc/quanticGeneratedAnswer/templates/generatedAnswer.html +1 -0
  10. package/force-app/main/default/lwc/quanticGeneratedAnswerContent/quanticGeneratedAnswerContent.js +2 -0
  11. package/force-app/main/default/lwc/quanticSmartSnippet/__tests__/quanticSmartSnippet.test.js +357 -0
  12. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/data.ts +30 -0
  13. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/fixture.ts +87 -0
  14. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/pageObject.ts +188 -0
  15. package/force-app/main/default/lwc/quanticSmartSnippet/e2e/quanticSmartSnippet.e2e.ts +118 -0
  16. package/force-app/main/default/lwc/quanticSmartSnippet/quanticSmartSnippet.html +1 -1
  17. package/force-app/main/default/lwc/quanticSmartSnippet/quanticSmartSnippet.js +2 -2
  18. package/force-app/main/default/lwc/quanticSmartSnippetSource/quanticSmartSnippetSource.html +2 -2
  19. package/force-app/main/default/lwc/quanticTabBar/e2e/quanticTabBar.e2e.ts +1 -1
  20. package/force-app/main/default/staticresources/coveoheadless/case-assist/headless.js +7 -8
  21. package/force-app/main/default/staticresources/coveoheadless/definitions/features/commerce/common/actions.d.ts +1 -0
  22. package/force-app/main/default/staticresources/coveoheadless/definitions/tsdoc-metadata.json +1 -1
  23. package/force-app/main/default/staticresources/coveoheadless/headless.js +9 -10
  24. package/force-app/main/default/staticresources/coveoheadless/insight/headless.js +8 -9
  25. package/force-app/main/default/staticresources/coveoheadless/recommendation/headless.js +7 -8
  26. package/package.json +5 -5
@@ -34,9 +34,9 @@ jest.mock(
34
34
 
35
35
  const selectors = {
36
36
  feedbackQuestion: '.feedback__question',
37
- likeButton: 'c-quantic-stateful-button[data-cy="feedback__like-button"]',
37
+ likeButton: 'c-quantic-stateful-button[data-testid="feedback__like-button"]',
38
38
  dislikeButton:
39
- 'c-quantic-stateful-button[data-cy="feedback__dislike-button"]',
39
+ 'c-quantic-stateful-button[data-testid="feedback__dislike-button"]',
40
40
  successMessage: '.feedback__success-message',
41
41
  explainWhyButton: '.feedback__explain-why',
42
42
  };
@@ -2,10 +2,10 @@
2
2
  <div class="slds-grid feedback__main-section">
3
3
  <span class="slds-var-p-right_small slds-text-color_weak feedback__question"
4
4
  id="feedback__question">{question}</span>
5
- <c-quantic-stateful-button selected={liked} data-cy="feedback__like-button" tooltip={likeLabel}
5
+ <c-quantic-stateful-button selected={liked} data-testid="feedback__like-button" tooltip={likeLabel}
6
6
  icon-name={likeIconName} onquantic__select={handleLike} onquantic__deselect={handleLike} without-borders selected-state-color="#2e844a"
7
7
  label={likeButtonLabel} icon-size={size}></c-quantic-stateful-button>
8
- <c-quantic-stateful-button selected={disliked} data-cy="feedback__dislike-button" tooltip={dislikeLabel}
8
+ <c-quantic-stateful-button selected={disliked} data-testid="feedback__dislike-button" tooltip={dislikeLabel}
9
9
  icon-name={dislikeIconName} onquantic__select={handleDislike} onquantic__deselect={handleDislike} without-borders selected-state-color="#ea001e"
10
10
  label={dislikeButtonLabel} icon-size={size}></c-quantic-stateful-button>
11
11
  </div>
@@ -13,7 +13,7 @@
13
13
  <div class="slds-grid feedback__success-message">
14
14
  <span class="slds-var-p-vertical_x-small">{successMessage}</span>
15
15
  <template if:false={hideExplainWhyButton}>
16
- <lightning-button data-cy="feedback__explain-why-button" class="slds-var-m-left_x-small feedback__explain-why"
16
+ <lightning-button data-testid="feedback__explain-why-button" class="slds-var-m-left_x-small feedback__explain-why"
17
17
  variant="base" label={labels.explainWhy} onclick={handlePressExplainWhyButton}></lightning-button>
18
18
  </template>
19
19
  </div>
@@ -3,7 +3,7 @@
3
3
  <div data-cy="feedback-modal-body__error" class="error-message slds-text-color_destructive">{error}</div>
4
4
  </lightning-modal-body>
5
5
  <lightning-modal-footer>
6
- <lightning-button data-cy="feedback-modal-footer__cancel" class="slds-button" variant="neutral"
6
+ <lightning-button data-testid="feedback-modal-footer__cancel" class="slds-button" variant="neutral"
7
7
  label={labels.cancel} onclick={closeModal}></lightning-button>
8
8
  </lightning-modal-footer>
9
9
  </template>
@@ -15,9 +15,9 @@
15
15
  </div>
16
16
  </lightning-modal-body>
17
17
  <lightning-modal-footer>
18
- <lightning-button data-cy="feedback-modal-footer__cancel" class="slds-button" variant="neutral" label={labels.cancel}
18
+ <lightning-button data-testid="feedback-modal-footer__cancel" class="slds-button" variant="neutral" label={labels.cancel}
19
19
  onclick={closeModal}></lightning-button>
20
- <lightning-button data-cy="feedback-modal-footer__submit" class="slds-button slds-m-left_x-small feedback-modal-footer__submit" variant="brand"
20
+ <lightning-button data-testid="feedback-modal-footer__submit" class="slds-button slds-m-left_x-small feedback-modal-footer__submit" variant="brand"
21
21
  label={labels.sendFeedback} onclick={handleSubmitFeedback}></lightning-button>
22
22
  </lightning-modal-footer>
23
23
  </template>
@@ -3,7 +3,7 @@ const genQaMarkdownTextPayload = {
3
3
  payloadType: 'genqa.messageType',
4
4
  payload: JSON.stringify({
5
5
  textDelta:
6
- 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.',
6
+ 'THIS IS SOME LOREM IPSUM: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin accumsan felis vel nulla venenatis, vel volutpat mauris suscipit. Praesent aliquam, ex et dapibus fermentum, ligula metus condimentum nunc, non vehicula magna magna a nulla. Integer efficitur nunc eget semper facilisis. Quisque nec tortor at nunc blandit dictum sit amet vel mauris. Duis at tellus sit amet mi pharetra tincidunt. Nullam id risus eget risus accumsan molestie ac quis velit. Vivamus consectetur nisi vel enim finibus, nec laoreet risus facilisis. Integer a lacinia ligula. Etiam cursus urna nisi, ut tincidunt elit consectetur quis. Pellentesque nec sem vel neque malesuada euismod vitae nec augue. Suspendisse non ligula eu purus posuere dictum quis et magna. Curabitur dignissim, magna non feugiat consectetur, lorem orci fringilla sapien, sit amet vehicula eros nulla eget enim. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin accumsan felis vel nulla venenatis, vel volutpat mauris suscipit. Praesent aliquam, ex et dapibus fermentum, ligula metus condimentum nunc, non vehicula magna magna a nulla. Integer efficitur nunc eget semper facilisis. Quisque nec tortor at nunc blandit dictum sit amet vel mauris. Duis at tellus sit amet mi pharetra tincidunt. Nullam id risus eget risus accumsan molestie ac quis velit. Vivamus consectetur nisi vel enim finibus, nec laoreet risus facilisis. Integer a lacinia ligula. Etiam cursus urna nisi, ut tincidunt elit consectetur quis. Pellentesque nec sem vel neque malesuada euismod vitae nec augue. Suspendisse non ligula eu purus posuere dictum quis et magna. Curabitur dignissim, magna non feugiat consectetur, lorem orci fringilla sapien, sit amet vehicula eros nulla eget enim.',
7
7
  }),
8
8
  finishReason: 'COMPLETED',
9
9
  };
@@ -63,6 +63,10 @@ export class GeneratedAnswerObject {
63
63
  .locator('.citation__link');
64
64
  }
65
65
 
66
+ get showMoreButton(): Locator {
67
+ return this.page.getByTestId('generated-answer__answer-toggle');
68
+ }
69
+
66
70
  async hoverOverCitation(index: number): Promise<void> {
67
71
  // waiting 500ms to allow the component to render completely, cause any re-rendering abort the hover action.
68
72
  await this.page.waitForTimeout(500);
@@ -1,4 +1,4 @@
1
- import {testSearch, testInsight} from './fixture';
1
+ import {testSearch, testInsight, expect} from './fixture';
2
2
  import {useCaseTestCases} from '../../../../../../playwright/utils/useCase';
3
3
  import genQaData from './data';
4
4
 
@@ -174,5 +174,26 @@ useCaseTestCases.forEach((useCase) => {
174
174
  });
175
175
  });
176
176
  });
177
+
178
+ test.describe('when the answer is generated in a single shot and the answer exceeds the maximum height', () => {
179
+ test.use({
180
+ options: {
181
+ collapsible: true,
182
+ },
183
+ });
184
+ test('should display the answer as collapsed', async ({
185
+ generatedAnswer,
186
+ }) => {
187
+ const expectedShowMoreLabel = 'Show more';
188
+ await generatedAnswer.waitForStreamEndUaAnalytics();
189
+
190
+ const showMoreButton = generatedAnswer.showMoreButton;
191
+ expect(showMoreButton).not.toBeNull();
192
+
193
+ const showMoreButtonLabel = await showMoreButton.textContent();
194
+ expect(showMoreButtonLabel).not.toBeNull();
195
+ expect(showMoreButtonLabel).toEqual(expectedShowMoreLabel);
196
+ });
197
+ });
177
198
  });
178
199
  });
@@ -151,13 +151,7 @@ export default class QuanticGeneratedAnswer extends LightningElement {
151
151
  renderedCallback() {
152
152
  initializeWithHeadless(this, this.engineId, this.initialize);
153
153
  if (this.collapsible) {
154
- // If we are still streaming add a little extra height to the answer element to account for the next answer chunk.
155
- // This helps a lot with the jankyness of the answer fading out when the chunk is close but not yet over the max height.
156
- const answerElementHeight = this.isStreaming
157
- ? this.generatedAnswerElementHeight + 50
158
- : this.generatedAnswerElementHeight;
159
- this._exceedsMaximumHeight =
160
- answerElementHeight > this._maximumAnswerHeight;
154
+ this._exceedsMaximumHeight = this.isMaximumHeightExceeded();
161
155
  }
162
156
  }
163
157
 
@@ -224,6 +218,16 @@ export default class QuanticGeneratedAnswer extends LightningElement {
224
218
  }
225
219
  }
226
220
 
221
+ isMaximumHeightExceeded() {
222
+ // If we are still streaming add a little extra height to the answer element to account for the next answer chunk.
223
+ // This helps a lot with the jankyness of the answer fading out when the chunk is close but not yet over the max height.
224
+ const answerElementHeight = this.isStreaming
225
+ ? this.generatedAnswerElementHeight + 50
226
+ : this.generatedAnswerElementHeight;
227
+
228
+ return answerElementHeight > this._maximumAnswerHeight;
229
+ }
230
+
227
231
  getGeneratedAnswerStatus() {
228
232
  if (!this.state.isVisible) {
229
233
  return this.labels.generatedAnswerIsHidden;
@@ -348,6 +352,14 @@ export default class QuanticGeneratedAnswer extends LightningElement {
348
352
  }
349
353
  };
350
354
 
355
+ handleAnswerContentUpdated = (event) => {
356
+ event.stopPropagation();
357
+ if (this.collapsible) {
358
+ this._exceedsMaximumHeight = this.isMaximumHeightExceeded();
359
+ }
360
+ this.updateGeneratedAnswerCSSVariables();
361
+ };
362
+
351
363
  handleToggleCollapseAnswer() {
352
364
  this.state?.expanded
353
365
  ? this.generatedAnswer.collapse()
@@ -53,6 +53,7 @@
53
53
  answer-content-format={answerContentFormat}
54
54
  answer={answer}
55
55
  is-streaming={isStreaming}
56
+ onquantic__answercontentupdated={handleAnswerContentUpdated}
56
57
  data-cy="generated-answer__content"
57
58
  >
58
59
  </c-quantic-generated-answer-content>
@@ -11,6 +11,7 @@ import generatedTextContentTemplate from './templates/generatedTextContent.html'
11
11
  /**
12
12
  * The `QuanticGeneratedAnswerContent` component displays the generated answer content.
13
13
  * @category Internal
14
+ * @fires CustomEvent#quantic__answercontentupdated
14
15
  * @example
15
16
  * <c-quantic-generated-answer-content answer-content-format={answerContentFormat} answer={answer} is-streaming={isStreaming}></c-quantic-generated-answer-content>
16
17
  */
@@ -110,6 +111,7 @@ export default class QuanticGeneratedAnswerContent extends LightningElement {
110
111
  else {
111
112
  answerContainer.textContent = this.answer;
112
113
  }
114
+ this.dispatchEvent(new CustomEvent('quantic__answercontentupdated'));
113
115
  }
114
116
 
115
117
  get generatedAnswerContentClass() {
@@ -0,0 +1,357 @@
1
+ /* eslint-disable jest/no-conditional-expect */
2
+ /* eslint-disable no-import-assign */
3
+ import QuanticSmartSnippet from '../quanticSmartSnippet';
4
+ // @ts-ignore
5
+ import {createElement} from 'lwc';
6
+ import * as mockHeadlessLoader from 'c/quanticHeadlessLoader';
7
+
8
+ let mockAnswerHeight = 300;
9
+
10
+ jest.mock('c/quanticHeadlessLoader');
11
+ jest.mock('c/quanticUtils', () => ({
12
+ getAbsoluteHeight: jest.fn(() => {
13
+ return mockAnswerHeight;
14
+ }),
15
+ I18nUtils: {
16
+ format: jest.fn(),
17
+ },
18
+ LinkUtils: {
19
+ bindAnalyticsToLink: jest.fn(),
20
+ },
21
+ }));
22
+
23
+ jest.mock(
24
+ '@salesforce/label/c.quantic_SmartSnippetShowMore',
25
+ () => ({default: 'Show more'}),
26
+ {
27
+ virtual: true,
28
+ }
29
+ );
30
+
31
+ jest.mock(
32
+ '@salesforce/label/c.quantic_SmartSnippetShowLess',
33
+ () => ({default: 'Show less'}),
34
+ {
35
+ virtual: true,
36
+ }
37
+ );
38
+
39
+ let isInitialized = false;
40
+
41
+ const exampleEngine = {
42
+ id: 'exampleEngineId',
43
+ };
44
+
45
+ const defaultOptions = {
46
+ engineId: exampleEngine.id,
47
+ };
48
+
49
+ const selectors = {
50
+ initializationError: 'c-quantic-component-error',
51
+ smartSnippet: 'c-quantic-smart-snippet',
52
+ smartSnippetAnswer: 'c-quantic-smart-snippet-answer',
53
+ smartSnippetToggleButton: '[data-testid="smart-snippet__toggle-button"]',
54
+ smartSnippetSource: 'c-quantic-smart-snippet-source',
55
+ smartSnippetFeedback: 'c-quantic-feedback',
56
+ };
57
+
58
+ const defaultSearchStatusState = {
59
+ hasResults: true,
60
+ firstSearchExecuted: true,
61
+ };
62
+
63
+ let searchStatusState = defaultSearchStatusState;
64
+
65
+ const mockSmartSnippetSource = {
66
+ title: 'The Lord of the Rings',
67
+ uri: 'https://en.wikipedia.org/wiki/The_Lord_of_the_Rings',
68
+ };
69
+
70
+ const defaultSmartSnippetState = {
71
+ question: 'Where was Gondor when Westfold fell?',
72
+ answer: 'Gondor was obviously busy with other things.',
73
+ documentId: '1',
74
+ expanded: false,
75
+ answerFound: true,
76
+ liked: false,
77
+ disliked: false,
78
+ feedbackModalOpen: false,
79
+ source: mockSmartSnippetSource,
80
+ };
81
+
82
+ let smartSnippetState = defaultSmartSnippetState;
83
+
84
+ const functionsMocks = {
85
+ buildSmartSnippet: jest.fn(() => ({
86
+ state: smartSnippetState,
87
+ subscribe: functionsMocks.smartSnippetStateSubscriber,
88
+ expand: functionsMocks.expand,
89
+ collapse: functionsMocks.collapse,
90
+ })),
91
+ buildSearchStatus: jest.fn(() => ({
92
+ state: searchStatusState,
93
+ subscribe: functionsMocks.searchStatusStateSubscriber,
94
+ })),
95
+ smartSnippetStateSubscriber: jest.fn((cb) => {
96
+ cb();
97
+ return functionsMocks.smartSnippetStateUnsubscriber;
98
+ }),
99
+ searchStatusStateSubscriber: jest.fn((cb) => {
100
+ cb();
101
+ return functionsMocks.searchStatusStateUnsubscriber;
102
+ }),
103
+ smartSnippetStateUnsubscriber: jest.fn(),
104
+ searchStatusStateUnsubscriber: jest.fn(),
105
+ expand: jest.fn(),
106
+ collapse: jest.fn(),
107
+ };
108
+
109
+ function createTestComponent(options = defaultOptions) {
110
+ const element = createElement('c-quantic-smart-snippet', {
111
+ is: QuanticSmartSnippet,
112
+ });
113
+ for (const [key, value] of Object.entries(options)) {
114
+ element[key] = value;
115
+ }
116
+ document.body.appendChild(element);
117
+ return element;
118
+ }
119
+
120
+ // Helper function to wait until the microtask queue is empty.
121
+ function flushPromises() {
122
+ return new Promise((resolve) => setTimeout(resolve, 0));
123
+ }
124
+
125
+ function prepareHeadlessState() {
126
+ // @ts-ignore
127
+ mockHeadlessLoader.getHeadlessBundle = () => {
128
+ return {
129
+ buildSmartSnippet: functionsMocks.buildSmartSnippet,
130
+ buildSearchStatus: functionsMocks.buildSearchStatus,
131
+ };
132
+ };
133
+ }
134
+
135
+ function mockSuccessfulHeadlessInitialization() {
136
+ // @ts-ignore
137
+ mockHeadlessLoader.initializeWithHeadless = (element, _, initialize) => {
138
+ if (element instanceof QuanticSmartSnippet && !isInitialized) {
139
+ isInitialized = true;
140
+ initialize(exampleEngine);
141
+ }
142
+ };
143
+ }
144
+
145
+ function mockErroneousHeadlessInitialization() {
146
+ // @ts-ignore
147
+ mockHeadlessLoader.initializeWithHeadless = (element) => {
148
+ if (element instanceof QuanticSmartSnippet) {
149
+ element.setInitializationError();
150
+ }
151
+ };
152
+ }
153
+
154
+ function cleanup() {
155
+ // The jsdom instance is shared across test cases in a single file so reset the DOM
156
+ while (document.body.firstChild) {
157
+ document.body.removeChild(document.body.firstChild);
158
+ }
159
+ jest.clearAllMocks();
160
+ isInitialized = false;
161
+ }
162
+
163
+ describe('c-quantic-smart-snippet', () => {
164
+ afterEach(() => {
165
+ smartSnippetState = defaultSmartSnippetState;
166
+ searchStatusState = defaultSearchStatusState;
167
+ cleanup();
168
+ });
169
+
170
+ describe('controller initialization', () => {
171
+ beforeEach(() => {
172
+ mockSuccessfulHeadlessInitialization();
173
+ prepareHeadlessState();
174
+ });
175
+
176
+ it('should build the smart snippet controller with the proper parameters and subscribe to its state change', async () => {
177
+ createTestComponent();
178
+ await flushPromises();
179
+
180
+ expect(functionsMocks.buildSmartSnippet).toHaveBeenCalledTimes(1);
181
+ expect(functionsMocks.buildSmartSnippet).toHaveBeenCalledWith(
182
+ exampleEngine
183
+ );
184
+ expect(functionsMocks.smartSnippetStateSubscriber).toHaveBeenCalledTimes(
185
+ 1
186
+ );
187
+ });
188
+
189
+ it('should build the search status controller with the proper parameters and subscribe to its state change', async () => {
190
+ createTestComponent();
191
+ await flushPromises();
192
+
193
+ expect(functionsMocks.buildSearchStatus).toHaveBeenCalledTimes(1);
194
+ expect(functionsMocks.buildSearchStatus).toHaveBeenCalledWith(
195
+ exampleEngine
196
+ );
197
+ expect(functionsMocks.searchStatusStateSubscriber).toHaveBeenCalledTimes(
198
+ 1
199
+ );
200
+ });
201
+ });
202
+
203
+ describe('when an initialization error occurs', () => {
204
+ beforeEach(() => {
205
+ mockErroneousHeadlessInitialization();
206
+ });
207
+
208
+ it('should display the initialization error component', async () => {
209
+ const element = createTestComponent();
210
+ await flushPromises();
211
+
212
+ const initializationError = element.shadowRoot.querySelector(
213
+ selectors.initializationError
214
+ );
215
+
216
+ expect(initializationError).not.toBeNull();
217
+ });
218
+ });
219
+
220
+ describe('when the query does not return a smart snippet', () => {
221
+ beforeAll(() => {
222
+ smartSnippetState = {...defaultSmartSnippetState, answerFound: false};
223
+ });
224
+ it('should not display the smart snippet component', async () => {
225
+ const element = createTestComponent();
226
+ await flushPromises();
227
+
228
+ const smartSnippet = element.shadowRoot.querySelector(
229
+ selectors.smartSnippet
230
+ );
231
+ expect(smartSnippet).toBeNull();
232
+ });
233
+ });
234
+
235
+ describe('when the query returns a smart snippet', () => {
236
+ beforeEach(() => {
237
+ mockSuccessfulHeadlessInitialization();
238
+ prepareHeadlessState();
239
+ smartSnippetState = defaultSmartSnippetState;
240
+ });
241
+
242
+ afterEach(() => {
243
+ smartSnippetState = defaultSmartSnippetState;
244
+ });
245
+
246
+ it('should properly display the smart snippet', async () => {
247
+ const element = createTestComponent();
248
+ await flushPromises();
249
+
250
+ const smartSnippetAnswer = element.shadowRoot.querySelector(
251
+ selectors.smartSnippetAnswer
252
+ );
253
+
254
+ expect(smartSnippetAnswer).not.toBeNull();
255
+ expect(smartSnippetAnswer.answer).toEqual(smartSnippetState.answer);
256
+
257
+ const smartSnippetSource = element.shadowRoot.querySelector(
258
+ selectors.smartSnippetSource
259
+ );
260
+ expect(smartSnippetSource).not.toBeNull();
261
+ expect(smartSnippetSource.source).toEqual(smartSnippetState.source);
262
+
263
+ const smartSnippetFeedback = element.shadowRoot.querySelector(
264
+ selectors.smartSnippetFeedback
265
+ );
266
+ expect(smartSnippetFeedback).not.toBeNull();
267
+ });
268
+
269
+ describe('when the smart snippet exceeds the maximum height', () => {
270
+ describe('when the smart snippet is collapsed', () => {
271
+ it('should properly display the toggle button of the smart snippet component', async () => {
272
+ const expectedShowMoreLabel = 'Show more';
273
+ const expectedShowMoreIcon = 'utility:chevrondown';
274
+ const element = createTestComponent();
275
+ await flushPromises();
276
+
277
+ const smartSnippetToggleButton = element.shadowRoot.querySelector(
278
+ selectors.smartSnippetToggleButton
279
+ );
280
+
281
+ expect(smartSnippetToggleButton).not.toBeNull();
282
+ expect(smartSnippetToggleButton.label).toBe(expectedShowMoreLabel);
283
+ expect(smartSnippetToggleButton.iconName).toBe(expectedShowMoreIcon);
284
+ });
285
+
286
+ describe('when clicking on the smart snippet toggle button', () => {
287
+ it('should call the expand method from the smartSnippet controller', async () => {
288
+ const element = createTestComponent();
289
+ await flushPromises();
290
+
291
+ const smartSnippetToggleButton = element.shadowRoot.querySelector(
292
+ selectors.smartSnippetToggleButton
293
+ );
294
+ expect(smartSnippetToggleButton).not.toBeNull();
295
+
296
+ await smartSnippetToggleButton.click();
297
+ await flushPromises();
298
+
299
+ expect(functionsMocks.expand).toHaveBeenCalledTimes(1);
300
+ });
301
+ });
302
+ });
303
+
304
+ describe('when the smart snippet is expanded', () => {
305
+ beforeEach(() => {
306
+ smartSnippetState = {...defaultSmartSnippetState, expanded: true};
307
+ });
308
+
309
+ it('should properly display the smart snippet component', async () => {
310
+ const expectedShowLessLabel = 'Show less';
311
+ const expectedShowLessIcon = 'utility:chevronup';
312
+ const element = createTestComponent();
313
+ await flushPromises();
314
+
315
+ const smartSnippetToggleButton = element.shadowRoot.querySelector(
316
+ selectors.smartSnippetToggleButton
317
+ );
318
+ expect(smartSnippetToggleButton).not.toBeNull();
319
+ expect(smartSnippetToggleButton.label).toBe(expectedShowLessLabel);
320
+ expect(smartSnippetToggleButton.iconName).toBe(expectedShowLessIcon);
321
+ });
322
+
323
+ describe('when clicking on the smart snippet toggle button', () => {
324
+ it('should call the collapse method from the smartSnippet controller', async () => {
325
+ const element = createTestComponent();
326
+ await flushPromises();
327
+
328
+ const smartSnippetToggleButton = element.shadowRoot.querySelector(
329
+ selectors.smartSnippetToggleButton
330
+ );
331
+
332
+ await smartSnippetToggleButton.click();
333
+ await flushPromises();
334
+
335
+ expect(functionsMocks.collapse).toHaveBeenCalledTimes(1);
336
+ });
337
+ });
338
+ });
339
+ });
340
+
341
+ describe('when interacting with the feedback modal', () => {
342
+ describe('when trying to open the feedback modal after executing the same query', () => {
343
+ // eslint-disable-next-line jest/no-disabled-tests, jest/expect-expect
344
+ it.skip('should not open the feedback modal', async () => {
345
+ // TODO: Implement this test - SFINT-5933
346
+ });
347
+ });
348
+
349
+ describe('when trying to open the feedback modal after executing a query that gave a new answer', () => {
350
+ // eslint-disable-next-line jest/no-disabled-tests, jest/expect-expect
351
+ it.skip('should open the feedback modal', async () => {
352
+ // TODO: Implement this test - SFINT-5933
353
+ });
354
+ });
355
+ });
356
+ });
357
+ });
@@ -0,0 +1,30 @@
1
+ const exampleQuestion = 'Where was Gondor when the Westfold fell?';
2
+ const exampleAnswerSnippet = `<a href="#">Gondor</a> was on the brink of destruction when the Westfold fell. Gondor did not come to Rohan's aid when the Westfold fell because it was overwhelmed by its own dire circumstances and unable to spare resources or manpower. The alliance between the two kingdoms, forged by the Oath of Eorl, was based on a promise of mutual defense in times of extreme need. However, by the time of the War of the Ring, Gondor was facing unprecedented threats from Sauron, whose forces in Mordor were massing for a full-scale assault on Minas Tirith. The Steward of Gondor, Denethor II, was deeply concerned about the security of his own kingdom and could not afford to weaken its defenses to send aid across the vast distances that separated Gondor from the Westfold. Even if assistance had been feasible, the logistical challenge of moving troops through potentially hostile territory would have delayed their arrival, rendering their efforts ineffective. Moreover, the threat to Rohan came not only from Sauron's influence but also from the unexpected betrayal of Saruman, who, until then, had been perceived as an ally. His treachery, combined with the swiftness and brutality of his attacks, left Rohan vulnerable and isolated, as neither Rohan nor Gondor had anticipated such aggression from Isengard. While the alliance between the two realms remained strong in spirit, Gondor's immediate need to safeguard its own survival against the growing shadow of Mordor took precedence, leaving Rohan to fend for itself during the fall of the Westfold.`;
3
+ const exampleScore = 0.42;
4
+ const exampleContentIdKey = 'permanentid';
5
+ const mockPermanentId = '1234';
6
+ const exampleContentIdValue = mockPermanentId;
7
+
8
+ export type QuestionAnswerData = {
9
+ answerFound: boolean;
10
+ question: string;
11
+ answerSnippet: string;
12
+ documentId: {
13
+ contentIdKey: string;
14
+ contentIdValue: string;
15
+ };
16
+ score: number;
17
+ };
18
+
19
+ const smartSnippetData: QuestionAnswerData = {
20
+ answerFound: true,
21
+ question: exampleQuestion,
22
+ answerSnippet: exampleAnswerSnippet,
23
+ documentId: {
24
+ contentIdKey: exampleContentIdKey,
25
+ contentIdValue: exampleContentIdValue,
26
+ },
27
+ score: exampleScore,
28
+ };
29
+
30
+ export default smartSnippetData;
@@ -0,0 +1,87 @@
1
+ import {SmartSnippetObject} from './pageObject';
2
+ import {quanticBase} from '../../../../../../playwright/fixtures/baseFixture';
3
+ import {SearchObject} from '../../../../../../playwright/page-object/searchObject';
4
+ import {
5
+ searchRequestRegex,
6
+ insightSearchRequestRegex,
7
+ } from '../../../../../../playwright/utils/requests';
8
+ import {InsightSetupObject} from '../../../../../../playwright/page-object/insightSetupObject';
9
+ import {useCaseEnum} from '../../../../../../playwright/utils/useCase';
10
+ import type {QuestionAnswerData} from './data';
11
+ import smartSnippetData from './data';
12
+
13
+ const pageUrl = 's/quantic-smart-snippet';
14
+
15
+ interface SmartSnippetOptions {
16
+ maximumSnippetHeight: number;
17
+ }
18
+
19
+ type QuanticSmartSnippetE2ESearchFixtures = {
20
+ smartSnippetData: QuestionAnswerData;
21
+ smartSnippet: SmartSnippetObject;
22
+ search: SearchObject;
23
+ options: Partial<SmartSnippetOptions>;
24
+ };
25
+
26
+ type QuanticSmartSnippetE2EInsightFixtures =
27
+ QuanticSmartSnippetE2ESearchFixtures & {
28
+ insightSetup: InsightSetupObject;
29
+ };
30
+
31
+ export const testSearch =
32
+ quanticBase.extend<QuanticSmartSnippetE2ESearchFixtures>({
33
+ smartSnippetData,
34
+ options: {},
35
+ search: async ({page}, use) => {
36
+ await use(new SearchObject(page, searchRequestRegex));
37
+ },
38
+ smartSnippet: async (
39
+ {page, options, configuration, search, smartSnippetData: data},
40
+ use
41
+ ) => {
42
+ const smartSnippetObject = new SmartSnippetObject(page);
43
+
44
+ await page.goto(pageUrl);
45
+ await search.mockSearchWithSmartSnippetResponse(data);
46
+
47
+ configuration.configure(options);
48
+ await search.waitForSearchResponse();
49
+ await use(smartSnippetObject);
50
+ },
51
+ });
52
+
53
+ export const testInsight =
54
+ quanticBase.extend<QuanticSmartSnippetE2EInsightFixtures>({
55
+ smartSnippetData,
56
+ options: {},
57
+ search: async ({page}, use) => {
58
+ await use(new SearchObject(page, insightSearchRequestRegex));
59
+ },
60
+ insightSetup: async ({page}, use) => {
61
+ await use(new InsightSetupObject(page));
62
+ },
63
+ smartSnippet: async (
64
+ {
65
+ page,
66
+ options,
67
+ search,
68
+ configuration,
69
+ insightSetup,
70
+ smartSnippetData: data,
71
+ },
72
+ use
73
+ ) => {
74
+ const smartSnippetObject = new SmartSnippetObject(page);
75
+
76
+ await page.goto(pageUrl);
77
+ await search.mockSearchWithSmartSnippetResponse(data);
78
+
79
+ configuration.configure({...options, useCase: useCaseEnum.insight});
80
+ await insightSetup.waitForInsightInterfaceInitialization();
81
+ await search.performSearch();
82
+ await search.waitForSearchResponse();
83
+ await use(smartSnippetObject);
84
+ },
85
+ });
86
+
87
+ export {expect} from '@playwright/test';