vue-instantsearch 4.10.8 → 4.10.10
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-widgets.test.js +46 -0
- package/src/components/ClearRefinements.vue +1 -0
- package/src/components/Menu.vue +3 -3
- package/src/components/__tests__/Menu.js +5 -564
- 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/Menu.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/ClearRefinements.vue.js +1 -1
- package/vue3/es/src/components/ClearRefinements.vue_vue&type=script&lang.js.map +1 -1
- package/vue3/es/src/components/{ClearRefinements.vue_vue&type=template&id=302b873a&lang.js → ClearRefinements.vue_vue&type=template&id=41d81b11&lang.js} +1 -1
- package/vue3/es/src/components/ClearRefinements.vue_vue&type=template&id=41d81b11&lang.js.map +1 -0
- package/vue3/es/src/components/Menu.vue.js +1 -1
- package/vue3/es/src/components/Menu.vue_vue&type=script&lang.js.map +1 -1
- package/vue3/es/src/components/{Menu.vue_vue&type=template&id=8e757064&lang.js → Menu.vue_vue&type=template&id=55b32cf6&lang.js} +1 -1
- package/vue3/es/src/components/Menu.vue_vue&type=template&id=55b32cf6&lang.js.map +1 -0
- package/vue3/umd/index.js +1 -1
- package/vue3/umd/index.js.map +1 -1
- package/src/components/__tests__/HitsPerPage.js +0 -85
- package/src/components/__tests__/__snapshots__/HitsPerPage.js.snap +0 -18
- package/src/components/__tests__/__snapshots__/Menu.js.snap +0 -503
- package/vue3/es/src/components/ClearRefinements.vue_vue&type=template&id=302b873a&lang.js.map +0 -1
- package/vue3/es/src/components/Menu.vue_vue&type=template&id=8e757064&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.10.
|
|
19
|
+
"version": "4.10.10",
|
|
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.56.
|
|
38
|
+
"instantsearch.js": "4.56.10",
|
|
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": "90a5e43746613d2f9eb3dc49fa15b1895d45c7bd"
|
|
91
91
|
}
|
|
@@ -18,6 +18,9 @@ import {
|
|
|
18
18
|
AisHits,
|
|
19
19
|
AisIndex,
|
|
20
20
|
AisRangeInput,
|
|
21
|
+
AisHitsPerPage,
|
|
22
|
+
AisClearRefinements,
|
|
23
|
+
AisCurrentRefinements,
|
|
21
24
|
} from '../instantsearch';
|
|
22
25
|
import { renderCompat } from '../util/vue-compat';
|
|
23
26
|
|
|
@@ -320,6 +323,47 @@ const testSetups = {
|
|
|
320
323
|
],
|
|
321
324
|
};
|
|
322
325
|
},
|
|
326
|
+
async createHitsPerPageWidgetTests({ instantSearchOptions, widgetParams }) {
|
|
327
|
+
mountApp(
|
|
328
|
+
{
|
|
329
|
+
render: renderCompat((h) =>
|
|
330
|
+
h(AisInstantSearch, { props: instantSearchOptions }, [
|
|
331
|
+
h(AisHitsPerPage, { props: widgetParams }),
|
|
332
|
+
h(GlobalErrorSwallower),
|
|
333
|
+
])
|
|
334
|
+
),
|
|
335
|
+
},
|
|
336
|
+
document.body.appendChild(document.createElement('div'))
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
await nextTick();
|
|
340
|
+
},
|
|
341
|
+
async createClearRefinementsWidgetTests({
|
|
342
|
+
instantSearchOptions,
|
|
343
|
+
widgetParams,
|
|
344
|
+
}) {
|
|
345
|
+
const refinementListAttributes = Object.keys(
|
|
346
|
+
instantSearchOptions.initialUiState?.indexName.refinementList || {}
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
mountApp(
|
|
350
|
+
{
|
|
351
|
+
render: renderCompat((h) =>
|
|
352
|
+
h(AisInstantSearch, { props: instantSearchOptions }, [
|
|
353
|
+
...refinementListAttributes.map((attribute) =>
|
|
354
|
+
h(AisRefinementList, { props: { attribute } })
|
|
355
|
+
),
|
|
356
|
+
h(AisCurrentRefinements),
|
|
357
|
+
h(AisClearRefinements, { props: widgetParams }),
|
|
358
|
+
h(GlobalErrorSwallower),
|
|
359
|
+
])
|
|
360
|
+
),
|
|
361
|
+
},
|
|
362
|
+
document.body.appendChild(document.createElement('div'))
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
await nextTick();
|
|
366
|
+
},
|
|
323
367
|
};
|
|
324
368
|
|
|
325
369
|
const testOptions = {
|
|
@@ -332,6 +376,8 @@ const testOptions = {
|
|
|
332
376
|
createHitsWidgetTests: undefined,
|
|
333
377
|
createRangeInputWidgetTests: undefined,
|
|
334
378
|
createInstantSearchWidgetTests: undefined,
|
|
379
|
+
createHitsPerPageWidgetTests: undefined,
|
|
380
|
+
createClearRefinementsWidgetTests: undefined,
|
|
335
381
|
};
|
|
336
382
|
|
|
337
383
|
describe('Common widget tests (Vue InstantSearch)', () => {
|
package/src/components/Menu.vue
CHANGED
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
:disabled="!state.canToggleShowMore"
|
|
40
40
|
@click.prevent="state.toggleShowMore()"
|
|
41
41
|
>
|
|
42
|
-
<slot name="showMoreLabel" :is-showing-more="state.isShowingMore">
|
|
43
|
-
|
|
44
|
-
</slot>
|
|
42
|
+
<slot name="showMoreLabel" :is-showing-more="state.isShowingMore">{{
|
|
43
|
+
state.isShowingMore ? 'Show less' : 'Show more'
|
|
44
|
+
}}</slot>
|
|
45
45
|
</button>
|
|
46
46
|
</slot>
|
|
47
47
|
</div>
|
|
@@ -10,337 +10,20 @@ import '../../../test/utils/sortedHtmlSerializer';
|
|
|
10
10
|
jest.mock('../../mixins/widget');
|
|
11
11
|
jest.mock('../../mixins/panel');
|
|
12
12
|
|
|
13
|
-
const apple = {
|
|
14
|
-
value: 'Apple',
|
|
15
|
-
label: 'Apple',
|
|
16
|
-
count: 50,
|
|
17
|
-
isRefined: false,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const samsung = {
|
|
21
|
-
value: 'Samsung',
|
|
22
|
-
label: 'Samsung',
|
|
23
|
-
count: 25,
|
|
24
|
-
isRefined: false,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const microsoft = {
|
|
28
|
-
value: 'Microsoft',
|
|
29
|
-
label: 'Microsoft',
|
|
30
|
-
count: 12,
|
|
31
|
-
isRefined: false,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const defaultState = {
|
|
35
|
-
items: [apple, samsung, microsoft],
|
|
36
|
-
canRefine: true,
|
|
37
|
-
canToggleShowMore: false,
|
|
38
|
-
isShowingMore: false,
|
|
39
|
-
refine: () => {},
|
|
40
|
-
createURL: () => {},
|
|
41
|
-
toggleShowMore: () => {},
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const defaultProps = {
|
|
45
|
-
attribute: 'brand',
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
it('accepts an attribute prop', () => {
|
|
49
|
-
__setState({
|
|
50
|
-
...defaultState,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const props = {
|
|
54
|
-
...defaultProps,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const wrapper = mount(Menu, {
|
|
58
|
-
propsData: props,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
expect(wrapper.vm.widgetParams.attribute).toBe('brand');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('accepts a limit prop', () => {
|
|
65
|
-
__setState({
|
|
66
|
-
...defaultState,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const props = {
|
|
70
|
-
...defaultProps,
|
|
71
|
-
limit: 5,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const wrapper = mount(Menu, {
|
|
75
|
-
propsData: props,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
expect(wrapper.vm.widgetParams.limit).toBe(5);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('accepts a showMoreLimit prop', () => {
|
|
82
|
-
__setState({
|
|
83
|
-
...defaultState,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const props = {
|
|
87
|
-
...defaultProps,
|
|
88
|
-
showMoreLimit: 10,
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const wrapper = mount(Menu, {
|
|
92
|
-
propsData: props,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
expect(wrapper.vm.widgetParams.showMoreLimit).toBe(10);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('accepts a sortBy prop', () => {
|
|
99
|
-
__setState({
|
|
100
|
-
...defaultState,
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const props = {
|
|
104
|
-
...defaultProps,
|
|
105
|
-
sortBy: ['name:desc'],
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const wrapper = mount(Menu, {
|
|
109
|
-
propsData: props,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
expect(wrapper.vm.widgetParams.sortBy).toEqual(['name:desc']);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('accepts a transformItems prop', () => {
|
|
116
|
-
__setState({
|
|
117
|
-
...defaultState,
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
const transformItems = () => {};
|
|
121
|
-
|
|
122
|
-
const props = {
|
|
123
|
-
...defaultProps,
|
|
124
|
-
transformItems,
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const wrapper = mount(Menu, {
|
|
128
|
-
propsData: props,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
expect(wrapper.vm.widgetParams.transformItems).toBe(transformItems);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe('default render', () => {
|
|
135
|
-
it('renders correctly', () => {
|
|
136
|
-
__setState({ ...defaultState });
|
|
137
|
-
|
|
138
|
-
const wrapper = mount(Menu, {
|
|
139
|
-
propsData: defaultProps,
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
expect(wrapper.html()).toMatchSnapshot();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('renders correctly without refinement', () => {
|
|
146
|
-
__setState({
|
|
147
|
-
...defaultState,
|
|
148
|
-
items: [],
|
|
149
|
-
canRefine: false,
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
const wrapper = mount(Menu, {
|
|
153
|
-
propsData: defaultProps,
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
expect(wrapper.findAll('.ais-Menu--noRefinement')).toHaveLength(1);
|
|
157
|
-
expect(wrapper.html()).toMatchSnapshot();
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('renders correctly with a selected item', () => {
|
|
161
|
-
__setState({
|
|
162
|
-
...defaultState,
|
|
163
|
-
items: [
|
|
164
|
-
apple,
|
|
165
|
-
{
|
|
166
|
-
...samsung,
|
|
167
|
-
isRefined: true,
|
|
168
|
-
},
|
|
169
|
-
microsoft,
|
|
170
|
-
],
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
const wrapper = mount(Menu, {
|
|
174
|
-
propsData: defaultProps,
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
expect(wrapper.findAll('.ais-Menu-item--selected')).toHaveLength(1);
|
|
178
|
-
expect(wrapper.find('.ais-Menu-item--selected .ais-Menu-link').html())
|
|
179
|
-
.toMatchInlineSnapshot(`
|
|
180
|
-
<a class="ais-Menu-link">
|
|
181
|
-
<span class="ais-Menu-label">
|
|
182
|
-
Samsung
|
|
183
|
-
</span>
|
|
184
|
-
<span class="ais-Menu-count">
|
|
185
|
-
25
|
|
186
|
-
</span>
|
|
187
|
-
</a>
|
|
188
|
-
`);
|
|
189
|
-
expect(wrapper.html()).toMatchSnapshot();
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it('renders correctly with a URL for the href', () => {
|
|
193
|
-
__setState({
|
|
194
|
-
...defaultState,
|
|
195
|
-
createURL: (value) => `/brand/${value}`,
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
const wrapper = mount(Menu, {
|
|
199
|
-
propsData: defaultProps,
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
expect(wrapper.find('.ais-Menu-link').attributes().href).toBe(
|
|
203
|
-
'/brand/Apple'
|
|
204
|
-
);
|
|
205
|
-
expect(wrapper.html()).toMatchSnapshot();
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('renders correctly with show more button', () => {
|
|
209
|
-
__setState({ ...defaultState });
|
|
210
|
-
|
|
211
|
-
const wrapper = mount(Menu, {
|
|
212
|
-
propsData: {
|
|
213
|
-
...defaultProps,
|
|
214
|
-
showMore: true,
|
|
215
|
-
},
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
expect(wrapper.findAll('.ais-Menu-showMore')).toHaveLength(1);
|
|
219
|
-
expect(wrapper.find('.ais-Menu-showMore').text()).toBe('Show more');
|
|
220
|
-
expect(wrapper.htmlCompat()).toMatchSnapshot();
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('renders correctly with show more button toggled', () => {
|
|
224
|
-
__setState({
|
|
225
|
-
...defaultState,
|
|
226
|
-
isShowingMore: true,
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
const wrapper = mount(Menu, {
|
|
230
|
-
propsData: {
|
|
231
|
-
...defaultProps,
|
|
232
|
-
showMore: true,
|
|
233
|
-
},
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
expect(wrapper.find('.ais-Menu-showMore').text()).toBe('Show less');
|
|
237
|
-
expect(wrapper.htmlCompat()).toMatchSnapshot();
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it('renders correctly with a disabled show more button', () => {
|
|
241
|
-
__setState({
|
|
242
|
-
...defaultState,
|
|
243
|
-
canToggleShowMore: false,
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
const wrapper = mount(Menu, {
|
|
247
|
-
propsData: {
|
|
248
|
-
...defaultProps,
|
|
249
|
-
showMore: true,
|
|
250
|
-
},
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
const showMoreWrapper = wrapper.find('.ais-Menu-showMore');
|
|
254
|
-
|
|
255
|
-
expect(wrapper.findAll('.ais-Menu-showMore')).toHaveLength(1);
|
|
256
|
-
expect(showMoreWrapper.classes()).toContain('ais-Menu-showMore--disabled');
|
|
257
|
-
expect(showMoreWrapper).vueToBeDisabled();
|
|
258
|
-
expect(wrapper.htmlCompat()).toMatchSnapshot();
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('renders correctly without a show more button (canRefine)', () => {
|
|
262
|
-
__setState({
|
|
263
|
-
...defaultState,
|
|
264
|
-
items: [],
|
|
265
|
-
canRefine: false,
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
const wrapper = mount(Menu, {
|
|
269
|
-
propsData: {
|
|
270
|
-
...defaultProps,
|
|
271
|
-
showMore: true,
|
|
272
|
-
},
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
expect(wrapper.findAll('.ais-Menu-showMore')).toHaveLength(0);
|
|
276
|
-
expect(wrapper.html()).toMatchSnapshot();
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it('renders correctly without a show more button (showMore)', () => {
|
|
280
|
-
__setState({ ...defaultState });
|
|
281
|
-
|
|
282
|
-
const wrapper = mount(Menu, {
|
|
283
|
-
propsData: {
|
|
284
|
-
...defaultProps,
|
|
285
|
-
showMore: false,
|
|
286
|
-
},
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
expect(wrapper.findAll('.ais-Menu-showMore')).toHaveLength(0);
|
|
290
|
-
expect(wrapper.html()).toMatchSnapshot();
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it('calls refine on link click', async () => {
|
|
294
|
-
const refine = jest.fn();
|
|
295
|
-
|
|
296
|
-
__setState({
|
|
297
|
-
...defaultState,
|
|
298
|
-
refine,
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
const wrapper = mount(Menu, {
|
|
302
|
-
propsData: defaultProps,
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
await wrapper.find('.ais-Menu-link').trigger('click');
|
|
306
|
-
|
|
307
|
-
expect(refine).toHaveBeenCalledTimes(1);
|
|
308
|
-
expect(refine).toHaveBeenCalledWith('Apple');
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it('calls toggleShowMore on button click', async () => {
|
|
312
|
-
const toggleShowMore = jest.fn();
|
|
313
|
-
|
|
314
|
-
__setState({
|
|
315
|
-
...defaultState,
|
|
316
|
-
canToggleShowMore: true,
|
|
317
|
-
toggleShowMore,
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
const wrapper = mount(Menu, {
|
|
321
|
-
propsData: {
|
|
322
|
-
...defaultProps,
|
|
323
|
-
showMore: true,
|
|
324
|
-
},
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
await wrapper.find('.ais-Menu-showMore').trigger('click');
|
|
328
|
-
|
|
329
|
-
expect(toggleShowMore).toHaveBeenCalledTimes(1);
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
|
|
333
13
|
it('exposes send-event method for insights middleware', async () => {
|
|
334
14
|
const sendEvent = jest.fn();
|
|
335
15
|
__setState({
|
|
336
|
-
...defaultState,
|
|
337
16
|
sendEvent,
|
|
338
17
|
});
|
|
339
18
|
|
|
340
19
|
const wrapper = mount({
|
|
341
20
|
components: { Menu },
|
|
342
21
|
data() {
|
|
343
|
-
return {
|
|
22
|
+
return {
|
|
23
|
+
props: {
|
|
24
|
+
attribute: 'brand',
|
|
25
|
+
},
|
|
26
|
+
};
|
|
344
27
|
},
|
|
345
28
|
template: `
|
|
346
29
|
<Menu v-bind="props">
|
|
@@ -356,245 +39,3 @@ it('exposes send-event method for insights middleware', async () => {
|
|
|
356
39
|
await wrapper.find('button').trigger('click');
|
|
357
40
|
expect(sendEvent).toHaveBeenCalledTimes(1);
|
|
358
41
|
});
|
|
359
|
-
|
|
360
|
-
describe('custom default render', () => {
|
|
361
|
-
const defaultSlot = `
|
|
362
|
-
<template v-slot="state">
|
|
363
|
-
<div :class="[!state.canRefine && 'no-refinement']">
|
|
364
|
-
<ol>
|
|
365
|
-
<li
|
|
366
|
-
v-for="item in state.items"
|
|
367
|
-
:key="item.value"
|
|
368
|
-
>
|
|
369
|
-
<a
|
|
370
|
-
:href="state.createURL(item.value)"
|
|
371
|
-
@click.prevent="state.refine(item.value)"
|
|
372
|
-
>
|
|
373
|
-
{{item.label}} - {{item.count}}
|
|
374
|
-
</a>
|
|
375
|
-
</li>
|
|
376
|
-
</ol>
|
|
377
|
-
<button
|
|
378
|
-
:disabled="!state.canToggleShowMore"
|
|
379
|
-
@click.prevent="state.toggleShowMore"
|
|
380
|
-
>
|
|
381
|
-
{{ state.isShowingMore ? 'Show less' : 'Show more' }}
|
|
382
|
-
</button>
|
|
383
|
-
</div>
|
|
384
|
-
</template>
|
|
385
|
-
`;
|
|
386
|
-
|
|
387
|
-
it('renders correctly', () => {
|
|
388
|
-
__setState({ ...defaultState });
|
|
389
|
-
|
|
390
|
-
const wrapper = mount({
|
|
391
|
-
components: { Menu },
|
|
392
|
-
data() {
|
|
393
|
-
return { props: defaultProps };
|
|
394
|
-
},
|
|
395
|
-
template: `
|
|
396
|
-
<Menu v-bind="props">
|
|
397
|
-
${defaultSlot}
|
|
398
|
-
</Menu>
|
|
399
|
-
`,
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
expect(wrapper.htmlCompat()).toMatchSnapshot();
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
it('renders correctly without refinement', () => {
|
|
406
|
-
__setState({
|
|
407
|
-
...defaultState,
|
|
408
|
-
items: [],
|
|
409
|
-
canRefine: false,
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
const wrapper = mount({
|
|
413
|
-
components: { Menu },
|
|
414
|
-
data() {
|
|
415
|
-
return { props: defaultProps };
|
|
416
|
-
},
|
|
417
|
-
template: `
|
|
418
|
-
<Menu v-bind="props">
|
|
419
|
-
${defaultSlot}
|
|
420
|
-
</Menu>
|
|
421
|
-
`,
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
expect(wrapper.htmlCompat()).toMatchSnapshot();
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
it('renders correctly with an URL for the href', () => {
|
|
428
|
-
__setState({
|
|
429
|
-
...defaultState,
|
|
430
|
-
createURL: (value) => `/brand/${value}`,
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
const wrapper = mount({
|
|
434
|
-
components: { Menu },
|
|
435
|
-
data() {
|
|
436
|
-
return { props: defaultProps };
|
|
437
|
-
},
|
|
438
|
-
template: `
|
|
439
|
-
<Menu v-bind="props">
|
|
440
|
-
${defaultSlot}
|
|
441
|
-
</Menu>
|
|
442
|
-
`,
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
expect(wrapper.htmlCompat()).toMatchSnapshot();
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
it('renders correctly with a show more button toggled', () => {
|
|
449
|
-
__setState({
|
|
450
|
-
...defaultState,
|
|
451
|
-
isShowingMore: true,
|
|
452
|
-
});
|
|
453
|
-
|
|
454
|
-
const wrapper = mount({
|
|
455
|
-
components: { Menu },
|
|
456
|
-
data() {
|
|
457
|
-
return { props: defaultProps };
|
|
458
|
-
},
|
|
459
|
-
template: `
|
|
460
|
-
<Menu v-bind="props">
|
|
461
|
-
${defaultSlot}
|
|
462
|
-
</Menu>
|
|
463
|
-
`,
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
expect(wrapper.htmlCompat()).toMatchSnapshot();
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
it('renders correctly with a disabled show more button', () => {
|
|
470
|
-
__setState({
|
|
471
|
-
...defaultState,
|
|
472
|
-
canToggleShowMore: false,
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
const wrapper = mount({
|
|
476
|
-
components: { Menu },
|
|
477
|
-
data() {
|
|
478
|
-
return { props: defaultProps };
|
|
479
|
-
},
|
|
480
|
-
template: `
|
|
481
|
-
<Menu v-bind="props">
|
|
482
|
-
${defaultSlot}
|
|
483
|
-
</Menu>
|
|
484
|
-
`,
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
expect(wrapper.htmlCompat()).toMatchSnapshot();
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
it('calls refine on link click', async () => {
|
|
491
|
-
const refine = jest.fn();
|
|
492
|
-
|
|
493
|
-
__setState({
|
|
494
|
-
...defaultState,
|
|
495
|
-
refine,
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
const wrapper = mount({
|
|
499
|
-
components: { Menu },
|
|
500
|
-
data() {
|
|
501
|
-
return { props: defaultProps };
|
|
502
|
-
},
|
|
503
|
-
template: `
|
|
504
|
-
<Menu v-bind="props">
|
|
505
|
-
${defaultSlot}
|
|
506
|
-
</Menu>
|
|
507
|
-
`,
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
await wrapper.find('a').trigger('click');
|
|
511
|
-
|
|
512
|
-
expect(refine).toHaveBeenCalledTimes(1);
|
|
513
|
-
expect(refine).toHaveBeenCalledWith('Apple');
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
it('calls toggleShowMore on button click', async () => {
|
|
517
|
-
const toggleShowMore = jest.fn();
|
|
518
|
-
|
|
519
|
-
__setState({
|
|
520
|
-
...defaultState,
|
|
521
|
-
canToggleShowMore: true,
|
|
522
|
-
toggleShowMore,
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
const wrapper = mount({
|
|
526
|
-
components: { Menu },
|
|
527
|
-
data() {
|
|
528
|
-
return { props: defaultProps };
|
|
529
|
-
},
|
|
530
|
-
template: `
|
|
531
|
-
<Menu v-bind="props">
|
|
532
|
-
${defaultSlot}
|
|
533
|
-
</Menu>
|
|
534
|
-
`,
|
|
535
|
-
});
|
|
536
|
-
|
|
537
|
-
await wrapper.find('button').trigger('click');
|
|
538
|
-
|
|
539
|
-
expect(toggleShowMore).toHaveBeenCalledTimes(1);
|
|
540
|
-
});
|
|
541
|
-
});
|
|
542
|
-
|
|
543
|
-
describe('custom showMoreLabel render', () => {
|
|
544
|
-
const showMoreLabelSlot = `
|
|
545
|
-
<template v-slot:showMoreLabel="{ isShowingMore }">
|
|
546
|
-
<span>
|
|
547
|
-
{{ isShowingMore ? 'Voir moins' : 'Voir plus' }}
|
|
548
|
-
</span>
|
|
549
|
-
</template>
|
|
550
|
-
`;
|
|
551
|
-
|
|
552
|
-
it('renders correctly with a custom show more label', () => {
|
|
553
|
-
__setState({ ...defaultState });
|
|
554
|
-
|
|
555
|
-
const props = {
|
|
556
|
-
...defaultProps,
|
|
557
|
-
showMore: true,
|
|
558
|
-
};
|
|
559
|
-
const wrapper = mount({
|
|
560
|
-
components: { Menu },
|
|
561
|
-
data() {
|
|
562
|
-
return { props };
|
|
563
|
-
},
|
|
564
|
-
template: `
|
|
565
|
-
<Menu v-bind="props">
|
|
566
|
-
${showMoreLabelSlot}
|
|
567
|
-
</Menu>
|
|
568
|
-
`,
|
|
569
|
-
});
|
|
570
|
-
|
|
571
|
-
expect(wrapper.find('.ais-Menu-showMore').text()).toBe('Voir plus');
|
|
572
|
-
expect(wrapper.htmlCompat()).toMatchSnapshot();
|
|
573
|
-
});
|
|
574
|
-
|
|
575
|
-
it('renders correctly with a custom show more label toggled', () => {
|
|
576
|
-
__setState({
|
|
577
|
-
...defaultState,
|
|
578
|
-
isShowingMore: true,
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
const props = {
|
|
582
|
-
...defaultProps,
|
|
583
|
-
showMore: true,
|
|
584
|
-
};
|
|
585
|
-
const wrapper = mount({
|
|
586
|
-
components: { Menu },
|
|
587
|
-
data() {
|
|
588
|
-
return { props };
|
|
589
|
-
},
|
|
590
|
-
template: `
|
|
591
|
-
<Menu v-bind="props">
|
|
592
|
-
${showMoreLabelSlot}
|
|
593
|
-
</Menu>
|
|
594
|
-
`,
|
|
595
|
-
});
|
|
596
|
-
|
|
597
|
-
expect(wrapper.find('.ais-Menu-showMore').text()).toBe('Voir moins');
|
|
598
|
-
expect(wrapper.htmlCompat()).toMatchSnapshot();
|
|
599
|
-
});
|
|
600
|
-
});
|