|
1 | 1 | import { |
| 2 | +getHighlightQuery, |
2 | 3 | getQueryStringQuery, |
3 | 4 | getSearchSortByQuery, |
4 | 5 | } from '../../src/targets/search'; |
@@ -181,3 +182,149 @@ test('getQueryStringQuery when datafield is an object array and queryString is t |
181 | 182 | // Snapshot demo |
182 | 183 | expect(result).toStrictEqual(expected); |
183 | 184 | }); |
| 185 | + |
| 186 | +test('getHighlightQuery when highlight is missing', () => { |
| 187 | +const result = getHighlightQuery({ |
| 188 | +dataField: [ |
| 189 | +{ field: 'data1', weight: 1 }, |
| 190 | +{ field: 'data2', weight: 1 }, |
| 191 | +{ field: 'data3', weight: 1 }, |
| 192 | +], |
| 193 | +sortBy: `desc`, |
| 194 | +}); |
| 195 | +const expected = {}; |
| 196 | +// Snapshot demo |
| 197 | +expect(result).toStrictEqual(expected); |
| 198 | +}); |
| 199 | + |
| 200 | +test('getHighlightQuery when highlight is false', () => { |
| 201 | +const result = getHighlightQuery({ |
| 202 | +dataField: [ |
| 203 | +{ field: 'data1', weight: 1 }, |
| 204 | +{ field: 'data2', weight: 1 }, |
| 205 | +{ field: 'data3', weight: 1 }, |
| 206 | +], |
| 207 | +sortBy: `desc`, |
| 208 | +highlight: false, |
| 209 | +}); |
| 210 | +const expected = {}; |
| 211 | +// Snapshot demo |
| 212 | +expect(result).toStrictEqual(expected); |
| 213 | +}); |
| 214 | + |
| 215 | +test('getHighlightQuery when highlight is true and datafield is an array of DataField', () => { |
| 216 | +const result = getHighlightQuery({ |
| 217 | +dataField: [ |
| 218 | +{ field: 'data1', weight: 1 }, |
| 219 | +{ field: 'data2', weight: 1 }, |
| 220 | +{ field: 'data3', weight: 1 }, |
| 221 | +], |
| 222 | +sortBy: `desc`, |
| 223 | +highlight: true, |
| 224 | +}); |
| 225 | +const expected = { |
| 226 | +highlight: { |
| 227 | +path: ['data1', 'data2', 'data3'], |
| 228 | +maxCharsToExamine: 500000, |
| 229 | +maxNumPassages: 5, |
| 230 | +}, |
| 231 | +}; |
| 232 | +// Snapshot demo |
| 233 | +expect(result).toStrictEqual(expected); |
| 234 | +}); |
| 235 | + |
| 236 | +test('getHighlightQuery when highlight is true and datafield is an array of DataField', () => { |
| 237 | +const result = getHighlightQuery({ |
| 238 | +dataField: [ |
| 239 | +{ field: 'data1', weight: 1 }, |
| 240 | +{ field: 'data2', weight: 1 }, |
| 241 | +{ field: 'data3', weight: 1 }, |
| 242 | +], |
| 243 | +sortBy: `desc`, |
| 244 | +highlight: true, |
| 245 | +}); |
| 246 | +const expected = { |
| 247 | +highlight: { |
| 248 | +path: ['data1', 'data2', 'data3'], |
| 249 | +maxCharsToExamine: 500000, |
| 250 | +maxNumPassages: 5, |
| 251 | +}, |
| 252 | +}; |
| 253 | +// Snapshot demo |
| 254 | +expect(result).toStrictEqual(expected); |
| 255 | +}); |
| 256 | + |
| 257 | +test('getHighlightQuery when highlight is true and datafield is an array of string', () => { |
| 258 | +const result = getHighlightQuery({ |
| 259 | +dataField: ['data1', 'data2', 'data3'], |
| 260 | +sortBy: `desc`, |
| 261 | +highlight: true, |
| 262 | +}); |
| 263 | +const expected = { |
| 264 | +highlight: { |
| 265 | +path: ['data1', 'data2', 'data3'], |
| 266 | +maxCharsToExamine: 500000, |
| 267 | +maxNumPassages: 5, |
| 268 | +}, |
| 269 | +}; |
| 270 | +// Snapshot demo |
| 271 | +expect(result).toStrictEqual(expected); |
| 272 | +}); |
| 273 | + |
| 274 | +test('getHighlightQuery when highlight is true and highlightField is a string', () => { |
| 275 | +const result = getHighlightQuery({ |
| 276 | +dataField: 'data', |
| 277 | +sortBy: `desc`, |
| 278 | +highlight: true, |
| 279 | +highlightField: 'field1', |
| 280 | +}); |
| 281 | +const expected = { |
| 282 | +highlight: { |
| 283 | +path: ['field1'], |
| 284 | +maxCharsToExamine: 500000, |
| 285 | +maxNumPassages: 5, |
| 286 | +}, |
| 287 | +}; |
| 288 | +// Snapshot demo |
| 289 | +expect(result).toStrictEqual(expected); |
| 290 | +}); |
| 291 | + |
| 292 | +test('getHighlightQuery when highlight is true and highlightField is an array', () => { |
| 293 | +const result = getHighlightQuery({ |
| 294 | +dataField: 'data', |
| 295 | +sortBy: `desc`, |
| 296 | +highlight: true, |
| 297 | +highlightField: ['field1', 'field2'], |
| 298 | +}); |
| 299 | +const expected = { |
| 300 | +highlight: { |
| 301 | +path: ['field1', 'field2'], |
| 302 | +maxCharsToExamine: 500000, |
| 303 | +maxNumPassages: 5, |
| 304 | +}, |
| 305 | +}; |
| 306 | +// Snapshot demo |
| 307 | +expect(result).toStrictEqual(expected); |
| 308 | +}); |
| 309 | + |
| 310 | +test('getHighlightQuery when highlight is true and customHighlight is passed', () => { |
| 311 | +const result = getHighlightQuery({ |
| 312 | +dataField: 'data', |
| 313 | +sortBy: `desc`, |
| 314 | +highlight: true, |
| 315 | +highlightField: ['field1', 'field2'], |
| 316 | +customHighlight: { |
| 317 | +maxCharsToExamine: 250000, |
| 318 | +maxNumPassages: 10, |
| 319 | +}, |
| 320 | +}); |
| 321 | +const expected = { |
| 322 | +highlight: { |
| 323 | +path: ['field1', 'field2'], |
| 324 | +maxCharsToExamine: 250000, |
| 325 | +maxNumPassages: 10, |
| 326 | +}, |
| 327 | +}; |
| 328 | +// Snapshot demo |
| 329 | +expect(result).toStrictEqual(expected); |
| 330 | +}); |
0 commit comments