@@ -5,7 +5,10 @@ import { useAnalytics } from '../../src/hooks/useAnalytics';
5
5
6
6
import { State } from '@yext/search-headless-react' ;
7
7
import { mockAnswersState , ignoreLinkClickErrors } from '../__utils__/mocks' ;
8
- import { verticalResults } from '../__fixtures__/data/universalresults' ;
8
+ import {
9
+ verticalResults ,
10
+ verticalResultsWithDuplicateEntity
11
+ } from '../__fixtures__/data/universalresults' ;
9
12
import { generativeDirectAnswerText , generativeDirectAnswerLink , generativeDirectAnswerResponse } from '../__fixtures__/data/generativeDirectAnswer' ;
10
13
import userEvent from '@testing-library/user-event' ;
11
14
import React from 'react' ;
@@ -27,6 +30,23 @@ const mockedState: Partial<State> = {
27
30
}
28
31
} ;
29
32
33
+ const mockedStateWithDuplicateEntity : Partial < State > = {
34
+ generativeDirectAnswer : {
35
+ isLoading : false ,
36
+ response : generativeDirectAnswerResponse ,
37
+ } ,
38
+ universal : {
39
+ verticals : verticalResultsWithDuplicateEntity
40
+ } ,
41
+ query : {
42
+ queryId : '[queryId]' ,
43
+ mostRecentSearch : 'test'
44
+ } ,
45
+ meta : {
46
+ searchType : 'universal'
47
+ }
48
+ } ;
49
+
30
50
const CustomCitationsComponent = ( props : CitationsProps ) => {
31
51
return (
32
52
< >
@@ -109,6 +129,17 @@ describe('GenerativeDirectAnswer with sufficient citation fields', () => {
109
129
expect ( screen . getByText ( generativeDirectAnswerText ) ) . toBeDefined ( ) ;
110
130
expect ( screen . getByText ( "CustomCitationsComponentTest" ) ) . toBeTruthy ( ) ;
111
131
} ) ;
132
+
133
+ it ( 'citations are deduplicated' , ( ) => {
134
+ mockAnswersState ( mockedStateWithDuplicateEntity ) ;
135
+ render ( < GenerativeDirectAnswer /> ) ;
136
+ expect ( screen . getByText ( generativeDirectAnswerText ) ) . toBeDefined ( ) ;
137
+ expect ( screen . getByText ( 'Sources (2)' ) ) . toBeDefined ( ) ;
138
+
139
+ checkResultData ( verticalResultsWithDuplicateEntity [ 0 ] . results [ 0 ] . rawData , false ) ; //not a citation
140
+ checkResultData ( verticalResultsWithDuplicateEntity [ 0 ] . results [ 1 ] . rawData , true ) ;
141
+ checkResultData ( verticalResultsWithDuplicateEntity [ 1 ] . results [ 0 ] . rawData , true ) ;
142
+ } ) ;
112
143
} ) ;
113
144
114
145
describe ( 'GenerativeDirectAnswer without sufficient citation fields' , ( ) => {
@@ -139,6 +170,14 @@ describe('GenerativeDirectAnswer without sufficient citation fields', () => {
139
170
} ) ;
140
171
} ) ;
141
172
173
+ // describe('GenerativeDirectAnswer with same entity appearing twice in search results', () => {
174
+ // beforeEach(() => {
175
+ // mockAnswersState(mockedStateWithDuplicateEntity);
176
+ // });
177
+ //
178
+ //
179
+ // });
180
+
142
181
function checkResultData ( resultData : Record < string , unknown > , shouldDisplay : boolean ) {
143
182
if ( typeof resultData . name === 'string' ) {
144
183
if ( shouldDisplay ) {
@@ -153,5 +192,5 @@ function checkResultData(resultData: Record<string, unknown>, shouldDisplay: boo
153
192
} else {
154
193
expect ( screen . queryByText ( resultData . description ) ) . toBeNull ( ) ;
155
194
}
156
- }
157
- }
195
+ }
196
+ }
0 commit comments