@@ -22,14 +22,15 @@ function initSearchClient() {
2222}
2323
2424const mockSearchResults = [
25- // 1. The first response is a valid DocumentSearchResult with 1 doc
25+ // 1. The first response is a valid DocumentSearchResult with 2 docs
2626 {
2727 took : 1 ,
2828 hits : {
2929 total : {
30- value : 1 ,
30+ value : 2 ,
3131 } ,
3232 hits : [
33+ // File content matching
3334 {
3435 _source : {
3536 repoUri : 'github.com/Microsoft/TypeScript-Node-Starter' ,
@@ -45,20 +46,34 @@ const mockSearchResults = [
4546 ] ,
4647 } ,
4748 } ,
49+ // File path matching
50+ {
51+ _source : {
52+ repoUri : 'github.com/Microsoft/TypeScript-Node-Starter' ,
53+ path : 'src/types/string.d.ts' ,
54+ content :
55+ 'no query in content;\nno query in content;\nno query in content;\nno query in content;\nno query in content;\n' ,
56+ language : 'typescript' ,
57+ qnames : [ 'express-flash' ] ,
58+ } ,
59+ highlight : {
60+ content : [ ] ,
61+ } ,
62+ } ,
4863 ] ,
4964 } ,
5065 aggregations : {
5166 repoUri : {
5267 buckets : [
5368 {
54- 'github.com/Microsoft/TypeScript-Node-Starter' : 1 ,
69+ 'github.com/Microsoft/TypeScript-Node-Starter' : 2 ,
5570 } ,
5671 ] ,
5772 } ,
5873 language : {
5974 buckets : [
6075 {
61- typescript : 1 ,
76+ typescript : 2 ,
6277 } ,
6378 ] ,
6479 } ,
@@ -105,12 +120,12 @@ beforeEach(() => {
105120 initSearchClient ( ) ;
106121} ) ;
107122
108- test ( 'Repository search' , async ( ) => {
123+ test ( 'Document search' , async ( ) => {
109124 // 1. The first response should have 1 result.
110125 const responseWithResult = await docSearchClient . search ( { query : 'string' , page : 1 } ) ;
111126 expect ( responseWithResult ) . toEqual (
112127 expect . objectContaining ( {
113- total : 1 ,
128+ total : 2 ,
114129 totalPage : 1 ,
115130 page : 1 ,
116131 query : 'string' ,
@@ -136,15 +151,29 @@ test('Repository search', async () => {
136151 language : 'typescript' ,
137152 hits : 1 ,
138153 } ,
154+ {
155+ uri : 'github.com/Microsoft/TypeScript-Node-Starter' ,
156+ filePath : 'src/types/string.d.ts' ,
157+ compositeContent : {
158+ // Content is shorted
159+ content : 'no query in content;\nno query in content;\nno query in content;\n' ,
160+ // Line mapping data is populated
161+ lineMapping : [ '1' , '2' , '3' , '..' ] ,
162+ // Highlight ranges are calculated
163+ ranges : [ ] ,
164+ } ,
165+ language : 'typescript' ,
166+ hits : 0 ,
167+ } ,
139168 ] ,
140169 repoAggregations : [
141170 {
142- 'github.com/Microsoft/TypeScript-Node-Starter' : 1 ,
171+ 'github.com/Microsoft/TypeScript-Node-Starter' : 2 ,
143172 } ,
144173 ] ,
145174 langAggregations : [
146175 {
147- typescript : 1 ,
176+ typescript : 2 ,
148177 } ,
149178 ] ,
150179 } )
@@ -156,12 +185,12 @@ test('Repository search', async () => {
156185 expect ( responseWithEmptyResult . total ) . toEqual ( 0 ) ;
157186} ) ;
158187
159- test ( 'Repository suggest' , async ( ) => {
188+ test ( 'Document suggest' , async ( ) => {
160189 // 1. The first response should have 1 result.
161190 const responseWithResult = await docSearchClient . suggest ( { query : 'string' , page : 1 } ) ;
162191 expect ( responseWithResult ) . toEqual (
163192 expect . objectContaining ( {
164- total : 1 ,
193+ total : 2 ,
165194 totalPage : 1 ,
166195 page : 1 ,
167196 query : 'string' ,
@@ -178,6 +207,18 @@ test('Repository suggest', async () => {
178207 language : 'typescript' ,
179208 hits : 0 ,
180209 } ,
210+ {
211+ uri : 'github.com/Microsoft/TypeScript-Node-Starter' ,
212+ filePath : 'src/types/string.d.ts' ,
213+ // compositeContent field is intended to leave empty.
214+ compositeContent : {
215+ content : '' ,
216+ lineMapping : [ ] ,
217+ ranges : [ ] ,
218+ } ,
219+ language : 'typescript' ,
220+ hits : 0 ,
221+ } ,
181222 ] ,
182223 } )
183224 ) ;
0 commit comments