Skip to content

Commit

Permalink
fix(headless): dispatch action when fetchMoreResults() is called from…
Browse files Browse the repository at this point in the history
… a folded result list controller (#3363)

https://coveord.atlassian.net/browse/KIT-2865
  • Loading branch information
fbeaudoincoveo authored Nov 6, 2023
1 parent 29cd00a commit d33048f
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getFoldingInitialState,
} from '../../../features/folding/folding-state';
import {queryReducer as query} from '../../../features/query/query-slice';
import {fetchMoreResults} from '../../../features/search/search-actions';
import {searchReducer as search} from '../../../features/search/search-slice';
import {
buildMockResult,
Expand Down Expand Up @@ -48,6 +49,7 @@ describe('FoldedResultList', () => {
props = {
options,
loadCollectionActionCreator: loadCollection,
fetchMoreResultsActionCreator: fetchMoreResults,
};

engine = buildMockSearchAppEngine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {CoreEngine, Result} from '../../../recommendation.index';
import {
ConfigurationSection,
FoldingSection,
QuerySection,
SearchSection,
} from '../../../state/state-sections';
import {loadReducerError} from '../../../utils/errors';
Expand Down Expand Up @@ -81,6 +82,11 @@ export interface CoreFoldedResultListProps {
collectionId: CollectionId
// eslint-disable-next-line @typescript-eslint/no-explicit-any
) => AsyncThunkAction<any, CollectionId, any>;
/**
* The action creator to build the `fetchMoreResults` action.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fetchMoreResultsActionCreator: () => AsyncThunkAction<unknown, void, any>;
}

/**
Expand Down Expand Up @@ -249,7 +255,9 @@ export function buildCoreFoldedResultList(

function loadFoldingReducer(
engine: CoreEngine
): engine is CoreEngine<SearchSection & ConfigurationSection & FoldingSection> {
): engine is CoreEngine<
SearchSection & ConfigurationSection & FoldingSection & QuerySection
> {
engine.addReducers({search, configuration, folding, query});
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {SearchAppState} from '../..';
import {loadCollection} from '../../features/folding/folding-actions';
import {fetchMoreResults} from '../../features/search/search-actions';
import {
MockSearchEngine,
buildMockResult,
buildMockSearchAppEngine,
createMockState,
} from '../../test';
import {
FoldedResultList,
buildFoldedResultList,
} from './headless-folded-result-list';

describe('folded result list', () => {
let state: SearchAppState;
let engine: MockSearchEngine;
let foldedResultList: FoldedResultList;

function initFoldedResultList() {
engine = buildMockSearchAppEngine({state});
foldedResultList = buildFoldedResultList(engine);
}

beforeEach(() => {
state = createMockState();
state.search.response.totalCountFiltered = 100;
initFoldedResultList();
});

it('#loadCollection dispatches the folding #loadCollection action', () => {
foldedResultList.loadCollection({
children: [],
isLoadingMoreResults: false,
moreResultsAvailable: false,
result: buildMockResult(),
});

expect(engine.findAsyncAction(loadCollection.pending)).toBeTruthy();
});
it('#fetchMoreResults dispatches the search #fetchMoreResults action', () => {
foldedResultList.fetchMoreResults();

expect(engine.findAsyncAction(fetchMoreResults.pending)).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {SearchEngine} from '../../app/search-engine/search-engine';
import {loadCollection} from '../../features/folding/folding-actions';
import {foldedResultAnalyticsClient} from '../../features/folding/folding-analytics-actions';
import {fetchMoreResults} from '../../features/search/search-actions';
import {
buildCoreFoldedResultList,
FoldingOptions,
Expand Down Expand Up @@ -40,7 +41,11 @@ export function buildFoldedResultList(
): FoldedResultList {
const foldedResultList = buildCoreFoldedResultList(
engine,
{...props, loadCollectionActionCreator: loadCollection},
{
...props,
loadCollectionActionCreator: loadCollection,
fetchMoreResultsActionCreator: fetchMoreResults,
},
foldedResultAnalyticsClient
);
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {loadCollection} from '../../../features/folding/insight-folding-actions';
import {fetchMoreResults} from '../../../features/insight-search/insight-search-actions';
import {InsightAppState} from '../../../state/insight-app-state';
import {buildMockResult} from '../../../test';
import {
MockInsightEngine,
buildMockInsightEngine,
} from '../../../test/mock-engine';
import {buildMockInsightState} from '../../../test/mock-insight-state';
import {
FoldedResultList,
buildFoldedResultList,
} from './headless-insight-folded-result-list';

describe('insight folded result list', () => {
let state: InsightAppState;
let engine: MockInsightEngine;
let foldedResultList: FoldedResultList;

function initFoldedResultList() {
engine = buildMockInsightEngine({state});
foldedResultList = buildFoldedResultList(engine);
}

beforeEach(() => {
state = buildMockInsightState();
state.search.response.totalCountFiltered = 100;
initFoldedResultList();
});

it('#loadCollection dispatches the insight folding #loadCollection action', () => {
foldedResultList.loadCollection({
children: [],
isLoadingMoreResults: false,
moreResultsAvailable: false,
result: buildMockResult(),
});

expect(engine.findAsyncAction(loadCollection.pending)).toBeTruthy();
});

it('#fetchMoreResults dispatches the insight search #fetchMoreResults action', () => {
foldedResultList.fetchMoreResults();

expect(engine.findAsyncAction(fetchMoreResults.pending)).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {insightFoldedResultAnalyticsClient} from '../../../features/folding/folding-insight-analytics-actions';
import {loadCollection} from '../../../features/folding/insight-folding-actions';
import {fetchMoreResults} from '../../../features/insight-search/insight-search-actions';
import {InsightEngine} from '../../../insight.index';
import {
buildCoreFoldedResultList,
Expand Down Expand Up @@ -40,7 +41,11 @@ export function buildFoldedResultList(
): FoldedResultList {
const foldedResultList = buildCoreFoldedResultList(
engine,
{...props, loadCollectionActionCreator: loadCollection},
{
...props,
loadCollectionActionCreator: loadCollection,
fetchMoreResultsActionCreator: fetchMoreResults,
},
insightFoldedResultAnalyticsClient
);
return {
Expand Down

0 comments on commit d33048f

Please sign in to comment.