vue-instantsearch 4.10.5 → 4.10.6

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 CHANGED
@@ -16,7 +16,7 @@
16
16
  "autocomplete"
17
17
  ],
18
18
  "license": "MIT",
19
- "version": "4.10.5",
19
+ "version": "4.10.6",
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.5",
38
+ "instantsearch.js": "4.56.6",
39
39
  "mitt": "^2.1.0"
40
40
  },
41
41
  "peerDependencies": {
@@ -60,7 +60,7 @@
60
60
  "@vue/test-utils": "1.3.0",
61
61
  "@vue/test-utils2": "npm:@vue/test-utils@2.0.0-rc.11",
62
62
  "algoliasearch": "4.14.3",
63
- "algoliasearch-helper": "3.13.2",
63
+ "algoliasearch-helper": "3.13.4",
64
64
  "instantsearch.css": "8.0.0",
65
65
  "rollup": "1.32.1",
66
66
  "rollup-plugin-babel": "4.4.0",
@@ -87,5 +87,5 @@
87
87
  "vuex": "3.5.1",
88
88
  "vuex4": "npm:vuex@4.0.0"
89
89
  },
90
- "gitHead": "99119060ec345379181f0446ea4ca8d7cf331354"
90
+ "gitHead": "eedac3a158042dac41cc818439e585ed1b482250"
91
91
  }
@@ -0,0 +1,359 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ import * as testSuites from '@instantsearch/tests/connectors';
5
+
6
+ import { nextTick, mountApp } from '../../test/utils';
7
+ import { renderCompat } from '../util/vue-compat';
8
+ import {
9
+ AisInstantSearch,
10
+ AisMenu,
11
+ AisRefinementList,
12
+ createWidgetMixin,
13
+ } from '../instantsearch';
14
+ import {
15
+ connectBreadcrumb,
16
+ connectCurrentRefinements,
17
+ connectHierarchicalMenu,
18
+ connectHitsPerPage,
19
+ connectMenu,
20
+ connectNumericMenu,
21
+ connectPagination,
22
+ connectRatingMenu,
23
+ connectRefinementList,
24
+ connectToggleRefinement,
25
+ } from 'instantsearch.js/es/connectors';
26
+ import { runTestSuites } from '@instantsearch/tests/common';
27
+ jest.unmock('instantsearch.js/es');
28
+
29
+ const testSetups = {
30
+ async createRefinementListConnectorTests({
31
+ instantSearchOptions,
32
+ widgetParams,
33
+ }) {
34
+ const CustomRefinementList = createCustomWidget({
35
+ connector: connectRefinementList,
36
+ name: 'RefinementList',
37
+ requiredProps: ['attribute'],
38
+ urlValue: 'value',
39
+ refineValue: 'Apple',
40
+ });
41
+
42
+ mountApp(
43
+ {
44
+ render: renderCompat((h) =>
45
+ h(AisInstantSearch, { props: instantSearchOptions }, [
46
+ h(CustomRefinementList, { props: widgetParams }),
47
+ ])
48
+ ),
49
+ },
50
+ document.body.appendChild(document.createElement('div'))
51
+ );
52
+
53
+ await nextTick();
54
+ },
55
+ async createHierarchicalMenuConnectorTests({
56
+ instantSearchOptions,
57
+ widgetParams,
58
+ }) {
59
+ const CustomHierarchicalMenu = createCustomWidget({
60
+ connector: connectHierarchicalMenu,
61
+ name: 'HierarchicalMenu',
62
+ requiredProps: ['attributes'],
63
+ urlValue: 'value',
64
+ refineValue: 'Apple',
65
+ });
66
+
67
+ mountApp(
68
+ {
69
+ render: renderCompat((h) =>
70
+ h(AisInstantSearch, { props: instantSearchOptions }, [
71
+ h(CustomHierarchicalMenu, { props: widgetParams }),
72
+ ])
73
+ ),
74
+ },
75
+ document.body.appendChild(document.createElement('div'))
76
+ );
77
+
78
+ await nextTick();
79
+ },
80
+ async createBreadcrumbConnectorTests({ instantSearchOptions, widgetParams }) {
81
+ const CustomBreadcrumb = createCustomWidget({
82
+ connector: connectBreadcrumb,
83
+ name: 'Breadcrumb',
84
+ requiredProps: ['attributes'],
85
+ urlValue: 'Apple > iPhone',
86
+ refineValue: 'Apple',
87
+ });
88
+
89
+ mountApp(
90
+ {
91
+ render: renderCompat((h) =>
92
+ h(AisInstantSearch, { props: instantSearchOptions }, [
93
+ h(CustomBreadcrumb, { props: widgetParams }),
94
+ ])
95
+ ),
96
+ },
97
+ document.body.appendChild(document.createElement('div'))
98
+ );
99
+
100
+ await nextTick();
101
+ },
102
+ async createMenuConnectorTests({ instantSearchOptions, widgetParams }) {
103
+ const CustomMenu = createCustomWidget({
104
+ connector: connectMenu,
105
+ name: 'Menu',
106
+ requiredProps: ['attribute'],
107
+ urlValue: 'value',
108
+ refineValue: 'Apple',
109
+ });
110
+
111
+ mountApp(
112
+ {
113
+ render: renderCompat((h) =>
114
+ h(AisInstantSearch, { props: instantSearchOptions }, [
115
+ h(CustomMenu, { props: widgetParams }),
116
+ h(AisMenu, { props: widgetParams }),
117
+ ])
118
+ ),
119
+ },
120
+ document.body.appendChild(document.createElement('div'))
121
+ );
122
+
123
+ await nextTick();
124
+ },
125
+ async createPaginationConnectorTests({ instantSearchOptions, widgetParams }) {
126
+ const CustomPagination = createCustomWidget({
127
+ connector: connectPagination,
128
+ name: 'Pagination',
129
+ urlValue: 10,
130
+ refineValue: (state) => (state.currentRefinement === 0 ? 1 : 0),
131
+ });
132
+
133
+ mountApp(
134
+ {
135
+ render: renderCompat((h) =>
136
+ h(AisInstantSearch, { props: instantSearchOptions }, [
137
+ h(CustomPagination, { props: widgetParams }),
138
+ ])
139
+ ),
140
+ },
141
+ document.body.appendChild(document.createElement('div'))
142
+ );
143
+
144
+ await nextTick();
145
+ },
146
+ async createCurrentRefinementsConnectorTests({
147
+ instantSearchOptions,
148
+ widgetParams,
149
+ }) {
150
+ const CustomCurrentRefinements = createCustomWidget({
151
+ connector: connectCurrentRefinements,
152
+ name: 'CurrentRefinements',
153
+ urlValue: {
154
+ attribute: 'brand',
155
+ type: 'disjunctive',
156
+ value: 'Apple',
157
+ label: 'Apple',
158
+ },
159
+ refineValue: {
160
+ attribute: 'brand',
161
+ type: 'disjunctive',
162
+ value: 'Samsung',
163
+ label: 'Samsung',
164
+ },
165
+ });
166
+
167
+ mountApp(
168
+ {
169
+ render: renderCompat((h) =>
170
+ h(AisInstantSearch, { props: instantSearchOptions }, [
171
+ h(CustomCurrentRefinements, { props: widgetParams }),
172
+ h(AisRefinementList, { props: { attribute: 'brand' } }),
173
+ ])
174
+ ),
175
+ },
176
+ document.body.appendChild(document.createElement('div'))
177
+ );
178
+
179
+ await nextTick();
180
+ },
181
+ async createHitsPerPageConnectorTests({
182
+ instantSearchOptions,
183
+ widgetParams,
184
+ }) {
185
+ const CustomHitsPerPage = createCustomWidget({
186
+ connector: connectHitsPerPage,
187
+ name: 'HitsPerPage',
188
+ requiredProps: ['items'],
189
+ urlValue: 12,
190
+ refineValue: (state) => (state.value === 10 ? 5 : 10),
191
+ });
192
+
193
+ mountApp(
194
+ {
195
+ render: renderCompat((h) =>
196
+ h(AisInstantSearch, { props: instantSearchOptions }, [
197
+ h(CustomHitsPerPage, { props: widgetParams }),
198
+ ])
199
+ ),
200
+ },
201
+ document.body.appendChild(document.createElement('div'))
202
+ );
203
+
204
+ await nextTick();
205
+ },
206
+ async createNumericMenuConnectorTests({
207
+ instantSearchOptions,
208
+ widgetParams,
209
+ }) {
210
+ const CustomNumericMenu = createCustomWidget({
211
+ connector: connectNumericMenu,
212
+ name: 'NumericMenu',
213
+ requiredProps: ['attribute', 'items'],
214
+ urlValue: encodeURI('{ "start": 500 }'),
215
+ });
216
+
217
+ mountApp(
218
+ {
219
+ render: renderCompat((h) =>
220
+ h(AisInstantSearch, { props: instantSearchOptions }, [
221
+ h(CustomNumericMenu, { props: widgetParams }),
222
+ ])
223
+ ),
224
+ },
225
+ document.body.appendChild(document.createElement('div'))
226
+ );
227
+
228
+ await nextTick();
229
+ },
230
+ async createRatingMenuConnectorTests({ instantSearchOptions, widgetParams }) {
231
+ const CustomRatingMenu = createCustomWidget({
232
+ connector: connectRatingMenu,
233
+ name: 'RatingMenu',
234
+ requiredProps: ['attribute'],
235
+ urlValue: encodeURI('5'),
236
+ });
237
+
238
+ mountApp(
239
+ {
240
+ render: renderCompat((h) =>
241
+ h(AisInstantSearch, { props: instantSearchOptions }, [
242
+ h(CustomRatingMenu, { props: widgetParams }),
243
+ ])
244
+ ),
245
+ },
246
+ document.body.appendChild(document.createElement('div'))
247
+ );
248
+
249
+ await nextTick();
250
+ },
251
+ async createToggleRefinementConnectorTests({
252
+ instantSearchOptions,
253
+ widgetParams,
254
+ }) {
255
+ const CustomToggleRefinement = createCustomWidget({
256
+ name: 'ToggleRefinement',
257
+ connector: connectToggleRefinement,
258
+ requiredProps: ['attribute', 'label'],
259
+ refineValue: (state) => state.value,
260
+ });
261
+
262
+ // Label is required in Vue
263
+ const props = {
264
+ ...widgetParams,
265
+ label: 'Free Shipping',
266
+ };
267
+
268
+ mountApp(
269
+ {
270
+ render: renderCompat((h) =>
271
+ h(AisInstantSearch, { props: instantSearchOptions }, [
272
+ h(CustomToggleRefinement, { props }),
273
+ ])
274
+ ),
275
+ },
276
+ document.body.appendChild(document.createElement('div'))
277
+ );
278
+
279
+ await nextTick();
280
+ },
281
+ };
282
+
283
+ function createCustomWidget({
284
+ connector,
285
+ name,
286
+ urlValue,
287
+ refineValue,
288
+ requiredProps = [],
289
+ }) {
290
+ return {
291
+ name: `Custom${name}`,
292
+ mixins: [createWidgetMixin({ connector })],
293
+ props: Object.fromEntries(
294
+ requiredProps.map((prop) => [prop, { required: true }])
295
+ ),
296
+ computed: {
297
+ widgetParams() {
298
+ return Object.fromEntries(
299
+ requiredProps.map((prop) => [prop, this[prop]])
300
+ );
301
+ },
302
+ },
303
+ render: renderCompat(function (h) {
304
+ return this.state
305
+ ? h('div', {}, [
306
+ h(
307
+ 'a',
308
+ {
309
+ attrs: {
310
+ 'data-testid': `${name}-link`,
311
+ href: this.state.createURL(urlValue),
312
+ },
313
+ },
314
+ 'LINK'
315
+ ),
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
+ ),
334
+ ])
335
+ : null;
336
+ }),
337
+ };
338
+ }
339
+
340
+ const testOptions = {
341
+ createHierarchicalMenuConnectorTests: undefined,
342
+ createBreadcrumbConnectorTests: undefined,
343
+ createRefinementListConnectorTests: undefined,
344
+ createMenuConnectorTests: undefined,
345
+ createPaginationConnectorTests: undefined,
346
+ createCurrentRefinementsConnectorTests: undefined,
347
+ createHitsPerPageConnectorTests: undefined,
348
+ createNumericMenuConnectorTests: undefined,
349
+ createRatingMenuConnectorTests: undefined,
350
+ createToggleRefinementConnectorTests: undefined,
351
+ };
352
+
353
+ describe('Common connector tests (Vue InstantSearch)', () => {
354
+ runTestSuites({
355
+ testSuites,
356
+ testSetups,
357
+ testOptions,
358
+ });
359
+ });
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ import * as testSuites from '@instantsearch/tests/shared';
5
+
6
+ import { nextTick, mountApp } from '../../test/utils';
7
+ import { renderCompat } from '../util/vue-compat';
8
+ import {
9
+ AisHits,
10
+ AisInstantSearch,
11
+ AisMenu,
12
+ AisPagination,
13
+ createWidgetMixin,
14
+ } from '../instantsearch';
15
+ import { connectMenu, connectPagination } from 'instantsearch.js/es/connectors';
16
+ import { runTestSuites } from '@instantsearch/tests/common';
17
+ jest.unmock('instantsearch.js/es');
18
+
19
+ const testSetups = {
20
+ async createSharedTests({ instantSearchOptions, widgetParams }) {
21
+ const CustomMenu = createCustomWidget({
22
+ connector: connectMenu,
23
+ name: 'Menu',
24
+ requiredProps: ['attribute'],
25
+ urlValue: 'value',
26
+ });
27
+ const CustomPagination = createCustomWidget({
28
+ connector: connectPagination,
29
+ name: 'Pagination',
30
+ urlValue: 10,
31
+ });
32
+
33
+ mountApp(
34
+ {
35
+ render: renderCompat((h) =>
36
+ h(AisInstantSearch, { props: instantSearchOptions }, [
37
+ h(CustomMenu, { props: widgetParams.menu }),
38
+ h(AisMenu, { props: widgetParams.menu }),
39
+ h(AisHits, { props: widgetParams.hits }),
40
+ h(CustomPagination, { props: widgetParams.pagination }),
41
+ h(AisPagination, { props: widgetParams.pagination }),
42
+ ])
43
+ ),
44
+ },
45
+ document.body.appendChild(document.createElement('div'))
46
+ );
47
+
48
+ await nextTick();
49
+ },
50
+ };
51
+
52
+ function createCustomWidget({ connector, name, urlValue, requiredProps = [] }) {
53
+ return {
54
+ name: `Custom${name}`,
55
+ mixins: [createWidgetMixin({ connector })],
56
+ props: Object.fromEntries(
57
+ requiredProps.map((prop) => [prop, { required: true }])
58
+ ),
59
+ computed: {
60
+ widgetParams() {
61
+ return Object.fromEntries(
62
+ requiredProps.map((prop) => [prop, this[prop]])
63
+ );
64
+ },
65
+ },
66
+ render: renderCompat(function (h) {
67
+ return this.state
68
+ ? h(
69
+ 'a',
70
+ {
71
+ attrs: {
72
+ 'data-testid': `${name}-link`,
73
+ href: this.state.createURL(urlValue),
74
+ },
75
+ },
76
+ 'LINK'
77
+ )
78
+ : null;
79
+ }),
80
+ };
81
+ }
82
+
83
+ const testOptions = {
84
+ createSharedTests: undefined,
85
+ };
86
+
87
+ describe('Common shared tests (Vue InstantSearch)', () => {
88
+ runTestSuites({
89
+ testSuites,
90
+ testSetups,
91
+ testOptions,
92
+ });
93
+ });