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.
@@ -0,0 +1,343 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+ import * as testSuites from '@instantsearch/tests/widgets';
5
+
6
+ import { nextTick, mountApp } from '../../test/utils';
7
+ import { renderCompat } from '../util/vue-compat';
8
+ import {
9
+ AisInstantSearch,
10
+ AisRefinementList,
11
+ AisHierarchicalMenu,
12
+ AisBreadcrumb,
13
+ AisMenu,
14
+ AisPagination,
15
+ AisInfiniteHits,
16
+ AisSearchBox,
17
+ createWidgetMixin,
18
+ AisHits,
19
+ AisIndex,
20
+ AisRangeInput,
21
+ } from '../instantsearch';
22
+ import { runTestSuites } from '@instantsearch/tests/common';
23
+
24
+ jest.unmock('instantsearch.js/es');
25
+
26
+ /**
27
+ * prevent rethrowing InstantSearch errors, so tests can be asserted.
28
+ * IRL this isn't needed, as the error doesn't stop execution.
29
+ */
30
+ const GlobalErrorSwallower = {
31
+ mixins: [createWidgetMixin({ connector: true })],
32
+ mounted() {
33
+ this.instantSearchInstance.on('error', () => {});
34
+ },
35
+ render() {
36
+ return null;
37
+ },
38
+ };
39
+
40
+ const testSetups = {
41
+ async createRefinementListWidgetTests({
42
+ instantSearchOptions,
43
+ widgetParams,
44
+ }) {
45
+ mountApp(
46
+ {
47
+ render: renderCompat((h) =>
48
+ h(AisInstantSearch, { props: instantSearchOptions }, [
49
+ h(AisRefinementList, { props: widgetParams }),
50
+ h(GlobalErrorSwallower),
51
+ ])
52
+ ),
53
+ },
54
+ document.body.appendChild(document.createElement('div'))
55
+ );
56
+
57
+ await nextTick();
58
+ },
59
+ async createHierarchicalMenuWidgetTests({
60
+ instantSearchOptions,
61
+ widgetParams,
62
+ }) {
63
+ mountApp(
64
+ {
65
+ render: renderCompat((h) =>
66
+ h(AisInstantSearch, { props: instantSearchOptions }, [
67
+ h(AisHierarchicalMenu, { props: widgetParams }),
68
+ h(GlobalErrorSwallower),
69
+ ])
70
+ ),
71
+ },
72
+ document.body.appendChild(document.createElement('div'))
73
+ );
74
+
75
+ await nextTick();
76
+ },
77
+ async createBreadcrumbWidgetTests({ instantSearchOptions, widgetParams }) {
78
+ // The passed `transformItems` prop is meant to apply only to the breadcrumb,
79
+ // not the hierarchical menu
80
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
81
+ const { transformItems, ...hierarchicalWidgetParams } = widgetParams;
82
+
83
+ mountApp(
84
+ {
85
+ render: renderCompat((h) =>
86
+ h(AisInstantSearch, { props: instantSearchOptions }, [
87
+ h(AisBreadcrumb, { props: widgetParams }),
88
+ h(AisHierarchicalMenu, { props: hierarchicalWidgetParams }),
89
+ h(GlobalErrorSwallower),
90
+ ])
91
+ ),
92
+ },
93
+ document.body.appendChild(document.createElement('div'))
94
+ );
95
+
96
+ await nextTick();
97
+ },
98
+ async createMenuWidgetTests({ instantSearchOptions, widgetParams }) {
99
+ mountApp(
100
+ {
101
+ render: renderCompat((h) =>
102
+ h(AisInstantSearch, { props: instantSearchOptions }, [
103
+ h(AisMenu, { props: widgetParams }),
104
+ h(GlobalErrorSwallower),
105
+ ])
106
+ ),
107
+ },
108
+ document.body.appendChild(document.createElement('div'))
109
+ );
110
+
111
+ await nextTick();
112
+ },
113
+ async createPaginationWidgetTests({ instantSearchOptions, widgetParams }) {
114
+ mountApp(
115
+ {
116
+ render: renderCompat((h) =>
117
+ h(AisInstantSearch, { props: instantSearchOptions }, [
118
+ h(AisPagination, { props: widgetParams }),
119
+ h(GlobalErrorSwallower),
120
+ ])
121
+ ),
122
+ },
123
+ document.body.appendChild(document.createElement('div'))
124
+ );
125
+
126
+ await nextTick();
127
+ },
128
+ async createInfiniteHitsWidgetTests({ instantSearchOptions, widgetParams }) {
129
+ mountApp(
130
+ {
131
+ render: renderCompat((h) =>
132
+ h(AisInstantSearch, { props: instantSearchOptions }, [
133
+ h(AisSearchBox),
134
+ h(AisInfiniteHits, {
135
+ attrs: { id: 'main-hits' },
136
+ props: widgetParams,
137
+ scopedSlots: {
138
+ item: ({ item: hit, sendEvent }) =>
139
+ h(
140
+ 'div',
141
+ {
142
+ attrs: {
143
+ 'data-testid': `main-hits-top-level-${hit.__position}`,
144
+ },
145
+ },
146
+ [
147
+ hit.objectID,
148
+ h('button', {
149
+ attrs: {
150
+ 'data-testid': `main-hits-convert-${hit.__position}`,
151
+ },
152
+ on: {
153
+ click: () =>
154
+ sendEvent('conversion', hit, 'Converted'),
155
+ },
156
+ }),
157
+ h('button', {
158
+ attrs: {
159
+ 'data-testid': `main-hits-click-${hit.__position}`,
160
+ },
161
+ on: {
162
+ click: () => sendEvent('click', hit, 'Clicked'),
163
+ },
164
+ }),
165
+ ]
166
+ ),
167
+ },
168
+ }),
169
+ h(AisIndex, { props: { indexName: 'nested' } }, [
170
+ h(AisInfiniteHits, {
171
+ attrs: { id: 'nested-hits' },
172
+ scopedSlots: {
173
+ item: ({ item: hit, sendEvent }) =>
174
+ h(
175
+ 'div',
176
+ {
177
+ attrs: {
178
+ 'data-testid': `nested-hits-top-level-${hit.__position}`,
179
+ },
180
+ },
181
+ [
182
+ hit.objectID,
183
+ h('button', {
184
+ attrs: {
185
+ 'data-testid': `nested-hits-click-${hit.__position}`,
186
+ },
187
+ on: {
188
+ click: () =>
189
+ sendEvent('click', hit, 'Clicked nested'),
190
+ },
191
+ }),
192
+ ]
193
+ ),
194
+ },
195
+ }),
196
+ ]),
197
+ h(GlobalErrorSwallower),
198
+ ])
199
+ ),
200
+ },
201
+ document.body.appendChild(document.createElement('div'))
202
+ );
203
+
204
+ await nextTick();
205
+ },
206
+ async createHitsWidgetTests({ instantSearchOptions, widgetParams }) {
207
+ mountApp(
208
+ {
209
+ render: renderCompat((h) =>
210
+ h(AisInstantSearch, { props: instantSearchOptions }, [
211
+ h(AisSearchBox),
212
+ h(AisHits, {
213
+ attrs: { id: 'main-hits' },
214
+ props: widgetParams,
215
+ scopedSlots: {
216
+ item: ({ item: hit, sendEvent }) =>
217
+ h(
218
+ 'div',
219
+ {
220
+ attrs: {
221
+ 'data-testid': `main-hits-top-level-${hit.__position}`,
222
+ },
223
+ },
224
+ [
225
+ hit.objectID,
226
+ h('button', {
227
+ attrs: {
228
+ 'data-testid': `main-hits-convert-${hit.__position}`,
229
+ },
230
+ on: {
231
+ click: () =>
232
+ sendEvent('conversion', hit, 'Converted'),
233
+ },
234
+ }),
235
+ h('button', {
236
+ attrs: {
237
+ 'data-testid': `main-hits-click-${hit.__position}`,
238
+ },
239
+ on: {
240
+ click: () => sendEvent('click', hit, 'Clicked'),
241
+ },
242
+ }),
243
+ ]
244
+ ),
245
+ },
246
+ }),
247
+ h(AisIndex, { props: { indexName: 'nested' } }, [
248
+ h(AisHits, {
249
+ attrs: { id: 'nested-hits' },
250
+ scopedSlots: {
251
+ item: ({ item: hit, sendEvent }) =>
252
+ h(
253
+ 'div',
254
+ {
255
+ attrs: {
256
+ 'data-testid': `nested-hits-top-level-${hit.__position}`,
257
+ },
258
+ },
259
+ [
260
+ hit.objectID,
261
+ h('button', {
262
+ attrs: {
263
+ 'data-testid': `nested-hits-click-${hit.__position}`,
264
+ },
265
+ on: {
266
+ click: () =>
267
+ sendEvent('click', hit, 'Clicked nested'),
268
+ },
269
+ }),
270
+ ]
271
+ ),
272
+ },
273
+ }),
274
+ ]),
275
+ h(GlobalErrorSwallower),
276
+ ])
277
+ ),
278
+ },
279
+ document.body.appendChild(document.createElement('div'))
280
+ );
281
+
282
+ await nextTick();
283
+ },
284
+ async createRangeInputWidgetTests({ instantSearchOptions, widgetParams }) {
285
+ mountApp(
286
+ {
287
+ render: renderCompat((h) =>
288
+ h(AisInstantSearch, { props: instantSearchOptions }, [
289
+ h(AisRangeInput, { props: widgetParams }),
290
+ h(GlobalErrorSwallower),
291
+ ])
292
+ ),
293
+ },
294
+ document.body.appendChild(document.createElement('div'))
295
+ );
296
+
297
+ await nextTick();
298
+ },
299
+ createInstantSearchWidgetTests({ instantSearchOptions }) {
300
+ mountApp(
301
+ {
302
+ render: renderCompat((h) =>
303
+ h(AisInstantSearch, { props: instantSearchOptions }, [
304
+ h(GlobalErrorSwallower),
305
+ ])
306
+ ),
307
+ },
308
+ document.body.appendChild(document.createElement('div'))
309
+ );
310
+
311
+ return {
312
+ algoliaAgents: [
313
+ `instantsearch.js (${
314
+ require('../../../instantsearch.js/package.json').version
315
+ })`,
316
+ `Vue InstantSearch (${
317
+ require('../../../vue-instantsearch/package.json').version
318
+ })`,
319
+ `Vue (${require('../util/vue-compat').version})`,
320
+ ],
321
+ };
322
+ },
323
+ };
324
+
325
+ const testOptions = {
326
+ createRefinementListWidgetTests: undefined,
327
+ createHierarchicalMenuWidgetTests: undefined,
328
+ createBreadcrumbWidgetTests: undefined,
329
+ createMenuWidgetTests: undefined,
330
+ createPaginationWidgetTests: undefined,
331
+ createInfiniteHitsWidgetTests: undefined,
332
+ createHitsWidgetTests: undefined,
333
+ createRangeInputWidgetTests: undefined,
334
+ createInstantSearchWidgetTests: undefined,
335
+ };
336
+
337
+ describe('Common widget tests (Vue InstantSearch)', () => {
338
+ runTestSuites({
339
+ testSuites,
340
+ testSetups,
341
+ testOptions,
342
+ });
343
+ });