Skip to content

Commit

Permalink
fix: enableQuerySyntax is not passed to recent-query-list controller (
Browse files Browse the repository at this point in the history
#3818)

https://coveord.atlassian.net/browse/KIT-3096

Whenever a submit action (Enter key pressed) is being recorded on a
recent-query suggestion, the `prepareForSearchWithQuery` search action
is triggered with the appropriate `enableQuerySyntax` value.

However, when a mouse click action is recorded on a recent-query
suggestion, the `prepareForSearchWithQuery` search action called by the
headless-recent-queries-list controller does not specify the
`enableQuerySyntax` value.

---------

Co-authored-by: Frederic Beaudoin <fbeaudoin@coveo.com>
  • Loading branch information
y-lakhdar and fbeaudoincoveo committed Apr 19, 2024
1 parent d878ad0 commit e1bb701
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
buildMockSearchEngine,
MockedSearchEngine,
} from '../../test/mock-engine-v2';
import {buildMockQueryState} from '../../test/mock-query-state';
import {createMockState} from '../../test/mock-state';
import {
buildRecentQueriesList,
Expand Down Expand Up @@ -70,11 +71,18 @@ describe('recent queries list', () => {
initialState: testInitialState,
options: testOptions,
};
const mockedPrepareForSearchWithQuery = jest.mocked(
prepareForSearchWithQuery
);

beforeEach(() => {
recentQueriesList = buildRecentQueriesList(engine, testProps);
});

afterEach(() => {
mockedPrepareForSearchWithQuery.mockClear();
});

it('should register with props on init', () => {
expect(registerRecentQueries).toHaveBeenCalledWith({
queries: testProps.initialState.queries,
Expand All @@ -95,18 +103,33 @@ describe('recent queries list', () => {
engine.state.recentQueries = {...testInitialState, ...testOptions};

expect(() => recentQueriesList.executeRecentQuery(100)).toThrow();
expect(validationSpy).toBeCalled();
expect(validationSpy).toHaveBeenCalled();
});

it('#executeRecentQuery should execute #prepareForSearchWithQuery with the proper parameters', () => {
engine.state.query = buildMockQueryState();
engine.state.recentQueries = {...testInitialState, ...testOptions};
recentQueriesList.executeRecentQuery(0);
expect(prepareForSearchWithQuery).toHaveBeenCalledWith({
expect(mockedPrepareForSearchWithQuery).toHaveBeenCalledTimes(1);
expect(mockedPrepareForSearchWithQuery).toHaveBeenCalledWith({
q: testInitialState.queries[0],
clearFilters: testOptions.clearFilters,
enableQuerySyntax: false,
});
});

it('#executeRecentQuery should execute #prepareForSearchWithQuery with the proper enableQuerySyntax parameter', () => {
engine.state.query = buildMockQueryState({enableQuerySyntax: true});
recentQueriesList = buildRecentQueriesList(engine);
recentQueriesList.executeRecentQuery(0);
expect(mockedPrepareForSearchWithQuery).toHaveBeenCalledTimes(1);
expect(mockedPrepareForSearchWithQuery).toHaveBeenCalledWith(
expect.objectContaining({
enableQuerySyntax: true,
})
);
});

it('should not clear filters if the #clearFilters option is false', () => {
recentQueriesList = buildRecentQueriesList(engine, {
options: {clearFilters: false, maxLength: 10},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import {ArrayValue, BooleanValue, NumberValue, Schema} from '@coveo/bueno';
import {
ArrayValue,
BooleanValue,
NumberValue,
Schema,
isBoolean,
} from '@coveo/bueno';
import {SearchEngine} from '../../app/search-engine/search-engine';
import {
clearRecentQueries,
Expand All @@ -11,10 +17,12 @@ import {
} from '../../features/recent-queries/recent-queries-analytics-actions';
import {recentQueriesReducer as recentQueries} from '../../features/recent-queries/recent-queries-slice';
import {
PrepareForSearchWithQueryOptions,
executeSearch,
prepareForSearchWithQuery,
} from '../../features/search/search-actions';
import {searchReducer as search} from '../../features/search/search-slice';
import {UpdateQueryActionCreatorPayload} from '../../ssr.index';
import {RecentQueriesSection} from '../../state/state-sections';
import {loadReducerError} from '../../utils/errors';
import {
Expand Down Expand Up @@ -195,12 +203,18 @@ export function buildRecentQueriesList(
if (errorMessage) {
throw new Error(errorMessage);
}
dispatch(
prepareForSearchWithQuery({
q: this.state.queries[index],
clearFilters: registrationOptions.clearFilters,
})
);

const queryOptions: UpdateQueryActionCreatorPayload &
PrepareForSearchWithQueryOptions = {
q: this.state.queries[index],
clearFilters: registrationOptions.clearFilters,
};

if (isBoolean(engine.state.query?.enableQuerySyntax)) {
queryOptions.enableQuerySyntax = engine.state.query.enableQuerySyntax;
}

dispatch(prepareForSearchWithQuery(queryOptions));
dispatch(
executeSearch({
legacy: logRecentQueryClick(),
Expand Down
2 changes: 1 addition & 1 deletion packages/headless/src/features/search/search-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface ExecuteSearchThunkReturn {
originalQuery: string;
}

interface PrepareForSearchWithQueryOptions {
export interface PrepareForSearchWithQueryOptions {
/**
* Whether to clear all active query filters when the end user submits a new query from the search box.
* Setting this option to "false" is not recommended & can lead to an increasing number of queries returning no results.
Expand Down

0 comments on commit e1bb701

Please sign in to comment.