-
Notifications
You must be signed in to change notification settings - Fork 552
Expand file tree
/
Copy pathIndex.js
More file actions
117 lines (103 loc) · 2.26 KB
/
Copy pathIndex.js
File metadata and controls
117 lines (103 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* @jest-environment @instantsearch/testutils/jest-environment-jsdom.ts
*/
import { mount } from '../../../test/utils';
import { __setWidget } from '../../mixins/widget';
import { Vue2, isVue3, isVue2 } from '../../util/vue-compat';
import Index from '../Index';
jest.mock('../../mixins/widget');
import '../../../test/utils/sortedHtmlSerializer';
beforeEach(() => {
jest.resetAllMocks();
});
it('passes props to widgetParams', () => {
const wrapper = mount(Index, {
propsData: {
indexName: 'the name',
indexId: 'the id',
},
});
expect(wrapper.vm.widgetParams).toEqual({
indexName: 'the name',
indexId: 'the id',
isolated: false,
});
});
it('passes the `isolated` prop to widgetParams without an `indexName`', () => {
const wrapper = mount(Index, {
propsData: {
isolated: true,
},
});
expect(wrapper.vm.widgetParams).toEqual({
indexName: undefined,
indexId: undefined,
isolated: true,
});
});
it('renders just a div by default', () => {
const wrapper = mount(Index, {
propsData: {
indexName: 'index name',
},
});
expect(wrapper.html()).toMatchInlineSnapshot(`
<div>
</div>
`);
});
it('renders its children', () => {
const wrapper = mount(Index, {
propsData: {
indexName: 'index name',
},
slots: {
default: '<div>hi there!</div>',
},
});
expect(wrapper.html()).toMatchInlineSnapshot(`
<div>
<div>
hi there!
</div>
</div>
`);
});
// eslint-disable-next-line jest/no-done-callback
it('provides the index widget', (done) => {
const indexWidget = { $$type: 'ais.index' };
__setWidget(indexWidget);
const ChildComponent = {
inject: ['$_ais_getParentIndex'],
mounted() {
this.$nextTick(() => {
expect(typeof this.$_ais_getParentIndex).toBe('function');
expect(this.$_ais_getParentIndex()).toEqual(indexWidget);
done();
});
},
render() {
return null;
},
};
if (isVue2) {
Vue2.config.errorHandler = done;
}
mount(
{
components: { Index, ChildComponent },
template: `
<Index index-name="something">
<ChildComponent />
</Index>
`,
},
isVue3 && {
global: {
config: {
errorHandler: done,
},
},
}
);
});