@@ -6,10 +6,13 @@ jest.mock('../../mixins/widget');
66it ( 'renders explanation if no slot is used' , ( ) => {
77 __setState ( {
88 results : {
9- query : 'q ' ,
9+ query : 'this is the quer ' ,
1010 hits : [ { objectID : '1' , name : 'one' } , { objectID : '2' , name : 'two' } ] ,
1111 page : 1 ,
1212 } ,
13+ state : {
14+ query : 'this is the query' ,
15+ } ,
1316 } ) ;
1417 const wrapper = mount ( StateResults ) ;
1518 expect ( wrapper . html ( ) ) . toMatchSnapshot ( ) ;
@@ -21,37 +24,91 @@ it("doesn't render if no results", () => {
2124 expect ( wrapper . html ( ) ) . toBeUndefined ( ) ;
2225} ) ;
2326
24- it ( 'gives results to default slot' , ( ) => {
27+ it ( 'gives state & results to default slot' , ( ) => {
2528 const results = {
2629 query : 'q' ,
2730 hits : [ { objectID : '1' , name : 'one' } , { objectID : '2' , name : 'two' } ] ,
2831 page : 1 ,
2932 } ;
33+ const state = {
34+ query : 'something' ,
35+ disjunctiveFacetsRefinements : { } ,
36+ page : 1 ,
37+ } ;
3038
3139 __setState ( {
40+ state,
3241 results,
3342 } ) ;
3443
3544 mount ( StateResults , {
3645 scopedSlots : {
37- default : props => expect ( props ) . toEqual ( results ) ,
46+ default : props => {
47+ expect ( props ) . toEqual ( expect . objectContaining ( results ) ) ;
48+ expect ( props . results ) . toEqual ( results ) ;
49+ expect ( props . state ) . toEqual ( state ) ;
50+ } ,
3851 } ,
3952 } ) ;
4053} ) ;
4154
42- it ( 'allows default slot to render whatever they want (truthy query)' , ( ) => {
55+ it ( 'allows default slot to render whatever they want' , ( ) => {
56+ const results = {
57+ query : 'hi' ,
58+ hits : [ { objectID : '1' , name : 'one' } , { objectID : '2' , name : 'two' } ] ,
59+ page : 1 ,
60+ } ;
61+ const state = {
62+ query : 'hi!' ,
63+ } ;
4364 __setState ( {
44- results : {
45- query : 'q' ,
46- hits : [ { objectID : '1' , name : 'one' } , { objectID : '2' , name : 'two' } ] ,
47- page : 1 ,
65+ state,
66+ results,
67+ } ) ;
68+
69+ const wrapper = mount ( StateResults , {
70+ scopedSlots : {
71+ default : `
72+ <template slot-scope="{ state: { query }, results: { page } }">
73+ <p v-if="query">
74+ Query is here, page is {{ page }}
75+ </p>
76+ <p v-else>
77+ There's no query
78+ </p>
79+ </template>` ,
4880 } ,
4981 } ) ;
5082
83+ expect ( wrapper . html ( ) ) . toMatchInlineSnapshot ( `
84+
85+ <div class="ais-StateResults">
86+ <p>
87+ Query is here, page is 1
88+ </p>
89+ </div>
90+
91+ ` ) ;
92+ } ) ;
93+
94+ it ( 'allows default slot to render whatever they want (truthy query)' , ( ) => {
95+ const results = {
96+ query : 'hi' ,
97+ hits : [ { objectID : '1' , name : 'one' } , { objectID : '2' , name : 'two' } ] ,
98+ page : 1 ,
99+ } ;
100+ const state = {
101+ query : 'hi!' ,
102+ } ;
103+ __setState ( {
104+ state,
105+ results,
106+ } ) ;
107+
51108 const wrapper = mount ( StateResults , {
52109 scopedSlots : {
53110 default : `
54- <template slot-scope="{ query }">
111+ <template slot-scope="{ results: { query } }">
55112 <p v-if="query">
56113 Query is here
57114 </p>
@@ -62,22 +119,35 @@ it('allows default slot to render whatever they want (truthy query)', () => {
62119 } ,
63120 } ) ;
64121
65- expect ( wrapper . html ( ) ) . toMatchSnapshot ( ) ;
122+ expect ( wrapper . html ( ) ) . toMatchInlineSnapshot ( `
123+
124+ <div class="ais-StateResults">
125+ <p>
126+ Query is here
127+ </p>
128+ </div>
129+
130+ ` ) ;
66131} ) ;
67132
68133it ( 'allows default slot to render whatever they want (falsy query)' , ( ) => {
134+ const results = {
135+ query : '' ,
136+ hits : [ { objectID : '1' , name : 'one' } , { objectID : '2' , name : 'two' } ] ,
137+ page : 1 ,
138+ } ;
139+ const state = {
140+ query : 'hi!' ,
141+ } ;
69142 __setState ( {
70- results : {
71- query : '' ,
72- hits : [ { objectID : '1' , name : 'one' } , { objectID : '2' , name : 'two' } ] ,
73- page : 1 ,
74- } ,
143+ state,
144+ results,
75145 } ) ;
76146
77147 const wrapper = mount ( StateResults , {
78148 scopedSlots : {
79149 default : `
80- <template slot-scope="{ query }">
150+ <template slot-scope="{ results: { query } }">
81151 <p v-if="query">
82152 Query is here
83153 </p>
@@ -88,5 +158,85 @@ it('allows default slot to render whatever they want (falsy query)', () => {
88158 } ,
89159 } ) ;
90160
91- expect ( wrapper . html ( ) ) . toMatchSnapshot ( ) ;
161+ expect ( wrapper . html ( ) ) . toMatchInlineSnapshot ( `
162+
163+ <div class="ais-StateResults">
164+ <p>
165+ There's no query
166+ </p>
167+ </div>
168+
169+ ` ) ;
170+ } ) ;
171+
172+ describe ( 'legacy spread props' , ( ) => {
173+ it ( 'allows default slot to render whatever they want (truthy query)' , ( ) => {
174+ __setState ( {
175+ results : {
176+ query : 'q' ,
177+ hits : [ { objectID : '1' , name : 'one' } , { objectID : '2' , name : 'two' } ] ,
178+ page : 1 ,
179+ } ,
180+ state : { } ,
181+ } ) ;
182+
183+ const wrapper = mount ( StateResults , {
184+ scopedSlots : {
185+ default : `
186+ <template slot-scope="{ query }">
187+ <p v-if="query">
188+ Query is here
189+ </p>
190+ <p v-else>
191+ There's no query
192+ </p>
193+ </template>` ,
194+ } ,
195+ } ) ;
196+
197+ expect ( wrapper . html ( ) ) . toMatchInlineSnapshot ( `
198+
199+ <div class="ais-StateResults">
200+ <p>
201+ Query is here
202+ </p>
203+ </div>
204+
205+ ` ) ;
206+ } ) ;
207+
208+ it ( 'allows default slot to render whatever they want (falsy query)' , ( ) => {
209+ __setState ( {
210+ results : {
211+ query : '' ,
212+ hits : [ { objectID : '1' , name : 'one' } , { objectID : '2' , name : 'two' } ] ,
213+ page : 1 ,
214+ } ,
215+ state : { } ,
216+ } ) ;
217+
218+ const wrapper = mount ( StateResults , {
219+ scopedSlots : {
220+ default : `
221+ <template slot-scope="{ query }">
222+ <p v-if="query">
223+ Query is here
224+ </p>
225+ <p v-else>
226+ There's no query
227+ </p>
228+ </template>` ,
229+ } ,
230+ } ) ;
231+
232+ expect ( wrapper . html ( ) ) . toMatchInlineSnapshot ( `
233+
234+ <div class="ais-StateResults">
235+ <p>
236+ There's no query
237+ </p>
238+ </div>
239+
240+ ` ) ;
241+ } ) ;
92242} ) ;
0 commit comments