@@ -16,6 +16,27 @@ function DocSearch(props: Partial<DocSearchProps>) {
1616 return < DocSearchComponent apiKey = "foo" indexName = "bar" { ...props } /> ;
1717}
1818
19+ // mock empty response
20+ function noResultSearch ( _queries : any , _requestOptions ?: any ) : Promise < any > {
21+ return new Promise ( ( resolve ) => {
22+ resolve ( {
23+ results : [
24+ {
25+ hits : [ ] ,
26+ hitsPerPage : 0 ,
27+ nbHits : 0 ,
28+ nbPages : 0 ,
29+ page : 0 ,
30+ processingTimeMS : 0 ,
31+ exhaustiveNbHits : true ,
32+ params : '' ,
33+ query : '' ,
34+ } ,
35+ ] ,
36+ } ) ;
37+ } ) ;
38+ }
39+
1940describe ( 'api' , ( ) => {
2041 beforeEach ( ( ) => {
2142 document . body . innerHTML = '' ;
@@ -71,40 +92,23 @@ describe('api', () => {
7192 it ( 'overrides the default DocSearchModal noResultsScreen text' , async ( ) => {
7293 render (
7394 < DocSearch
74- // mock empty response
7595 transformSearchClient = { ( searchClient ) => {
7696 return {
7797 ...searchClient ,
78- search : ( ) => {
79- return new Promise ( ( resolve ) => {
80- resolve ( {
81- results : [
82- {
83- hits : [ ] ,
84- hitsPerPage : 0 ,
85- nbHits : 0 ,
86- nbPages : 0 ,
87- page : 0 ,
88- processingTimeMS : 0 ,
89- exhaustiveNbHits : true ,
90- params : '' ,
91- query : '' ,
92- } ,
93- ] ,
94- } ) ;
95- } ) ;
96- } ,
98+ search : noResultSearch ,
9799 } ;
98100 } }
99101 translations = { {
100102 modal : {
101103 noResultsScreen : {
102104 noResultsText : 'Pas de résultats pour' ,
103- openIssueText : 'Ouvrez une issue sur docsearch-configs' ,
104- openIssueLinkText : 'Lien du repo' ,
105+ reportMissingResultsText :
106+ 'Ouvrez une issue sur docsearch-configs' ,
107+ reportMissingResultsLinkText : 'Lien du repo' ,
105108 } ,
106109 } ,
107110 } }
111+ reportMissingResultsUrl = { ( ) => 'algolia.com' }
108112 />
109113 ) ;
110114
@@ -190,4 +194,68 @@ describe('api', () => {
190194 expect ( screen . getByText ( 'Selectionner' ) ) . toBeInTheDocument ( ) ;
191195 } ) ;
192196 } ) ;
197+
198+ describe ( 'reportMissingResultsUrl' , ( ) => {
199+ it ( 'does not render the link to the repository by default' , async ( ) => {
200+ render (
201+ < DocSearch
202+ transformSearchClient = { ( searchClient ) => {
203+ return {
204+ ...searchClient ,
205+ search : noResultSearch ,
206+ } ;
207+ } }
208+ />
209+ ) ;
210+
211+ await act ( async ( ) => {
212+ await waitFor ( ( ) => {
213+ fireEvent . click ( document . querySelector ( '.DocSearch-Button' ) ) ;
214+ } ) ;
215+
216+ fireEvent . input ( document . querySelector ( '.DocSearch-Input' ) , {
217+ target : { value : 'q' } ,
218+ } ) ;
219+ } ) ;
220+
221+ expect ( screen . getByText ( / N o r e s u l t s f o r / ) ) . toBeInTheDocument ( ) ;
222+ expect (
223+ document . querySelector ( '.DocSearch-Help a' )
224+ ) . not . toBeInTheDocument ( ) ;
225+ } ) ;
226+
227+ it ( 'render the link to the repository' , async ( ) => {
228+ render (
229+ < DocSearch
230+ transformSearchClient = { ( searchClient ) => {
231+ return {
232+ ...searchClient ,
233+ search : noResultSearch ,
234+ } ;
235+ } }
236+ reportMissingResultsUrl = { ( { query } ) =>
237+ `https://github.com/algolia/docsearch/issues/new?title=${ query } `
238+ }
239+ />
240+ ) ;
241+
242+ await act ( async ( ) => {
243+ await waitFor ( ( ) => {
244+ fireEvent . click ( document . querySelector ( '.DocSearch-Button' ) ) ;
245+ } ) ;
246+
247+ fireEvent . input ( document . querySelector ( '.DocSearch-Input' ) , {
248+ target : { value : 'q' } ,
249+ } ) ;
250+ } ) ;
251+
252+ expect ( screen . getByText ( / N o r e s u l t s f o r / ) ) . toBeInTheDocument ( ) ;
253+
254+ const link = document . querySelector ( '.DocSearch-Help a' ) ;
255+ expect ( link ) . toBeInTheDocument ( ) ;
256+ expect ( link . getAttribute ( 'href' ) ) . toBe (
257+ 'https://github.com/algolia/docsearch/issues/new?title=q'
258+ ) ;
259+ } ) ;
260+ } ) ;
193261} ) ;
0 commit comments