From b69dd94766690fab7443b6f7af701ddc2f16bf72 Mon Sep 17 00:00:00 2001 From: Andre Wanlin <67169551+awanlin@users.noreply.github.com> Date: Sat, 18 Jun 2022 12:29:54 -0500 Subject: [PATCH] Fixed failing tests Signed-off-by: Andre Wanlin <67169551+awanlin@users.noreply.github.com> --- .../src/PgSearchEngine/PgSearchEngine.test.ts | 48 +++++++++++++++++-- .../src/PgSearchEngine/PgSearchEngine.ts | 2 +- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts index 1d0e31757f..c1ed730053 100644 --- a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts +++ b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.test.ts @@ -26,7 +26,7 @@ import { PgSearchEngineIndexer } from './PgSearchEngineIndexer'; const highlightOptions: PgSearchHighlightConfig = { preTag: '', postTag: '', - useHighlight: false, + useHighlight: true, maxWords: 35, minWords: 15, shortWord: 3, @@ -35,6 +35,8 @@ const highlightOptions: PgSearchHighlightConfig = { fragmentDelimiter: ' ... ', }; +jest.mock('uuid', () => ({ v4: () => 'tag' })); + jest.mock('./PgSearchEngineIndexer', () => ({ PgSearchEngineIndexer: jest .fn() @@ -71,10 +73,13 @@ describe('PgSearchEngine', () => { filters: {}, }); - expect(translatorSpy).toHaveBeenCalledWith({ - term: 'testTerm', - filters: {}, - }); + expect(translatorSpy).toHaveBeenCalledWith( + { + term: 'testTerm', + filters: {}, + }, + highlightOptions, + ); }); it('should pass page cursor', async () => { @@ -205,6 +210,16 @@ describe('PgSearchEngine', () => { }, type: 'my-type', rank: 1, + highlight: { + preTag: '', + postTag: '', + fields: { + title: 'Hello World', + text: 'Lorem Ipsum', + location: 'location-1', + path: '', + }, + }, }, ], nextPageCursor: undefined, @@ -214,6 +229,7 @@ describe('PgSearchEngine', () => { pgTerm: '("Hello" | "Hello":*)&("World" | "World":*)', offset: 0, limit: 26, + options: highlightOptions, }); }); @@ -252,6 +268,16 @@ describe('PgSearchEngine', () => { }, type: 'my-type', rank: i + 1, + highlight: { + preTag: '', + postTag: '', + fields: { + title: 'Hello World', + text: 'Lorem Ipsum', + location: 'location-1', + path: '', + }, + }, })), nextPageCursor: 'MQ==', }); @@ -260,6 +286,7 @@ describe('PgSearchEngine', () => { pgTerm: '("Hello" | "Hello":*)&("World" | "World":*)', offset: 0, limit: 26, + options: highlightOptions, }); }); @@ -300,6 +327,16 @@ describe('PgSearchEngine', () => { }, type: 'my-type', rank: i + 1, + highlight: { + preTag: '', + postTag: '', + fields: { + title: 'Hello World', + text: 'Lorem Ipsum', + location: 'location-1', + path: '', + }, + }, })) .slice(25), previousPageCursor: 'MA==', @@ -309,6 +346,7 @@ describe('PgSearchEngine', () => { pgTerm: '("Hello" | "Hello":*)&("World" | "World":*)', offset: 25, limit: 26, + options: highlightOptions, }); }); }); diff --git a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts index 764e530435..d0c1571991 100644 --- a/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts +++ b/plugins/search-backend-module-pg/src/PgSearchEngine/PgSearchEngine.ts @@ -46,7 +46,7 @@ export class PgSearchEngine implements SearchEngine { this.highlightOptions = { preTag: `<${uuidTag}>`, postTag: ``, - useHighlight: false, + useHighlight: true, maxWords: 35, minWords: 15, shortWord: 3,