@@ -30,7 +30,7 @@ describe('Snippet Browser test', () => {
3030 } ,
3131 ] )
3232 const snippeted = response . results [ 0 ] ?. hits [ 0 ] ?. _snippetResult
33- expect ( snippeted ?. overview ?. value ) . toEqual ( ' Princess' )
33+ expect ( snippeted ) . toHaveProperty ( 'overview' , { value : ' Princess...' } )
3434 } )
3535
3636 test ( 'Test one attributesToSnippet on specific query' , async ( ) => {
@@ -44,10 +44,15 @@ describe('Snippet Browser test', () => {
4444 } ,
4545 } ,
4646 ] )
47- const highlighted = response . results [ 0 ] ?. hits [ 0 ] ?. _snippetResult
47+ const highlighted = response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult
4848 const snippeted = response . results [ 0 ] . hits [ 0 ] . _snippetResult
49- expect ( highlighted ?. overview ?. value ) . toEqual ( 'While' )
50- expect ( snippeted ?. overview ?. value ) . toEqual ( 'While...' )
49+
50+ expect ( highlighted ) . toHaveProperty ( 'overview' , {
51+ value : 'While' ,
52+ } )
53+ expect ( snippeted ) . toHaveProperty ( 'overview' , {
54+ value : 'While...' ,
55+ } )
5156 } )
5257
5358 test ( 'Test * attributesToSnippet on specific query' , async ( ) => {
@@ -61,35 +66,50 @@ describe('Snippet Browser test', () => {
6166 } ,
6267 } ,
6368 ] )
64- const highlighted = response . results [ 0 ] ?. hits [ 0 ] ?. _snippetResult
69+ const highlighted = response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult
6570 const snippeted = response . results [ 0 ] . hits [ 0 ] . _snippetResult
66- expect ( highlighted ?. id ?. value ) . toEqual ( '6' )
67- expect ( highlighted ?. title ?. value ) . toEqual (
68- '__ais-highlight__Judg__/ais-highlight__ment Night'
69- )
70- expect ( highlighted ?. overview ?. value ) . toEqual ( 'While' )
71+
72+ expect ( highlighted ) . toHaveProperty ( 'id' , {
73+ value : '6' ,
74+ } )
75+ expect ( snippeted ) . toHaveProperty ( 'id' , {
76+ value : '6' ,
77+ } )
78+ expect ( highlighted ) . toHaveProperty ( 'title' , {
79+ value : '__ais-highlight__Judg__/ais-highlight__ment Night' ,
80+ } )
81+ expect ( snippeted ) . toHaveProperty ( 'title' , {
82+ value : '__ais-highlight__Judg__/ais-highlight__ment Night' ,
83+ } )
84+ expect ( highlighted ) . toHaveProperty ( 'overview' , {
85+ value : 'While' ,
86+ } )
87+ expect ( snippeted ) . toHaveProperty ( 'overview' , {
88+ value : 'While...' ,
89+ } )
90+ expect ( highlighted ) . toHaveProperty ( 'release_date' , {
91+ value : '750643200' ,
92+ } )
93+ expect ( snippeted ) . toHaveProperty ( 'release_date' , {
94+ value : '750643200' ,
95+ } )
96+
7197 expect ( highlighted ?. genres ) . toBeTruthy ( )
7298 if ( highlighted ?. genres ) {
7399 expect ( highlighted ?. genres [ 0 ] . value ) . toEqual ( 'Action' )
74100 expect ( highlighted ?. genres [ 1 ] . value ) . toEqual ( 'Thriller' )
75101 expect ( highlighted ?. genres [ 2 ] . value ) . toEqual ( 'Crime' )
76102 }
77- expect ( highlighted ?. release_date ?. value ) . toEqual ( '750643200' )
78- expect ( snippeted ?. id ?. value ) . toEqual ( '6' )
79- expect ( snippeted ?. title ?. value ) . toEqual (
80- '__ais-highlight__Judg__/ais-highlight__ment Night'
81- )
82- expect ( snippeted ?. overview ?. value ) . toEqual ( 'While...' )
103+
83104 expect ( snippeted ?. genres ) . toBeTruthy ( )
84105 if ( snippeted ?. genres ) {
85106 expect ( snippeted ?. genres [ 0 ] . value ) . toEqual ( 'Action' )
86107 expect ( snippeted ?. genres [ 1 ] . value ) . toEqual ( 'Thriller' )
87108 expect ( snippeted ?. genres [ 2 ] . value ) . toEqual ( 'Crime' )
88109 }
89- expect ( snippeted ?. release_date ?. value ) . toEqual ( '750643200' )
90110 } )
91111
92- test . only ( 'Test two snippets on specific query and compare snippet with highlight results' , async ( ) => {
112+ test ( 'Test two snippets on specific query and compare snippet with highlight results' , async ( ) => {
93113 const response = await searchClient . search < Movies > ( [
94114 {
95115 indexName : 'movies' ,
@@ -106,25 +126,31 @@ describe('Snippet Browser test', () => {
106126 const firstHitHighlight = response . results [ 0 ] ?. hits [ 0 ] ?. _highlightResult
107127 const firstHitSnippet = response . results [ 0 ] . hits [ 0 ] . _snippetResult
108128
109- expect ( firstHitHighlight ?. title ?. value ) . toEqual ( '<p>S</p>tar Wars' )
110- expect ( firstHitHighlight ?. overview ?. value ) . toEqual (
111- 'Luke <p>S</p>kywalker and'
112- )
113- expect ( firstHitSnippet ?. title ?. value ) . toEqual ( '<p>S</p>tar Wars' )
114- expect ( firstHitSnippet ?. overview ?. value ) . toEqual (
115- 'Luke <p>S</p>kywalker and...'
116- )
129+ expect ( firstHitHighlight ) . toHaveProperty ( 'title' , {
130+ value : '<p>S</p>tar Wars' ,
131+ } )
132+ expect ( firstHitHighlight ) . toHaveProperty ( 'overview' , {
133+ value : 'Luke <p>S</p>kywalker and' ,
134+ } )
135+
136+ expect ( firstHitSnippet ) . toHaveProperty ( 'title' , {
137+ value : '<p>S</p>tar Wars' ,
138+ } )
139+ expect ( firstHitSnippet ) . toHaveProperty ( 'overview' , {
140+ value : 'Luke <p>S</p>kywalker and...' ,
141+ } )
117142
118143 const secondHitHighlight = response . results [ 0 ] ?. hits [ 1 ] ?. _highlightResult
119144 const secondHitSnippet = response . results [ 0 ] ?. hits [ 1 ] ?. _snippetResult
120145 expect ( secondHitHighlight ) . toHaveProperty ( 'title' , { value : 'Four' } )
121146 expect ( secondHitHighlight ?. overview ?. value ) . toEqual ( "It'<p>s</p> Ted" )
122147
123- expect ( secondHitSnippet ) . toHaveProperty ( 'title' , { value : 'Four...' } )
148+ expect ( secondHitSnippet ) . toHaveProperty ( 'title' , {
149+ value : 'Four...' ,
150+ } )
124151 expect ( secondHitSnippet ) . toHaveProperty ( 'overview' , {
125152 value : "It'<p>s</p> Ted..." ,
126153 } )
127- // expect(secondHitSnippet?.overview?.value).toEqual("It'<p>s</p> Ted...")
128154 } )
129155
130156 test ( 'Test attributesToSnippet on a null attribute' , async ( ) => {
@@ -143,7 +169,7 @@ describe('Snippet Browser test', () => {
143169 expect ( firstHit ) . toHaveProperty ( 'overview' , { value : 'null' } )
144170 } )
145171
146- test . only ( 'Test one attributesToSnippet on placeholder w/ snippetEllipsisText' , async ( ) => {
172+ test ( 'Test one attributesToSnippet on placeholder w/ snippetEllipsisText' , async ( ) => {
147173 const response = await searchClient . search < Movies > ( [
148174 {
149175 indexName : 'movies' ,
0 commit comments