vue-instantsearch 4.12.0 → 4.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.
- package/package.json +3 -3
- package/src/__tests__/common-connectors.test.js +86 -21
- package/src/__tests__/common-widgets.test.js +75 -0
- package/src/components/SearchBox.vue +4 -4
- package/src/components/SearchInput.vue +3 -10
- package/src/components/SortBy.vue +1 -0
- package/src/components/Stats.vue +40 -2
- package/src/components/ToggleRefinement.vue +1 -1
- package/src/components/__tests__/SearchBox.js +30 -101
- package/src/components/__tests__/SortBy.js +0 -53
- package/src/components/__tests__/ToggleRefinement.js +0 -132
- package/src/components/__tests__/__snapshots__/RefinementList.js.snap +8 -24
- package/src/components/__tests__/__snapshots__/SortBy.js.snap +0 -22
- package/src/components/__tests__/__snapshots__/ToggleRefinement.js.snap +0 -51
- package/src/util/vue-compat/index-vue3.js +3 -2
- package/vue2/cjs/index.js +1 -1
- package/vue2/cjs/index.js.map +1 -1
- package/vue2/es/package.json.js +1 -1
- package/vue2/es/src/components/SearchBox.vue_rollup-plugin-vue=script.js +1 -1
- package/vue2/es/src/components/SearchInput.vue.js +1 -1
- package/vue2/es/src/components/SortBy.vue.js +1 -1
- package/vue2/es/src/components/Stats.vue.js +1 -1
- package/vue2/es/src/components/Stats.vue_rollup-plugin-vue=script.js +1 -1
- package/vue2/es/src/components/ToggleRefinement.vue.js +1 -1
- package/vue2/umd/index.js +1 -1
- package/vue2/umd/index.js.map +1 -1
- package/vue3/cjs/index.js +1 -1
- package/vue3/cjs/index.js.map +1 -1
- package/vue3/es/package.json.js +1 -1
- package/vue3/es/src/components/SearchBox.vue.js +1 -1
- package/vue3/es/src/components/SearchBox.vue_vue&type=script&lang.js +1 -1
- package/vue3/es/src/components/SearchBox.vue_vue&type=script&lang.js.map +1 -1
- package/vue3/es/src/components/{SearchBox.vue_vue&type=template&id=27000fa5&lang.js → SearchBox.vue_vue&type=template&id=47fdc6ba&lang.js} +1 -1
- package/vue3/es/src/components/SearchBox.vue_vue&type=template&id=47fdc6ba&lang.js.map +1 -0
- package/vue3/es/src/components/SearchInput.vue.js +1 -1
- package/vue3/es/src/components/SearchInput.vue_vue&type=script&lang.js.map +1 -1
- package/vue3/es/src/components/SearchInput.vue_vue&type=template&id=2e14ab6e&lang.js +2 -0
- package/vue3/es/src/components/SearchInput.vue_vue&type=template&id=2e14ab6e&lang.js.map +1 -0
- package/vue3/es/src/components/SortBy.vue.js +1 -1
- package/vue3/es/src/components/SortBy.vue_vue&type=script&lang.js.map +1 -1
- package/vue3/es/src/components/SortBy.vue_vue&type=template&id=78751313&lang.js +2 -0
- package/vue3/es/src/components/SortBy.vue_vue&type=template&id=78751313&lang.js.map +1 -0
- package/vue3/es/src/components/Stats.vue.js +1 -1
- package/vue3/es/src/components/Stats.vue_vue&type=script&lang.js +1 -1
- package/vue3/es/src/components/Stats.vue_vue&type=script&lang.js.map +1 -1
- package/vue3/es/src/components/Stats.vue_vue&type=template&id=67854642&lang.js +2 -0
- package/vue3/es/src/components/Stats.vue_vue&type=template&id=67854642&lang.js.map +1 -0
- package/vue3/es/src/components/ToggleRefinement.vue.js +1 -1
- package/vue3/es/src/components/ToggleRefinement.vue_vue&type=script&lang.js.map +1 -1
- package/vue3/es/src/components/{ToggleRefinement.vue_vue&type=template&id=1e8d14ba&lang.js → ToggleRefinement.vue_vue&type=template&id=4074ad16&lang.js} +2 -2
- package/vue3/es/src/components/ToggleRefinement.vue_vue&type=template&id=4074ad16&lang.js.map +1 -0
- package/vue3/es/src/util/vue-compat/index-vue3.js +1 -1
- package/vue3/es/src/util/vue-compat/index-vue3.js.map +1 -1
- package/vue3/umd/index.js +1 -1
- package/vue3/umd/index.js.map +1 -1
- package/src/components/__tests__/Stats.js +0 -62
- package/src/components/__tests__/__snapshots__/SearchBox.js.snap +0 -59
- package/vue3/es/src/components/SearchBox.vue_vue&type=template&id=27000fa5&lang.js.map +0 -1
- package/vue3/es/src/components/SearchInput.vue_vue&type=template&id=00f0f603&lang.js +0 -2
- package/vue3/es/src/components/SearchInput.vue_vue&type=template&id=00f0f603&lang.js.map +0 -1
- package/vue3/es/src/components/SortBy.vue_vue&type=template&id=507e7d3a&lang.js +0 -2
- package/vue3/es/src/components/SortBy.vue_vue&type=template&id=507e7d3a&lang.js.map +0 -1
- package/vue3/es/src/components/Stats.vue_vue&type=template&id=6d9c672c&lang.js +0 -2
- package/vue3/es/src/components/Stats.vue_vue&type=template&id=6d9c672c&lang.js.map +0 -1
- package/vue3/es/src/components/ToggleRefinement.vue_vue&type=template&id=1e8d14ba&lang.js.map +0 -1
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"autocomplete"
|
|
17
17
|
],
|
|
18
18
|
"license": "MIT",
|
|
19
|
-
"version": "4.
|
|
19
|
+
"version": "4.13.0",
|
|
20
20
|
"files": [
|
|
21
21
|
"vue2",
|
|
22
22
|
"vue3",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"test:exports:vue3": "node ./test/module/vue3/is-es-module.mjs && node ./test/module/vue3/is-cjs-module.cjs"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"instantsearch.js": "4.
|
|
38
|
+
"instantsearch.js": "4.61.0",
|
|
39
39
|
"mitt": "^2.1.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
@@ -87,5 +87,5 @@
|
|
|
87
87
|
"vuex": "3.5.1",
|
|
88
88
|
"vuex4": "npm:vuex@4.0.0"
|
|
89
89
|
},
|
|
90
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "0035f4bc5b91cdb4095ec36f5514c6718ea00c29"
|
|
91
91
|
}
|
|
@@ -36,7 +36,27 @@ const testSetups = {
|
|
|
36
36
|
name: 'RefinementList',
|
|
37
37
|
requiredProps: ['attribute'],
|
|
38
38
|
urlValue: 'value',
|
|
39
|
-
|
|
39
|
+
refineComponents: [
|
|
40
|
+
(h, state) =>
|
|
41
|
+
h(
|
|
42
|
+
'form',
|
|
43
|
+
{
|
|
44
|
+
on: {
|
|
45
|
+
submit: (event) => {
|
|
46
|
+
state.refine(event.currentTarget.elements[0].value);
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
[
|
|
51
|
+
h('input', {
|
|
52
|
+
attrs: {
|
|
53
|
+
type: 'text',
|
|
54
|
+
'data-testid': 'RefinementList-refine-input',
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
]
|
|
58
|
+
),
|
|
59
|
+
],
|
|
40
60
|
});
|
|
41
61
|
|
|
42
62
|
mountApp(
|
|
@@ -61,7 +81,27 @@ const testSetups = {
|
|
|
61
81
|
name: 'HierarchicalMenu',
|
|
62
82
|
requiredProps: ['attributes'],
|
|
63
83
|
urlValue: 'value',
|
|
64
|
-
|
|
84
|
+
refineComponents: [
|
|
85
|
+
(h, state) =>
|
|
86
|
+
h(
|
|
87
|
+
'form',
|
|
88
|
+
{
|
|
89
|
+
on: {
|
|
90
|
+
submit: (event) => {
|
|
91
|
+
state.refine(event.currentTarget.elements[0].value);
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
[
|
|
96
|
+
h('input', {
|
|
97
|
+
attrs: {
|
|
98
|
+
type: 'text',
|
|
99
|
+
'data-testid': 'HierarchicalMenu-refine-input',
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
]
|
|
103
|
+
),
|
|
104
|
+
],
|
|
65
105
|
});
|
|
66
106
|
|
|
67
107
|
mountApp(
|
|
@@ -105,7 +145,27 @@ const testSetups = {
|
|
|
105
145
|
name: 'Menu',
|
|
106
146
|
requiredProps: ['attribute'],
|
|
107
147
|
urlValue: 'value',
|
|
108
|
-
|
|
148
|
+
refineComponents: [
|
|
149
|
+
(h, state) =>
|
|
150
|
+
h(
|
|
151
|
+
'form',
|
|
152
|
+
{
|
|
153
|
+
on: {
|
|
154
|
+
submit: (event) => {
|
|
155
|
+
state.refine(event.currentTarget.elements[0].value);
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
[
|
|
160
|
+
h('input', {
|
|
161
|
+
attrs: {
|
|
162
|
+
type: 'text',
|
|
163
|
+
'data-testid': 'Menu-refine-input',
|
|
164
|
+
},
|
|
165
|
+
}),
|
|
166
|
+
]
|
|
167
|
+
),
|
|
168
|
+
],
|
|
109
169
|
});
|
|
110
170
|
|
|
111
171
|
mountApp(
|
|
@@ -233,6 +293,7 @@ const testSetups = {
|
|
|
233
293
|
name: 'RatingMenu',
|
|
234
294
|
requiredProps: ['attribute'],
|
|
235
295
|
urlValue: encodeURI('5'),
|
|
296
|
+
refineValue: 5,
|
|
236
297
|
});
|
|
237
298
|
|
|
238
299
|
mountApp(
|
|
@@ -286,6 +347,27 @@ function createCustomWidget({
|
|
|
286
347
|
urlValue,
|
|
287
348
|
refineValue,
|
|
288
349
|
requiredProps = [],
|
|
350
|
+
refineComponents = [
|
|
351
|
+
(h, state) =>
|
|
352
|
+
h(
|
|
353
|
+
'button',
|
|
354
|
+
{
|
|
355
|
+
attrs: {
|
|
356
|
+
'data-testid': `${name}-refine`,
|
|
357
|
+
},
|
|
358
|
+
on: {
|
|
359
|
+
click: () => {
|
|
360
|
+
state.refine(
|
|
361
|
+
typeof refineValue === 'function'
|
|
362
|
+
? refineValue(state)
|
|
363
|
+
: refineValue
|
|
364
|
+
);
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
'REFINE'
|
|
369
|
+
),
|
|
370
|
+
],
|
|
289
371
|
}) {
|
|
290
372
|
return {
|
|
291
373
|
name: `Custom${name}`,
|
|
@@ -313,24 +395,7 @@ function createCustomWidget({
|
|
|
313
395
|
},
|
|
314
396
|
'LINK'
|
|
315
397
|
),
|
|
316
|
-
h
|
|
317
|
-
'button',
|
|
318
|
-
{
|
|
319
|
-
attrs: {
|
|
320
|
-
'data-testid': `${name}-refine`,
|
|
321
|
-
},
|
|
322
|
-
on: {
|
|
323
|
-
click: () => {
|
|
324
|
-
this.state.refine(
|
|
325
|
-
typeof refineValue === 'function'
|
|
326
|
-
? refineValue(this.state)
|
|
327
|
-
: refineValue
|
|
328
|
-
);
|
|
329
|
-
},
|
|
330
|
-
},
|
|
331
|
-
},
|
|
332
|
-
'REFINE'
|
|
333
|
-
),
|
|
398
|
+
...refineComponents.map((component) => component(h, this.state)),
|
|
334
399
|
])
|
|
335
400
|
: null;
|
|
336
401
|
}),
|
|
@@ -21,6 +21,9 @@ import {
|
|
|
21
21
|
AisHitsPerPage,
|
|
22
22
|
AisClearRefinements,
|
|
23
23
|
AisCurrentRefinements,
|
|
24
|
+
AisToggleRefinement,
|
|
25
|
+
AisSortBy,
|
|
26
|
+
AisStats,
|
|
24
27
|
} from '../instantsearch';
|
|
25
28
|
import { renderCompat } from '../util/vue-compat';
|
|
26
29
|
|
|
@@ -400,6 +403,72 @@ const testSetups = {
|
|
|
400
403
|
document.body.appendChild(document.createElement('div'))
|
|
401
404
|
);
|
|
402
405
|
|
|
406
|
+
await nextTick();
|
|
407
|
+
},
|
|
408
|
+
async createToggleRefinementWidgetTests({
|
|
409
|
+
instantSearchOptions,
|
|
410
|
+
widgetParams,
|
|
411
|
+
}) {
|
|
412
|
+
mountApp(
|
|
413
|
+
{
|
|
414
|
+
render: renderCompat((h) =>
|
|
415
|
+
h(AisInstantSearch, { props: instantSearchOptions }, [
|
|
416
|
+
h(AisToggleRefinement, { props: widgetParams }),
|
|
417
|
+
h(GlobalErrorSwallower),
|
|
418
|
+
])
|
|
419
|
+
),
|
|
420
|
+
},
|
|
421
|
+
document.body.appendChild(document.createElement('div'))
|
|
422
|
+
);
|
|
423
|
+
|
|
424
|
+
await nextTick();
|
|
425
|
+
},
|
|
426
|
+
async createSearchBoxWidgetTests({ instantSearchOptions, widgetParams }) {
|
|
427
|
+
mountApp(
|
|
428
|
+
{
|
|
429
|
+
render: renderCompat((h) =>
|
|
430
|
+
h(AisInstantSearch, { props: instantSearchOptions }, [
|
|
431
|
+
h(AisSearchBox, { props: widgetParams }),
|
|
432
|
+
h(GlobalErrorSwallower),
|
|
433
|
+
])
|
|
434
|
+
),
|
|
435
|
+
},
|
|
436
|
+
document.body.appendChild(document.createElement('div'))
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
await nextTick();
|
|
440
|
+
},
|
|
441
|
+
async createSortByWidgetTests({ instantSearchOptions, widgetParams }) {
|
|
442
|
+
mountApp(
|
|
443
|
+
{
|
|
444
|
+
render: renderCompat((h) =>
|
|
445
|
+
h(AisInstantSearch, { props: instantSearchOptions }, [
|
|
446
|
+
h(AisSortBy, { props: widgetParams }),
|
|
447
|
+
h(GlobalErrorSwallower),
|
|
448
|
+
])
|
|
449
|
+
),
|
|
450
|
+
},
|
|
451
|
+
document.body.appendChild(document.createElement('div'))
|
|
452
|
+
);
|
|
453
|
+
|
|
454
|
+
await nextTick();
|
|
455
|
+
},
|
|
456
|
+
async createStatsWidgetTests({ instantSearchOptions, widgetParams }) {
|
|
457
|
+
mountApp(
|
|
458
|
+
{
|
|
459
|
+
render: renderCompat((h) =>
|
|
460
|
+
h('div', {}, [
|
|
461
|
+
h(AisInstantSearch, { props: instantSearchOptions }, [
|
|
462
|
+
h(AisSearchBox),
|
|
463
|
+
h(AisStats, { props: widgetParams }),
|
|
464
|
+
h(GlobalErrorSwallower),
|
|
465
|
+
]),
|
|
466
|
+
])
|
|
467
|
+
),
|
|
468
|
+
},
|
|
469
|
+
document.body.appendChild(document.createElement('div'))
|
|
470
|
+
);
|
|
471
|
+
|
|
403
472
|
await nextTick();
|
|
404
473
|
},
|
|
405
474
|
};
|
|
@@ -417,6 +486,12 @@ const testOptions = {
|
|
|
417
486
|
createHitsPerPageWidgetTests: undefined,
|
|
418
487
|
createClearRefinementsWidgetTests: undefined,
|
|
419
488
|
createCurrentRefinementsWidgetTests: undefined,
|
|
489
|
+
createToggleRefinementWidgetTests: undefined,
|
|
490
|
+
createSearchBoxWidgetTests: {
|
|
491
|
+
skippedTests: { 'searchAsYouType option': true },
|
|
492
|
+
},
|
|
493
|
+
createSortByWidgetTests: undefined,
|
|
494
|
+
createStatsWidgetTests: undefined,
|
|
420
495
|
};
|
|
421
496
|
|
|
422
497
|
describe('Common widget tests (Vue InstantSearch)', () => {
|
|
@@ -66,7 +66,7 @@ export default {
|
|
|
66
66
|
props: {
|
|
67
67
|
placeholder: {
|
|
68
68
|
type: String,
|
|
69
|
-
default: '
|
|
69
|
+
default: '',
|
|
70
70
|
},
|
|
71
71
|
autofocus: {
|
|
72
72
|
type: Boolean,
|
|
@@ -74,15 +74,15 @@ export default {
|
|
|
74
74
|
},
|
|
75
75
|
showLoadingIndicator: {
|
|
76
76
|
type: Boolean,
|
|
77
|
-
default:
|
|
77
|
+
default: true,
|
|
78
78
|
},
|
|
79
79
|
submitTitle: {
|
|
80
80
|
type: String,
|
|
81
|
-
default: '
|
|
81
|
+
default: 'Submit the search query',
|
|
82
82
|
},
|
|
83
83
|
resetTitle: {
|
|
84
84
|
type: String,
|
|
85
|
-
default: 'Clear',
|
|
85
|
+
default: 'Clear the search query',
|
|
86
86
|
},
|
|
87
87
|
value: {
|
|
88
88
|
type: String,
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
autocapitalize="off"
|
|
16
16
|
autocomplete="off"
|
|
17
17
|
spellcheck="false"
|
|
18
|
-
required
|
|
19
18
|
maxlength="512"
|
|
20
19
|
aria-label="Search"
|
|
21
20
|
:placeholder="placeholder"
|
|
@@ -39,8 +38,6 @@
|
|
|
39
38
|
<slot name="submit-icon">
|
|
40
39
|
<svg
|
|
41
40
|
aria-hidden="true"
|
|
42
|
-
role="img"
|
|
43
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
44
41
|
width="10"
|
|
45
42
|
height="10"
|
|
46
43
|
viewBox="0 0 40 40"
|
|
@@ -48,7 +45,6 @@
|
|
|
48
45
|
>
|
|
49
46
|
<path
|
|
50
47
|
d="M26.804 29.01c-2.832 2.34-6.465 3.746-10.426 3.746C7.333 32.756 0 25.424 0 16.378 0 7.333 7.333 0 16.378 0c9.046 0 16.378 7.333 16.378 16.378 0 3.96-1.406 7.594-3.746 10.426l10.534 10.534c.607.607.61 1.59-.004 2.202-.61.61-1.597.61-2.202.004L26.804 29.01zm-10.426.627c7.323 0 13.26-5.936 13.26-13.26 0-7.32-5.937-13.257-13.26-13.257C9.056 3.12 3.12 9.056 3.12 16.378c0 7.323 5.936 13.26 13.258 13.26z"
|
|
51
|
-
fillRule="evenodd"
|
|
52
48
|
/>
|
|
53
49
|
</svg>
|
|
54
50
|
</slot>
|
|
@@ -66,15 +62,13 @@
|
|
|
66
62
|
<slot name="reset-icon">
|
|
67
63
|
<svg
|
|
68
64
|
aria-hidden="true"
|
|
69
|
-
|
|
70
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
71
|
-
style="width: 1em; height: 1em"
|
|
65
|
+
height="10"
|
|
72
66
|
viewBox="0 0 20 20"
|
|
73
67
|
:class="suit('resetIcon')"
|
|
68
|
+
width="10"
|
|
74
69
|
>
|
|
75
70
|
<path
|
|
76
71
|
d="M8.114 10L.944 2.83 0 1.885 1.886 0l.943.943L10 8.113l7.17-7.17.944-.943L20 1.886l-.943.943-7.17 7.17 7.17 7.17.943.944L18.114 20l-.943-.943-7.17-7.17-7.17 7.17-.944.943L0 18.114l.943-.943L8.113 10z"
|
|
77
|
-
fillRule="evenodd"
|
|
78
72
|
/>
|
|
79
73
|
</svg>
|
|
80
74
|
</slot>
|
|
@@ -87,11 +81,10 @@
|
|
|
87
81
|
>
|
|
88
82
|
<slot name="loading-indicator">
|
|
89
83
|
<svg
|
|
90
|
-
|
|
84
|
+
:aria-hidden="!shouldShowLoadingIndicator"
|
|
91
85
|
aria-label="Results are loading"
|
|
92
86
|
width="16"
|
|
93
87
|
height="16"
|
|
94
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
95
88
|
stroke="#444"
|
|
96
89
|
viewBox="0 0 38 38"
|
|
97
90
|
:class="suit('loadingIcon')"
|
package/src/components/Stats.vue
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
<!-- prettier-ignore -->
|
|
8
8
|
<span :class="suit('text')"
|
|
9
9
|
><template v-if="state.areHitsSorted"
|
|
10
|
-
>{{
|
|
11
|
-
><template v-else>{{
|
|
10
|
+
>{{ sortedResultsSentence }}</template
|
|
11
|
+
><template v-else>{{ resultsSentence }}</template
|
|
12
12
|
> found in {{ state.processingTimeMS.toLocaleString() }}ms</span
|
|
13
13
|
>
|
|
14
14
|
</slot>
|
|
@@ -33,6 +33,44 @@ export default {
|
|
|
33
33
|
createSuitMixin({ name: 'Stats' }),
|
|
34
34
|
],
|
|
35
35
|
computed: {
|
|
36
|
+
sortedResultsSentence() {
|
|
37
|
+
const { nbHits, nbSortedHits } = this.state;
|
|
38
|
+
|
|
39
|
+
const suffix = `sorted out of ${nbHits.toLocaleString()}`;
|
|
40
|
+
|
|
41
|
+
if (nbSortedHits === 0) {
|
|
42
|
+
return `No relevant results ${suffix}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (nbSortedHits === 1) {
|
|
46
|
+
return `1 relevant result ${suffix}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (nbSortedHits > 1) {
|
|
50
|
+
return `${(
|
|
51
|
+
nbSortedHits || 0
|
|
52
|
+
).toLocaleString()} relevant results ${suffix}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return '';
|
|
56
|
+
},
|
|
57
|
+
resultsSentence() {
|
|
58
|
+
const { nbHits } = this.state;
|
|
59
|
+
|
|
60
|
+
if (nbHits === 0) {
|
|
61
|
+
return 'No results';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (nbHits === 1) {
|
|
65
|
+
return '1 result';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (nbHits > 1) {
|
|
69
|
+
return `${nbHits.toLocaleString()} results`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return '';
|
|
73
|
+
},
|
|
36
74
|
widgetParams() {
|
|
37
75
|
return {};
|
|
38
76
|
},
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
:checked="state.value.isRefined"
|
|
20
20
|
@change="state.refine(state.value)"
|
|
21
21
|
/>
|
|
22
|
-
<span :class="suit('labelText')">{{ label }}</span>
|
|
22
|
+
<span :class="suit('labelText')">{{ label || state.value.name }}</span>
|
|
23
23
|
<span v-if="state.value.count !== null" :class="suit('count')">{{
|
|
24
24
|
state.value.count.toLocaleString()
|
|
25
25
|
}}</span>
|
|
@@ -10,37 +10,6 @@ import '../../../test/utils/sortedHtmlSerializer';
|
|
|
10
10
|
|
|
11
11
|
const defaultState = {};
|
|
12
12
|
|
|
13
|
-
test('renders HTML correctly', () => {
|
|
14
|
-
__setState(defaultState);
|
|
15
|
-
const wrapper = mount(SearchBox);
|
|
16
|
-
|
|
17
|
-
expect(wrapper.htmlCompat()).toMatchSnapshot();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('with autofocus', () => {
|
|
21
|
-
__setState(defaultState);
|
|
22
|
-
const wrapper = mount(SearchBox, {
|
|
23
|
-
propsData: {
|
|
24
|
-
autofocus: true,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
expect(wrapper.find('.ais-SearchBox-input')).vueToBeAutofocused();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('with placeholder', () => {
|
|
32
|
-
__setState(defaultState);
|
|
33
|
-
const wrapper = mount(SearchBox, {
|
|
34
|
-
propsData: {
|
|
35
|
-
placeholder: 'Search placeholder',
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
expect(wrapper.find('.ais-SearchBox-input').attributes().placeholder).toBe(
|
|
40
|
-
'Search placeholder'
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
13
|
test('with submit title', () => {
|
|
45
14
|
__setState(defaultState);
|
|
46
15
|
const wrapper = mount(SearchBox, {
|
|
@@ -67,47 +36,11 @@ test('with reset title', () => {
|
|
|
67
36
|
);
|
|
68
37
|
});
|
|
69
38
|
|
|
70
|
-
test('with reset button hidden without refinement', () => {
|
|
71
|
-
__setState({ ...defaultState });
|
|
72
|
-
|
|
73
|
-
const wrapper = mount(SearchBox);
|
|
74
|
-
|
|
75
|
-
expect(wrapper.find('.ais-SearchBox-reset')).vueToBeHidden();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('with reset button visible with refinement', () => {
|
|
79
|
-
__setState({
|
|
80
|
-
...defaultState,
|
|
81
|
-
query: 'Hello',
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const wrapper = mount(SearchBox);
|
|
85
|
-
|
|
86
|
-
expect(wrapper.find('.ais-SearchBox-reset')).not.vueToBeHidden();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('with stalled search hides the submit, reset and displays the loader', () => {
|
|
90
|
-
__setState({
|
|
91
|
-
...defaultState,
|
|
92
|
-
isSearchStalled: true,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const wrapper = mount(SearchBox, {
|
|
96
|
-
propsData: {
|
|
97
|
-
showLoadingIndicator: true,
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
expect(wrapper.find('.ais-SearchBox-submit')).vueToBeHidden();
|
|
102
|
-
|
|
103
|
-
expect(wrapper.find('.ais-SearchBox-reset')).vueToBeHidden();
|
|
104
|
-
|
|
105
|
-
expect(wrapper.find('.ais-SearchBox-loadingIndicator').exists()).toBe(true);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
39
|
test('with stalled search but no `showLoadingIndicator` displays the submit and hides reset, loader', () => {
|
|
109
40
|
__setState({ ...defaultState, isSearchStalled: true });
|
|
110
|
-
const wrapper = mount(SearchBox
|
|
41
|
+
const wrapper = mount(SearchBox, {
|
|
42
|
+
propsData: { showLoadingIndicator: false },
|
|
43
|
+
});
|
|
111
44
|
|
|
112
45
|
expect(wrapper.find('.ais-SearchBox-submit')).not.vueToBeHidden();
|
|
113
46
|
|
|
@@ -118,11 +51,7 @@ test('with stalled search but no `showLoadingIndicator` displays the submit and
|
|
|
118
51
|
|
|
119
52
|
test('with not stalled search displays the submit and hides reset, loader', () => {
|
|
120
53
|
__setState(defaultState);
|
|
121
|
-
const wrapper = mount(SearchBox
|
|
122
|
-
propsData: {
|
|
123
|
-
showLoadingIndicator: true,
|
|
124
|
-
},
|
|
125
|
-
});
|
|
54
|
+
const wrapper = mount(SearchBox);
|
|
126
55
|
|
|
127
56
|
expect(wrapper.find('.ais-SearchBox-submit')).not.vueToBeHidden();
|
|
128
57
|
|
|
@@ -204,34 +133,34 @@ test('overriding slots', () => {
|
|
|
204
133
|
|
|
205
134
|
expect(htmlCompat(wrapper.find('.ais-SearchBox-submit').html()))
|
|
206
135
|
.toMatchInlineSnapshot(`
|
|
207
|
-
<button class="ais-SearchBox-submit"
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
>
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
</button>
|
|
216
|
-
`);
|
|
136
|
+
<button class="ais-SearchBox-submit"
|
|
137
|
+
hidden="hidden"
|
|
138
|
+
title="Submit the search query"
|
|
139
|
+
type="submit"
|
|
140
|
+
>
|
|
141
|
+
<span>
|
|
142
|
+
SUBMIT
|
|
143
|
+
</span>
|
|
144
|
+
</button>
|
|
145
|
+
`);
|
|
217
146
|
expect(htmlCompat(wrapper.find('.ais-SearchBox-reset').html()))
|
|
218
147
|
.toMatchInlineSnapshot(`
|
|
219
|
-
<button class="ais-SearchBox-reset"
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
>
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
</button>
|
|
228
|
-
`);
|
|
148
|
+
<button class="ais-SearchBox-reset"
|
|
149
|
+
hidden="hidden"
|
|
150
|
+
title="Clear the search query"
|
|
151
|
+
type="reset"
|
|
152
|
+
>
|
|
153
|
+
<span>
|
|
154
|
+
RESET
|
|
155
|
+
</span>
|
|
156
|
+
</button>
|
|
157
|
+
`);
|
|
229
158
|
expect(wrapper.find('.ais-SearchBox-loadingIndicator').html())
|
|
230
159
|
.toMatchInlineSnapshot(`
|
|
231
|
-
<span class="ais-SearchBox-loadingIndicator">
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
</span>
|
|
236
|
-
`);
|
|
160
|
+
<span class="ais-SearchBox-loadingIndicator">
|
|
161
|
+
<span>
|
|
162
|
+
LOADING...
|
|
163
|
+
</span>
|
|
164
|
+
</span>
|
|
165
|
+
`);
|
|
237
166
|
});
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @jest-environment jsdom
|
|
3
3
|
*/
|
|
4
|
-
import { getByRole } from '@testing-library/dom';
|
|
5
|
-
import userEvent from '@testing-library/user-event';
|
|
6
|
-
|
|
7
4
|
import { mount } from '../../../test/utils';
|
|
8
5
|
import '../../../test/utils/sortedHtmlSerializer';
|
|
9
6
|
import { __setState } from '../../mixins/widget';
|
|
@@ -31,32 +28,6 @@ const defaultProps = {
|
|
|
31
28
|
],
|
|
32
29
|
};
|
|
33
30
|
|
|
34
|
-
it('accepts transformItems prop', () => {
|
|
35
|
-
__setState({ ...defaultState });
|
|
36
|
-
|
|
37
|
-
const transformItems = () => {};
|
|
38
|
-
|
|
39
|
-
const wrapper = mount(SortBy, {
|
|
40
|
-
propsData: {
|
|
41
|
-
...defaultProps,
|
|
42
|
-
transformItems,
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
expect(wrapper.vm.widgetParams.transformItems).toBe(transformItems);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('renders correctly', () => {
|
|
50
|
-
__setState({ ...defaultState });
|
|
51
|
-
|
|
52
|
-
const wrapper = mount(SortBy, {
|
|
53
|
-
propsData: {
|
|
54
|
-
...defaultProps,
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
expect(wrapper.html()).toMatchSnapshot();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
31
|
it('renders with scoped slots', () => {
|
|
61
32
|
const defaultSlot = `
|
|
62
33
|
<template v-slot="{ items, refine, currentRefinement }">
|
|
@@ -91,27 +62,3 @@ it('renders with scoped slots', () => {
|
|
|
91
62
|
|
|
92
63
|
expect(wrapper.html()).toMatchSnapshot();
|
|
93
64
|
});
|
|
94
|
-
|
|
95
|
-
it('calls `refine` when the selection changes with the `value`', () => {
|
|
96
|
-
const refine = jest.fn();
|
|
97
|
-
__setState({
|
|
98
|
-
...defaultState,
|
|
99
|
-
refine,
|
|
100
|
-
});
|
|
101
|
-
const wrapper = mount(SortBy, {
|
|
102
|
-
propsData: {
|
|
103
|
-
...defaultProps,
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
userEvent.selectOptions(
|
|
108
|
-
getByRole(wrapper.element, 'combobox'),
|
|
109
|
-
getByRole(wrapper.element, 'option', { name: 'Quality ascending' })
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
expect(refine).toHaveBeenCalledTimes(1);
|
|
113
|
-
expect(refine).toHaveBeenLastCalledWith('some_index_quality');
|
|
114
|
-
expect(
|
|
115
|
-
getByRole(wrapper.element, 'option', { name: 'Quality ascending' }).selected
|
|
116
|
-
).toBe(true);
|
|
117
|
-
});
|