@coveo/quantic 3.16.0 → 3.16.1-pre.9c01cf606f
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/force-app/main/default/staticresources/coveoheadless/case-assist/headless.js +2 -2
- 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/recent-queries-list/headless-recent-queries-list.d.ts +5 -0
- package/force-app/main/default/staticresources/coveoheadless/headless.js +10 -10
- package/force-app/main/default/staticresources/coveoheadless/insight/headless.js +2 -2
- package/force-app/main/default/staticresources/coveoheadless/recommendation/headless.js +2 -2
- package/package.json +5 -3
- 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
package/force-app/main/default/lwc/quanticSearchBoxInput/__tests__/quanticSearchBoxInput.test.js
DELETED
|
@@ -1,823 +0,0 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
import {createElement} from 'lwc';
|
|
3
|
-
import QuanticSearchBoxInput from '../quanticSearchBoxInput';
|
|
4
|
-
|
|
5
|
-
const functionsMocks = {
|
|
6
|
-
exampleHandleInputValueChange: jest.fn(() => {}),
|
|
7
|
-
exampleHandleSubmitSearch: jest.fn(() => {}),
|
|
8
|
-
exampleShowSuggestions: jest.fn(() => {}),
|
|
9
|
-
exampleSelectSuggestion: jest.fn(() => {}),
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const defaultPlaceholder = 'Search...';
|
|
13
|
-
const mockInputValue = 'Test input value';
|
|
14
|
-
const mockLongInputValue =
|
|
15
|
-
'Test input value that is longer than the default input value length to test the textarea expanding feature';
|
|
16
|
-
const mockSuggestions = [
|
|
17
|
-
{key: '1', value: 'suggestion1', rawValue: 'suggestion1'},
|
|
18
|
-
{key: '2', value: 'suggestion2', rawValue: 'suggestion2'},
|
|
19
|
-
{key: '3', value: 'suggestion3', rawValue: 'suggestion3'},
|
|
20
|
-
];
|
|
21
|
-
const exampleRecentQueries = ['foo', 'bar'];
|
|
22
|
-
|
|
23
|
-
const defaultOptions = {
|
|
24
|
-
withoutSubmitButton: false,
|
|
25
|
-
textarea: true,
|
|
26
|
-
placeholder: defaultPlaceholder,
|
|
27
|
-
suggestions: [],
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const selectors = {
|
|
31
|
-
searchBoxInput: '[data-cy="search-box-input"]',
|
|
32
|
-
searchBoxTextArea: '[data-cy="search-box-textarea"]',
|
|
33
|
-
searchBoxSubmitBtn: '.searchbox__submit-button',
|
|
34
|
-
searchBoxClearIcon: '.searchbox__clear-button',
|
|
35
|
-
searchBoxSuggestionsList: 'c-quantic-search-box-suggestions-list',
|
|
36
|
-
SuggestionsListBox: '[role="listbox"]',
|
|
37
|
-
searchBoxContainer: '.searchbox__container',
|
|
38
|
-
searchBoxComboBox: '.slds-combobox_container .slds-combobox',
|
|
39
|
-
searchBoxSearchIcon: '.searchbox__search-icon',
|
|
40
|
-
suggestionOption: '[data-cy="suggestions-option"]',
|
|
41
|
-
suggestionOptionText: '[data-cy="suggestions-option-text"]',
|
|
42
|
-
clearRecentQueryButton: '[data-cy="clear-recent-queries"]',
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
function setupEventListeners(element) {
|
|
46
|
-
element.addEventListener(
|
|
47
|
-
'quantic__inputvaluechange',
|
|
48
|
-
functionsMocks.exampleHandleInputValueChange
|
|
49
|
-
);
|
|
50
|
-
element.addEventListener(
|
|
51
|
-
'quantic__submitsearch',
|
|
52
|
-
functionsMocks.exampleHandleSubmitSearch
|
|
53
|
-
);
|
|
54
|
-
element.addEventListener(
|
|
55
|
-
'quantic__showsuggestions',
|
|
56
|
-
functionsMocks.exampleShowSuggestions
|
|
57
|
-
);
|
|
58
|
-
element.addEventListener(
|
|
59
|
-
'quantic__selectsuggestion',
|
|
60
|
-
functionsMocks.exampleSelectSuggestion
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function createTestComponent(options = defaultOptions) {
|
|
65
|
-
const element = createElement('c-quantic-search-box-input', {
|
|
66
|
-
is: QuanticSearchBoxInput,
|
|
67
|
-
});
|
|
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
|
-
// Helper function to wait until the microtask queue is empty.
|
|
77
|
-
function flushPromises() {
|
|
78
|
-
return new Promise((resolve) => setTimeout(resolve, 0));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
describe('c-quantic-search-box-input', () => {
|
|
82
|
-
function cleanup() {
|
|
83
|
-
// The jsdom instance is shared across test cases in a single file so reset the DOM
|
|
84
|
-
while (document.body.firstChild) {
|
|
85
|
-
document.body.removeChild(document.body.firstChild);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
beforeAll(() => {
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
global.CoveoHeadless = {
|
|
92
|
-
HighlightUtils: {
|
|
93
|
-
highlightString: () => {},
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
afterEach(() => {
|
|
99
|
-
cleanup();
|
|
100
|
-
jest.clearAllMocks();
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
[false, true].forEach((textareaValue) => {
|
|
104
|
-
describe(`when the textarea property is set to ${textareaValue}`, () => {
|
|
105
|
-
it(`should display the ${
|
|
106
|
-
textareaValue ? 'expandable' : 'default'
|
|
107
|
-
} search box properly`, async () => {
|
|
108
|
-
const element = createTestComponent({
|
|
109
|
-
...defaultOptions,
|
|
110
|
-
textarea: textareaValue,
|
|
111
|
-
});
|
|
112
|
-
await flushPromises();
|
|
113
|
-
|
|
114
|
-
const submitButton = element.shadowRoot.querySelector(
|
|
115
|
-
selectors.searchBoxSubmitBtn
|
|
116
|
-
);
|
|
117
|
-
const clearIcon = element.shadowRoot.querySelector(
|
|
118
|
-
selectors.searchBoxClearIcon
|
|
119
|
-
);
|
|
120
|
-
const input = element.shadowRoot.querySelector(
|
|
121
|
-
textareaValue ? selectors.searchBoxTextArea : selectors.searchBoxInput
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
expect(input).not.toBeNull();
|
|
125
|
-
expect(input.placeholder).toEqual(defaultOptions.placeholder);
|
|
126
|
-
expect(submitButton).not.toBeNull();
|
|
127
|
-
expect(clearIcon).toBeNull();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
describe('when the withoutSubmitButton is set to false', () => {
|
|
131
|
-
it('should display the submit button correctly to the right only', async () => {
|
|
132
|
-
const element = createTestComponent({
|
|
133
|
-
...defaultOptions,
|
|
134
|
-
withoutSubmitButton: false,
|
|
135
|
-
textarea: textareaValue,
|
|
136
|
-
});
|
|
137
|
-
await flushPromises();
|
|
138
|
-
|
|
139
|
-
const submitButton = element.shadowRoot.querySelector(
|
|
140
|
-
selectors.searchBoxSubmitBtn
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
const searchIcon = element.shadowRoot.querySelector(
|
|
144
|
-
selectors.searchBoxSearchIcon
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
expect(submitButton).not.toBeNull();
|
|
148
|
-
expect(searchIcon).toBeNull();
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe('when the withoutSubmitButton is set to true', () => {
|
|
153
|
-
it('should not display the submit button to the right of the searchbox', async () => {
|
|
154
|
-
const element = createTestComponent({
|
|
155
|
-
...defaultOptions,
|
|
156
|
-
withoutSubmitButton: true,
|
|
157
|
-
textarea: textareaValue,
|
|
158
|
-
});
|
|
159
|
-
await flushPromises();
|
|
160
|
-
|
|
161
|
-
const searchIcon = element.shadowRoot.querySelector(
|
|
162
|
-
selectors.searchBoxSearchIcon
|
|
163
|
-
);
|
|
164
|
-
const submitButton = element.shadowRoot.querySelector(
|
|
165
|
-
selectors.searchBoxSubmitBtn
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
expect(submitButton).toBeNull();
|
|
169
|
-
expect(searchIcon).not.toBeNull();
|
|
170
|
-
expect(searchIcon.classList.contains('slds-input__icon_left')).toBe(
|
|
171
|
-
true
|
|
172
|
-
);
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe('when the placeholder property receives a custom placeholder value', () => {
|
|
177
|
-
it('should display the custom value as the searchbox placeholder', async () => {
|
|
178
|
-
const customPlaceholder = 'Custom placeholder';
|
|
179
|
-
const element = createTestComponent({
|
|
180
|
-
...defaultOptions,
|
|
181
|
-
placeholder: customPlaceholder,
|
|
182
|
-
textarea: textareaValue,
|
|
183
|
-
});
|
|
184
|
-
await flushPromises();
|
|
185
|
-
|
|
186
|
-
const input = element.shadowRoot.querySelector(
|
|
187
|
-
textareaValue
|
|
188
|
-
? selectors.searchBoxTextArea
|
|
189
|
-
: selectors.searchBoxInput
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
expect(input.placeholder).toEqual(customPlaceholder);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
describe('when the suggestions list is not empty', () => {
|
|
197
|
-
describe('when only query suggestions are displayed', () => {
|
|
198
|
-
it('should display the suggestions in the suggestions list', async () => {
|
|
199
|
-
const expectedSuggestionsLabelValues = [
|
|
200
|
-
...mockSuggestions.map((suggestion) => suggestion.rawValue),
|
|
201
|
-
];
|
|
202
|
-
const element = createTestComponent({
|
|
203
|
-
...defaultOptions,
|
|
204
|
-
suggestions: mockSuggestions,
|
|
205
|
-
textarea: textareaValue,
|
|
206
|
-
});
|
|
207
|
-
await flushPromises();
|
|
208
|
-
|
|
209
|
-
const input = element.shadowRoot.querySelector(
|
|
210
|
-
textareaValue
|
|
211
|
-
? selectors.searchBoxTextArea
|
|
212
|
-
: selectors.searchBoxInput
|
|
213
|
-
);
|
|
214
|
-
expect(input).not.toBeNull();
|
|
215
|
-
await input.focus();
|
|
216
|
-
|
|
217
|
-
const suggestionsList = element.shadowRoot.querySelector(
|
|
218
|
-
selectors.searchBoxSuggestionsList
|
|
219
|
-
);
|
|
220
|
-
expect(suggestionsList).not.toBeNull();
|
|
221
|
-
|
|
222
|
-
const suggestionsListItems =
|
|
223
|
-
suggestionsList.shadowRoot.querySelectorAll(
|
|
224
|
-
selectors.suggestionOption
|
|
225
|
-
);
|
|
226
|
-
expect(suggestionsListItems).not.toBeNull();
|
|
227
|
-
expect(suggestionsListItems.length).toEqual(mockSuggestions.length);
|
|
228
|
-
|
|
229
|
-
const suggestionOptionLabels =
|
|
230
|
-
suggestionsList.shadowRoot.querySelectorAll(
|
|
231
|
-
selectors.suggestionOptionText
|
|
232
|
-
);
|
|
233
|
-
const suggestionsLength = mockSuggestions.length;
|
|
234
|
-
|
|
235
|
-
expect(suggestionOptionLabels).not.toBeNull();
|
|
236
|
-
expect(suggestionOptionLabels.length).toEqual(suggestionsLength);
|
|
237
|
-
|
|
238
|
-
suggestionOptionLabels.forEach((suggestion, index) => {
|
|
239
|
-
expect(suggestion.title).toEqual(
|
|
240
|
-
expectedSuggestionsLabelValues[index]
|
|
241
|
-
);
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
describe('with both query suggestions and recent queries available', () => {
|
|
247
|
-
it('should display the query suggestions and the recent queries in the suggestions list', async () => {
|
|
248
|
-
const expectedSuggestionsLabelValues = [
|
|
249
|
-
...exampleRecentQueries,
|
|
250
|
-
...mockSuggestions.map((suggestion) => suggestion.rawValue),
|
|
251
|
-
];
|
|
252
|
-
|
|
253
|
-
const element = createTestComponent({
|
|
254
|
-
...defaultOptions,
|
|
255
|
-
suggestions: mockSuggestions,
|
|
256
|
-
recentQueries: exampleRecentQueries,
|
|
257
|
-
textarea: textareaValue,
|
|
258
|
-
inputValue: '',
|
|
259
|
-
});
|
|
260
|
-
await flushPromises();
|
|
261
|
-
|
|
262
|
-
const input = element.shadowRoot.querySelector(
|
|
263
|
-
textareaValue
|
|
264
|
-
? selectors.searchBoxTextArea
|
|
265
|
-
: selectors.searchBoxInput
|
|
266
|
-
);
|
|
267
|
-
expect(input).not.toBeNull();
|
|
268
|
-
await input.focus();
|
|
269
|
-
|
|
270
|
-
const suggestionsList = element.shadowRoot.querySelector(
|
|
271
|
-
selectors.searchBoxSuggestionsList
|
|
272
|
-
);
|
|
273
|
-
expect(suggestionsList).not.toBeNull();
|
|
274
|
-
|
|
275
|
-
const suggestionsListItems =
|
|
276
|
-
suggestionsList.shadowRoot.querySelectorAll(
|
|
277
|
-
selectors.suggestionOption
|
|
278
|
-
);
|
|
279
|
-
const clearRecentQueriesButton =
|
|
280
|
-
suggestionsList.shadowRoot.querySelector(
|
|
281
|
-
selectors.clearRecentQueryButton
|
|
282
|
-
);
|
|
283
|
-
expect(suggestionsListItems).not.toBeNull();
|
|
284
|
-
expect(clearRecentQueriesButton).not.toBeNull();
|
|
285
|
-
expect(suggestionsListItems.length).toEqual(
|
|
286
|
-
mockSuggestions.length + exampleRecentQueries.length
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
const suggestionOptionLabels =
|
|
290
|
-
suggestionsList.shadowRoot.querySelectorAll(
|
|
291
|
-
selectors.suggestionOptionText
|
|
292
|
-
);
|
|
293
|
-
const suggestionsAndRecentQueriesLength =
|
|
294
|
-
mockSuggestions.length + exampleRecentQueries.length;
|
|
295
|
-
|
|
296
|
-
expect(suggestionOptionLabels).not.toBeNull();
|
|
297
|
-
expect(suggestionOptionLabels.length).toEqual(
|
|
298
|
-
suggestionsAndRecentQueriesLength
|
|
299
|
-
);
|
|
300
|
-
|
|
301
|
-
suggestionOptionLabels.forEach((suggestion, index) => {
|
|
302
|
-
expect(suggestion.title).toEqual(
|
|
303
|
-
expectedSuggestionsLabelValues[index]
|
|
304
|
-
);
|
|
305
|
-
});
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
describe('when pressing the DOWN to select a suggestion', () => {
|
|
309
|
-
it('should persist the value of the suggestion on blur', async () => {
|
|
310
|
-
const element = createTestComponent({
|
|
311
|
-
...defaultOptions,
|
|
312
|
-
suggestions: mockSuggestions,
|
|
313
|
-
recentQueries: exampleRecentQueries,
|
|
314
|
-
textarea: textareaValue,
|
|
315
|
-
inputValue: '',
|
|
316
|
-
});
|
|
317
|
-
await flushPromises();
|
|
318
|
-
|
|
319
|
-
const input = element.shadowRoot.querySelector(
|
|
320
|
-
textareaValue
|
|
321
|
-
? selectors.searchBoxTextArea
|
|
322
|
-
: selectors.searchBoxInput
|
|
323
|
-
);
|
|
324
|
-
expect(input).not.toBeNull();
|
|
325
|
-
|
|
326
|
-
await input.focus();
|
|
327
|
-
// First keydown to navigate to the clear recent queries option.
|
|
328
|
-
input.dispatchEvent(
|
|
329
|
-
new KeyboardEvent('keydown', {key: 'ArrowDown'})
|
|
330
|
-
);
|
|
331
|
-
// Second keydown to navigate to the first recent query option.
|
|
332
|
-
input.dispatchEvent(
|
|
333
|
-
new KeyboardEvent('keydown', {key: 'ArrowDown'})
|
|
334
|
-
);
|
|
335
|
-
await flushPromises();
|
|
336
|
-
|
|
337
|
-
expect(input.value).toBe(exampleRecentQueries[0]);
|
|
338
|
-
|
|
339
|
-
await input.blur();
|
|
340
|
-
await flushPromises();
|
|
341
|
-
|
|
342
|
-
expect(input.value).toBe(exampleRecentQueries[0]);
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
it('should persist the value of the suggestion when pressing the Escape key', async () => {
|
|
346
|
-
const element = createTestComponent({
|
|
347
|
-
...defaultOptions,
|
|
348
|
-
suggestions: mockSuggestions,
|
|
349
|
-
recentQueries: exampleRecentQueries,
|
|
350
|
-
textarea: textareaValue,
|
|
351
|
-
inputValue: '',
|
|
352
|
-
});
|
|
353
|
-
await flushPromises();
|
|
354
|
-
|
|
355
|
-
const input = element.shadowRoot.querySelector(
|
|
356
|
-
textareaValue
|
|
357
|
-
? selectors.searchBoxTextArea
|
|
358
|
-
: selectors.searchBoxInput
|
|
359
|
-
);
|
|
360
|
-
expect(input).not.toBeNull();
|
|
361
|
-
|
|
362
|
-
await input.focus();
|
|
363
|
-
// First keydown to navigate to the clear recent queries option.
|
|
364
|
-
input.dispatchEvent(
|
|
365
|
-
new KeyboardEvent('keydown', {key: 'ArrowDown'})
|
|
366
|
-
);
|
|
367
|
-
// Second keydown to navigate to the first recent query option.
|
|
368
|
-
input.dispatchEvent(
|
|
369
|
-
new KeyboardEvent('keydown', {key: 'ArrowDown'})
|
|
370
|
-
);
|
|
371
|
-
await flushPromises();
|
|
372
|
-
|
|
373
|
-
expect(input.value).toBe(exampleRecentQueries[0]);
|
|
374
|
-
|
|
375
|
-
input.dispatchEvent(
|
|
376
|
-
new KeyboardEvent('keydown', {key: 'Escape'})
|
|
377
|
-
);
|
|
378
|
-
await flushPromises();
|
|
379
|
-
|
|
380
|
-
expect(input.value).toBe(exampleRecentQueries[0]);
|
|
381
|
-
});
|
|
382
|
-
});
|
|
383
|
-
});
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
describe('when the suggestions list is empty', () => {
|
|
387
|
-
it('should not display the quanticSearchBoxSuggestionsList component', async () => {
|
|
388
|
-
const element = createTestComponent({
|
|
389
|
-
...defaultOptions,
|
|
390
|
-
suggestions: [],
|
|
391
|
-
textarea: textareaValue,
|
|
392
|
-
});
|
|
393
|
-
await flushPromises();
|
|
394
|
-
|
|
395
|
-
const suggestionsList = element.shadowRoot.querySelector(
|
|
396
|
-
selectors.searchBoxSuggestionsList
|
|
397
|
-
);
|
|
398
|
-
expect(suggestionsList).toBeNull();
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
describe('when focusing on the input', () => {
|
|
403
|
-
it('should dispatch a #quantic__showsuggestions custom event', async () => {
|
|
404
|
-
const element = createTestComponent({
|
|
405
|
-
...defaultOptions,
|
|
406
|
-
textarea: textareaValue,
|
|
407
|
-
});
|
|
408
|
-
setupEventListeners(element);
|
|
409
|
-
await flushPromises();
|
|
410
|
-
|
|
411
|
-
const input = element.shadowRoot.querySelector(
|
|
412
|
-
textareaValue
|
|
413
|
-
? selectors.searchBoxTextArea
|
|
414
|
-
: selectors.searchBoxInput
|
|
415
|
-
);
|
|
416
|
-
expect(input).not.toBeNull();
|
|
417
|
-
|
|
418
|
-
await input.focus();
|
|
419
|
-
|
|
420
|
-
expect(functionsMocks.exampleShowSuggestions).toHaveBeenCalledTimes(
|
|
421
|
-
1
|
|
422
|
-
);
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
describe('when selecting a suggestion from the suggestions list', () => {
|
|
426
|
-
it('should dispatch a #quantic__selectsuggestion event with the selected suggestion as payload', async () => {
|
|
427
|
-
const element = createTestComponent({
|
|
428
|
-
...defaultOptions,
|
|
429
|
-
suggestions: mockSuggestions,
|
|
430
|
-
textarea: textareaValue,
|
|
431
|
-
});
|
|
432
|
-
setupEventListeners(element);
|
|
433
|
-
await flushPromises();
|
|
434
|
-
|
|
435
|
-
const input = element.shadowRoot.querySelector(
|
|
436
|
-
textareaValue
|
|
437
|
-
? selectors.searchBoxTextArea
|
|
438
|
-
: selectors.searchBoxInput
|
|
439
|
-
);
|
|
440
|
-
expect(input).not.toBeNull();
|
|
441
|
-
|
|
442
|
-
await input.focus();
|
|
443
|
-
|
|
444
|
-
const suggestionsList = element.shadowRoot.querySelector(
|
|
445
|
-
selectors.searchBoxSuggestionsList
|
|
446
|
-
);
|
|
447
|
-
expect(suggestionsList).not.toBeNull();
|
|
448
|
-
|
|
449
|
-
const querySuggestionIndex = 0;
|
|
450
|
-
const firstSuggestion = suggestionsList.shadowRoot.querySelectorAll(
|
|
451
|
-
selectors.suggestionOption
|
|
452
|
-
)[querySuggestionIndex];
|
|
453
|
-
expect(firstSuggestion).not.toBeNull();
|
|
454
|
-
|
|
455
|
-
firstSuggestion.dispatchEvent(new CustomEvent('mousedown'));
|
|
456
|
-
expect(
|
|
457
|
-
functionsMocks.exampleSelectSuggestion
|
|
458
|
-
).toHaveBeenCalledTimes(1);
|
|
459
|
-
|
|
460
|
-
/** @type{{detail: {selectedSuggestion: object}}} */
|
|
461
|
-
const eventData =
|
|
462
|
-
functionsMocks.exampleSelectSuggestion.mock.calls[0][0];
|
|
463
|
-
const expectedFirstSuggestionSelected = {
|
|
464
|
-
isClearRecentQueryButton: undefined,
|
|
465
|
-
isRecentQuery: undefined,
|
|
466
|
-
value: mockSuggestions[querySuggestionIndex].rawValue,
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
expect(eventData.detail.selectedSuggestion).toEqual(
|
|
470
|
-
expectedFirstSuggestionSelected
|
|
471
|
-
);
|
|
472
|
-
});
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
describe('when selecting the clear recent query option from the suggestions list', () => {
|
|
476
|
-
it('should dispatch a #quantic__selectsuggestion event with the selected suggestion as payload', async () => {
|
|
477
|
-
const element = createTestComponent({
|
|
478
|
-
...defaultOptions,
|
|
479
|
-
suggestions: mockSuggestions,
|
|
480
|
-
textarea: textareaValue,
|
|
481
|
-
recentQueries: exampleRecentQueries,
|
|
482
|
-
inputValue: '',
|
|
483
|
-
});
|
|
484
|
-
setupEventListeners(element);
|
|
485
|
-
await flushPromises();
|
|
486
|
-
|
|
487
|
-
const input = element.shadowRoot.querySelector(
|
|
488
|
-
textareaValue
|
|
489
|
-
? selectors.searchBoxTextArea
|
|
490
|
-
: selectors.searchBoxInput
|
|
491
|
-
);
|
|
492
|
-
expect(input).not.toBeNull();
|
|
493
|
-
|
|
494
|
-
await input.focus();
|
|
495
|
-
|
|
496
|
-
const suggestionsList = element.shadowRoot.querySelector(
|
|
497
|
-
selectors.searchBoxSuggestionsList
|
|
498
|
-
);
|
|
499
|
-
expect(suggestionsList).not.toBeNull();
|
|
500
|
-
|
|
501
|
-
const clearRecentQueriesOption =
|
|
502
|
-
suggestionsList.shadowRoot.querySelectorAll(
|
|
503
|
-
selectors.clearRecentQueryButton
|
|
504
|
-
)[0];
|
|
505
|
-
expect(clearRecentQueriesOption).not.toBeNull();
|
|
506
|
-
|
|
507
|
-
clearRecentQueriesOption.dispatchEvent(
|
|
508
|
-
new CustomEvent('mousedown')
|
|
509
|
-
);
|
|
510
|
-
expect(
|
|
511
|
-
functionsMocks.exampleSelectSuggestion
|
|
512
|
-
).toHaveBeenCalledTimes(1);
|
|
513
|
-
|
|
514
|
-
/** @type{{detail: {selectedSuggestion: object}}} */
|
|
515
|
-
const eventData =
|
|
516
|
-
functionsMocks.exampleSelectSuggestion.mock.calls[0][0];
|
|
517
|
-
const expectedFirstSuggestionSelected = {
|
|
518
|
-
isClearRecentQueryButton: true,
|
|
519
|
-
isRecentQuery: undefined,
|
|
520
|
-
value: undefined,
|
|
521
|
-
};
|
|
522
|
-
|
|
523
|
-
expect(eventData.detail.selectedSuggestion).toEqual(
|
|
524
|
-
expectedFirstSuggestionSelected
|
|
525
|
-
);
|
|
526
|
-
});
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
describe('when selecting a recent query from the suggestions list', () => {
|
|
530
|
-
it('should dispatch a #quantic__selectsuggestion event with the selected recent query as payload', async () => {
|
|
531
|
-
const element = createTestComponent({
|
|
532
|
-
...defaultOptions,
|
|
533
|
-
suggestions: mockSuggestions,
|
|
534
|
-
textarea: textareaValue,
|
|
535
|
-
recentQueries: exampleRecentQueries,
|
|
536
|
-
inputValue: '',
|
|
537
|
-
});
|
|
538
|
-
setupEventListeners(element);
|
|
539
|
-
await flushPromises();
|
|
540
|
-
|
|
541
|
-
const input = element.shadowRoot.querySelector(
|
|
542
|
-
textareaValue
|
|
543
|
-
? selectors.searchBoxTextArea
|
|
544
|
-
: selectors.searchBoxInput
|
|
545
|
-
);
|
|
546
|
-
expect(input).not.toBeNull();
|
|
547
|
-
|
|
548
|
-
await input.focus();
|
|
549
|
-
|
|
550
|
-
const suggestionsList = element.shadowRoot.querySelector(
|
|
551
|
-
selectors.searchBoxSuggestionsList
|
|
552
|
-
);
|
|
553
|
-
expect(suggestionsList).not.toBeNull();
|
|
554
|
-
|
|
555
|
-
const recentQueryIndex = 0;
|
|
556
|
-
const firstRecentQuery =
|
|
557
|
-
suggestionsList.shadowRoot.querySelectorAll(
|
|
558
|
-
selectors.suggestionOption
|
|
559
|
-
)[recentQueryIndex];
|
|
560
|
-
expect(firstRecentQuery).not.toBeNull();
|
|
561
|
-
|
|
562
|
-
firstRecentQuery.dispatchEvent(new CustomEvent('mousedown'));
|
|
563
|
-
expect(
|
|
564
|
-
functionsMocks.exampleSelectSuggestion
|
|
565
|
-
).toHaveBeenCalledTimes(1);
|
|
566
|
-
|
|
567
|
-
/** @type{{detail: {selectedSuggestion: object}}} */
|
|
568
|
-
const eventData =
|
|
569
|
-
functionsMocks.exampleSelectSuggestion.mock.calls[0][0];
|
|
570
|
-
const expectedFirstSuggestionSelected = {
|
|
571
|
-
isClearRecentQueryButton: undefined,
|
|
572
|
-
isRecentQuery: true,
|
|
573
|
-
value: exampleRecentQueries[recentQueryIndex],
|
|
574
|
-
};
|
|
575
|
-
|
|
576
|
-
expect(eventData.detail.selectedSuggestion).toEqual(
|
|
577
|
-
expectedFirstSuggestionSelected
|
|
578
|
-
);
|
|
579
|
-
});
|
|
580
|
-
});
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
describe('when typing something in the input', () => {
|
|
584
|
-
it('should dispatch a #quantic__inputvaluechange custom event with the input value as payload', async () => {
|
|
585
|
-
const element = createTestComponent({
|
|
586
|
-
...defaultOptions,
|
|
587
|
-
textarea: textareaValue,
|
|
588
|
-
inputValue: mockInputValue,
|
|
589
|
-
});
|
|
590
|
-
setupEventListeners(element);
|
|
591
|
-
await flushPromises();
|
|
592
|
-
|
|
593
|
-
const input = element.shadowRoot.querySelector(
|
|
594
|
-
textareaValue
|
|
595
|
-
? selectors.searchBoxTextArea
|
|
596
|
-
: selectors.searchBoxInput
|
|
597
|
-
);
|
|
598
|
-
expect(input).not.toBeNull();
|
|
599
|
-
|
|
600
|
-
input.dispatchEvent(new KeyboardEvent('input'));
|
|
601
|
-
expect(
|
|
602
|
-
functionsMocks.exampleHandleInputValueChange
|
|
603
|
-
).toHaveBeenCalledTimes(1);
|
|
604
|
-
|
|
605
|
-
/** @type{{detail: {value: string}}} */
|
|
606
|
-
const eventData =
|
|
607
|
-
functionsMocks.exampleHandleInputValueChange.mock.calls[0][0];
|
|
608
|
-
expect(eventData.detail.value).toEqual(mockInputValue);
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
describe('when clicking on the submit button', () => {
|
|
612
|
-
it('should dispatch a #quantic__submitsearch custom event', async () => {
|
|
613
|
-
const element = createTestComponent({
|
|
614
|
-
...defaultOptions,
|
|
615
|
-
textarea: textareaValue,
|
|
616
|
-
});
|
|
617
|
-
setupEventListeners(element);
|
|
618
|
-
await flushPromises();
|
|
619
|
-
|
|
620
|
-
const submitButton = element.shadowRoot.querySelector(
|
|
621
|
-
selectors.searchBoxSubmitBtn
|
|
622
|
-
);
|
|
623
|
-
expect(submitButton).not.toBeNull();
|
|
624
|
-
|
|
625
|
-
submitButton.click();
|
|
626
|
-
|
|
627
|
-
expect(
|
|
628
|
-
functionsMocks.exampleHandleSubmitSearch
|
|
629
|
-
).toHaveBeenCalledTimes(1);
|
|
630
|
-
});
|
|
631
|
-
});
|
|
632
|
-
|
|
633
|
-
describe('when pressing the ENTER key', () => {
|
|
634
|
-
it('should dispatch a #quantic__submitsearch custom event', async () => {
|
|
635
|
-
const element = createTestComponent({
|
|
636
|
-
...defaultOptions,
|
|
637
|
-
textarea: textareaValue,
|
|
638
|
-
});
|
|
639
|
-
setupEventListeners(element);
|
|
640
|
-
await flushPromises();
|
|
641
|
-
|
|
642
|
-
const input = element.shadowRoot.querySelector(
|
|
643
|
-
textareaValue
|
|
644
|
-
? selectors.searchBoxTextArea
|
|
645
|
-
: selectors.searchBoxInput
|
|
646
|
-
);
|
|
647
|
-
expect(input).not.toBeNull();
|
|
648
|
-
|
|
649
|
-
await input.focus();
|
|
650
|
-
input.dispatchEvent(new KeyboardEvent('keydown', {key: 'Enter'}));
|
|
651
|
-
|
|
652
|
-
expect(
|
|
653
|
-
functionsMocks.exampleHandleSubmitSearch
|
|
654
|
-
).toHaveBeenCalledTimes(1);
|
|
655
|
-
});
|
|
656
|
-
|
|
657
|
-
it(`${
|
|
658
|
-
textareaValue ? 'should not' : 'should'
|
|
659
|
-
} dispatch a #quantic__submitsearch custom event when the shift key is pressed along with the enter key`, async () => {
|
|
660
|
-
const element = createTestComponent({
|
|
661
|
-
...defaultOptions,
|
|
662
|
-
textarea: textareaValue,
|
|
663
|
-
});
|
|
664
|
-
setupEventListeners(element);
|
|
665
|
-
await flushPromises();
|
|
666
|
-
|
|
667
|
-
const input = element.shadowRoot.querySelector(
|
|
668
|
-
textareaValue
|
|
669
|
-
? selectors.searchBoxTextArea
|
|
670
|
-
: selectors.searchBoxInput
|
|
671
|
-
);
|
|
672
|
-
expect(input).not.toBeNull();
|
|
673
|
-
|
|
674
|
-
await input.focus();
|
|
675
|
-
input.dispatchEvent(
|
|
676
|
-
new KeyboardEvent('keydown', {key: 'Enter', shiftKey: true})
|
|
677
|
-
);
|
|
678
|
-
|
|
679
|
-
expect(
|
|
680
|
-
functionsMocks.exampleHandleSubmitSearch
|
|
681
|
-
).toHaveBeenCalledTimes(textareaValue ? 0 : 1);
|
|
682
|
-
});
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
describe('accessibility', () => {
|
|
686
|
-
describe('when pressing the DOWN and UP arrow keys', () => {
|
|
687
|
-
it('should set the aria-activedescendant attribute of the input according to the currently active suggestion', async () => {
|
|
688
|
-
const element = createTestComponent({
|
|
689
|
-
...defaultOptions,
|
|
690
|
-
suggestions: mockSuggestions,
|
|
691
|
-
textarea: textareaValue,
|
|
692
|
-
});
|
|
693
|
-
await flushPromises();
|
|
694
|
-
|
|
695
|
-
const input = element.shadowRoot.querySelector(
|
|
696
|
-
textareaValue
|
|
697
|
-
? selectors.searchBoxTextArea
|
|
698
|
-
: selectors.searchBoxInput
|
|
699
|
-
);
|
|
700
|
-
expect(input).not.toBeNull();
|
|
701
|
-
|
|
702
|
-
await input.focus();
|
|
703
|
-
const suggestionsList = element.shadowRoot.querySelector(
|
|
704
|
-
selectors.searchBoxSuggestionsList
|
|
705
|
-
);
|
|
706
|
-
const suggestionsListItems = Array.from(
|
|
707
|
-
suggestionsList.shadowRoot.querySelectorAll(
|
|
708
|
-
selectors.suggestionOption
|
|
709
|
-
)
|
|
710
|
-
);
|
|
711
|
-
expect(suggestionsList).not.toBeNull();
|
|
712
|
-
expect(suggestionsListItems).not.toBeNull();
|
|
713
|
-
|
|
714
|
-
input.dispatchEvent(
|
|
715
|
-
new KeyboardEvent('keydown', {key: 'ArrowDown'})
|
|
716
|
-
);
|
|
717
|
-
await flushPromises();
|
|
718
|
-
|
|
719
|
-
const firstSuggestionId = suggestionsListItems[0].id;
|
|
720
|
-
|
|
721
|
-
expect(input.getAttribute('aria-activedescendant')).toBe(
|
|
722
|
-
firstSuggestionId
|
|
723
|
-
);
|
|
724
|
-
|
|
725
|
-
input.dispatchEvent(
|
|
726
|
-
new KeyboardEvent('keydown', {key: 'ArrowUp'})
|
|
727
|
-
);
|
|
728
|
-
await flushPromises();
|
|
729
|
-
|
|
730
|
-
const lastSuggestionId = suggestionsListItems.at(-1).id;
|
|
731
|
-
|
|
732
|
-
expect(input.getAttribute('aria-activedescendant')).toBe(
|
|
733
|
-
lastSuggestionId
|
|
734
|
-
);
|
|
735
|
-
|
|
736
|
-
await input.blur();
|
|
737
|
-
expect(input.getAttribute('aria-activedescendant')).toBeNull();
|
|
738
|
-
});
|
|
739
|
-
});
|
|
740
|
-
|
|
741
|
-
describe('when the search box input is rendered', () => {
|
|
742
|
-
it('should set the aria-controls attribute of the input according to the id of the suggestions listbox', async () => {
|
|
743
|
-
const element = createTestComponent({
|
|
744
|
-
...defaultOptions,
|
|
745
|
-
suggestions: mockSuggestions,
|
|
746
|
-
textarea: textareaValue,
|
|
747
|
-
});
|
|
748
|
-
await flushPromises();
|
|
749
|
-
|
|
750
|
-
const input = element.shadowRoot.querySelector(
|
|
751
|
-
textareaValue
|
|
752
|
-
? selectors.searchBoxTextArea
|
|
753
|
-
: selectors.searchBoxInput
|
|
754
|
-
);
|
|
755
|
-
expect(input).not.toBeNull();
|
|
756
|
-
|
|
757
|
-
await input.focus();
|
|
758
|
-
const suggestionsList = element.shadowRoot.querySelector(
|
|
759
|
-
selectors.searchBoxSuggestionsList
|
|
760
|
-
);
|
|
761
|
-
const suggestionsListBox =
|
|
762
|
-
suggestionsList.shadowRoot.querySelector(
|
|
763
|
-
selectors.SuggestionsListBox
|
|
764
|
-
);
|
|
765
|
-
expect(suggestionsList).not.toBeNull();
|
|
766
|
-
expect(suggestionsListBox).not.toBeNull();
|
|
767
|
-
|
|
768
|
-
expect(input.getAttribute('aria-controls')).toBe(
|
|
769
|
-
suggestionsListBox.id
|
|
770
|
-
);
|
|
771
|
-
});
|
|
772
|
-
});
|
|
773
|
-
});
|
|
774
|
-
});
|
|
775
|
-
|
|
776
|
-
describe('when clicking on the clear icon after typing something', () => {
|
|
777
|
-
it('should properly clear the input value', async () => {
|
|
778
|
-
const element = createTestComponent({
|
|
779
|
-
...defaultOptions,
|
|
780
|
-
textarea: textareaValue,
|
|
781
|
-
});
|
|
782
|
-
await flushPromises();
|
|
783
|
-
|
|
784
|
-
element.inputValue = mockLongInputValue;
|
|
785
|
-
await flushPromises();
|
|
786
|
-
|
|
787
|
-
const clearIcon = element.shadowRoot.querySelector(
|
|
788
|
-
selectors.searchBoxClearIcon
|
|
789
|
-
);
|
|
790
|
-
const input = element.shadowRoot.querySelector(
|
|
791
|
-
textareaValue
|
|
792
|
-
? selectors.searchBoxTextArea
|
|
793
|
-
: selectors.searchBoxInput
|
|
794
|
-
);
|
|
795
|
-
|
|
796
|
-
expect(input).not.toBeNull();
|
|
797
|
-
expect(input.value).toEqual(mockLongInputValue);
|
|
798
|
-
|
|
799
|
-
clearIcon.click();
|
|
800
|
-
expect(input.value).toEqual('');
|
|
801
|
-
const expectedCollapsedInputHeight = textareaValue ? '0px' : '';
|
|
802
|
-
expect(input.style.height).toEqual(expectedCollapsedInputHeight);
|
|
803
|
-
});
|
|
804
|
-
});
|
|
805
|
-
|
|
806
|
-
describe('when the component renders with a value in the input', () => {
|
|
807
|
-
it('should display the clear icon', async () => {
|
|
808
|
-
const element = createTestComponent({
|
|
809
|
-
...defaultOptions,
|
|
810
|
-
inputValue: mockInputValue,
|
|
811
|
-
textarea: textareaValue,
|
|
812
|
-
});
|
|
813
|
-
await flushPromises();
|
|
814
|
-
|
|
815
|
-
const clearIcon = element.shadowRoot.querySelector(
|
|
816
|
-
selectors.searchBoxClearIcon
|
|
817
|
-
);
|
|
818
|
-
expect(clearIcon).not.toBeNull();
|
|
819
|
-
});
|
|
820
|
-
});
|
|
821
|
-
});
|
|
822
|
-
});
|
|
823
|
-
});
|