mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
Merged PR 399: #1203 Refetch Items and Reset Search Results on New Search
#1203 Refetch Items and Reset Search Results on New Search
This commit is contained in:
@@ -81,7 +81,7 @@ export const reloadResults = createAction(
|
||||
|
||||
export const addResult = createAction(
|
||||
`${prefix} Add Result`,
|
||||
props<{ id: number; result: OrderItemListItemDTO[] }>()
|
||||
props<{ id: number; result: OrderItemListItemDTO[]; isNewSearch?: boolean }>()
|
||||
);
|
||||
|
||||
export const clearHits = createAction(
|
||||
|
||||
@@ -234,7 +234,11 @@ fdescribe('#SearchEffects', () => {
|
||||
actions$ = hot('-a', { a: fetchResultsDone });
|
||||
|
||||
const setHitsAction = actions.setHits({ id, hits: 0 });
|
||||
const addResultAction = actions.addResult({ id, result: [] });
|
||||
const addResultAction = actions.addResult({
|
||||
id,
|
||||
result: [],
|
||||
isNewSearch: true,
|
||||
});
|
||||
|
||||
const expected = cold('-(bc)', { b: setHitsAction, c: addResultAction });
|
||||
|
||||
@@ -274,6 +278,7 @@ fdescribe('#SearchEffects', () => {
|
||||
const addResultAction = actions.addResult({
|
||||
id,
|
||||
result: [{ orderId: 345 }],
|
||||
isNewSearch: false,
|
||||
});
|
||||
|
||||
const expected = cold('-(bcd)', {
|
||||
|
||||
@@ -109,7 +109,11 @@ export class SearchEffects implements OnInitEffects {
|
||||
? [actions.setTimestamp({ id: action.id })]
|
||||
: []),
|
||||
actions.setHits({ id: action.id, hits: result.hits || 0 }),
|
||||
actions.addResult({ id: action.id, result: result.result || [] }),
|
||||
actions.addResult({
|
||||
id: action.id,
|
||||
result: result.result || [],
|
||||
isNewSearch: result.skip === 0,
|
||||
}),
|
||||
];
|
||||
}
|
||||
return NEVER;
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
import * as actions from './search.actions';
|
||||
import { searchReducer } from './search.reducer';
|
||||
import { SearchProcessState } from '@shelf-store';
|
||||
import { OrderItemListItemDTO } from '@swagger/oms';
|
||||
|
||||
fdescribe('#SearchStateReducer', () => {
|
||||
const id = 123;
|
||||
@@ -141,4 +142,67 @@ fdescribe('#SearchStateReducer', () => {
|
||||
expect(state.entities[action.id].state).toEqual(SearchProcessState.INIT);
|
||||
});
|
||||
});
|
||||
|
||||
describe('addResult', () => {
|
||||
let action: {
|
||||
id: number;
|
||||
result: OrderItemListItemDTO[];
|
||||
isNewSearch?: boolean;
|
||||
} & TypedAction<string> & {
|
||||
type: string;
|
||||
};
|
||||
|
||||
const addProductsAction = actions.addResult({
|
||||
id,
|
||||
result: [
|
||||
{ orderId: 789, orderItemSubsetId: 234 },
|
||||
{ orderId: 456, orderItemSubsetId: 543 },
|
||||
],
|
||||
isNewSearch: false,
|
||||
});
|
||||
|
||||
it('should set the provided result as result if it is a new search', () => {
|
||||
action = actions.addResult({
|
||||
id,
|
||||
result: [{ orderId: 123 }],
|
||||
isNewSearch: true,
|
||||
});
|
||||
|
||||
let state = searchReducer(initialState, addProductsAction);
|
||||
state = searchReducer(state, action);
|
||||
|
||||
expect(state.entities[action.id].result.length).toEqual(
|
||||
action.result.length
|
||||
);
|
||||
expect(
|
||||
state.entities[action.id].result.find(
|
||||
(r) => r.orderId === action.result[0].orderId
|
||||
)
|
||||
).toBeTruthy();
|
||||
});
|
||||
it('should add the provided result to the existing results if it is not a new search', () => {
|
||||
action = actions.addResult({
|
||||
id,
|
||||
result: [{ orderId: 567, orderItemSubsetId: 890 }],
|
||||
isNewSearch: false,
|
||||
});
|
||||
|
||||
let state = searchReducer(initialState, addProductsAction);
|
||||
state = searchReducer(state, action);
|
||||
|
||||
expect(state.entities[action.id].result.length).toEqual(
|
||||
action.result.length + addProductsAction.result.length
|
||||
);
|
||||
expect(
|
||||
state.entities[action.id].result.find(
|
||||
(r) => r.orderId === action.result[0].orderId
|
||||
)
|
||||
).toBeTruthy();
|
||||
expect(
|
||||
state.entities[action.id].result.find(
|
||||
(r) => r.orderId === addProductsAction.result[0].orderId
|
||||
)
|
||||
).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -126,7 +126,9 @@ const _searchReducer = createReducer(
|
||||
{
|
||||
id: a.id,
|
||||
changes: {
|
||||
result: [...entitiesWithoutDublicatedItems, ...a.result],
|
||||
result: a.isNewSearch
|
||||
? [...a.result]
|
||||
: [...entitiesWithoutDublicatedItems, ...a.result],
|
||||
state: SearchProcessState.FETCHED,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user