@@ -196,6 +196,57 @@ describe('Tracking Beacon 2.0', () => {
196196 } ) ;
197197 } ) ;
198198
199+ it ( 'does not send autocomplete render or impression events for repeated searches' , ( ) => {
200+ let renderCounter = 0 ;
201+ let impressionCounter = 0 ;
202+ let initialResponseId ;
203+ cy . intercept ( 'POST' , / b e a c o n .s e a r c h s p r i n g .i o \/ b e a c o n \/ v 2 \/ .* \/ a u t o c o m p l e t e \/ r e n d e r / , ( req ) => {
204+ renderCounter ++ ;
205+ req . reply ( { success : true } ) ;
206+ } ) . as ( 'beacon2/autocomplete/render-initial' ) ;
207+ cy . intercept ( 'POST' , / b e a c o n .s e a r c h s p r i n g .i o \/ b e a c o n \/ v 2 \/ .* \/ a u t o c o m p l e t e \/ i m p r e s s i o n / , ( req ) => {
208+ impressionCounter ++ ;
209+ req . reply ( { success : true } ) ;
210+ } ) . as ( 'beacon2/autocomplete/impression-initial' ) ;
211+
212+ cy . visit ( 'https://localhost:2222' ) ;
213+ cy . get ( 'input[name="q"]' ) . type ( 'glas' ) ;
214+
215+ cy . wait ( `@beacon2/autocomplete/render-initial` ) . then ( ( { request } ) => {
216+ const { data } = JSON . parse ( request . body ) ;
217+ initialResponseId = data . responseId ;
218+ expect ( initialResponseId ) . to . be . a ( 'string' ) . and . to . not . be . empty ;
219+ expect ( renderCounter ) . to . equal ( 1 ) ;
220+
221+ // re-register intercepts to keep counting
222+ cy . intercept ( 'POST' , / b e a c o n .s e a r c h s p r i n g .i o \/ b e a c o n \/ v 2 \/ .* \/ a u t o c o m p l e t e \/ r e n d e r / , ( req ) => {
223+ renderCounter ++ ;
224+ req . reply ( { success : true } ) ;
225+ } ) ;
226+ } ) ;
227+ cy . wait ( `@beacon2/autocomplete/impression-initial` ) . then ( ( { request } ) => {
228+ const { data } = JSON . parse ( request . body ) ;
229+ expect ( data . responseId ) . to . equal ( initialResponseId ) ;
230+ expect ( impressionCounter ) . to . equal ( 1 ) ;
231+
232+ cy . intercept ( 'POST' , / b e a c o n .s e a r c h s p r i n g .i o \/ b e a c o n \/ v 2 \/ .* \/ a u t o c o m p l e t e \/ i m p r e s s i o n / , ( req ) => {
233+ impressionCounter ++ ;
234+ req . reply ( { success : true } ) ;
235+ } ) ;
236+
237+ // append 's' to make 'glass' - should return cached response (same responseId)
238+ cy . get ( 'input[name="q"]' ) . type ( 's' ) ;
239+ cy . wait ( 2000 ) . then ( ( ) => {
240+ // verify the store still has the same responseId (cached response)
241+ cy . snapController ( 'autocomplete' ) . then ( ( { store } ) => {
242+ expect ( store . results . find ( ( result ) => result . type === 'product' ) . responseId ) . to . equal ( initialResponseId ) ;
243+ } ) ;
244+ expect ( renderCounter ) . to . equal ( 1 ) ;
245+ expect ( impressionCounter ) . to . equal ( 1 ) ;
246+ } ) ;
247+ } ) ;
248+ } ) ;
249+
199250 it ( 'tracked autocomplete impression only once per unique search query' , ( ) => {
200251 let counter = 0 ;
201252 cy . intercept ( 'POST' , / b e a c o n .s e a r c h s p r i n g .i o \/ b e a c o n \/ v 2 \/ .* \/ a u t o c o m p l e t e \/ i m p r e s s i o n / , ( req ) => {
0 commit comments