Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/app/state-management/effects/datasets.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ describe("DatasetEffects", () => {
const expected = cold("--b", { b: outcome });
expect(effects.fetchDatasets$).toBeObservable(expected);
});

it("should cancel a previous in-flight request when a new action is dispatched", () => {
const datasets = [dataset];
const action = fromActions.fetchDatasetsAction();
const outcome = fromActions.fetchDatasetsCompleteAction({ datasets });

// Second action at frame 3 cancels the first request (which would complete at frame 3).
// Only the response to the second action, arriving at frame 5, is emitted.
actions = hot("-a-b", { a: action, b: action });
const response = cold("--a|", { a: datasets });
datasetApi.datasetsControllerFullqueryV3.and.returnValue(response);

const expected = cold("-----b", { b: outcome });
expect(effects.fetchDatasets$).toBeObservable(expected);
});
});

describe("fetchFacetCounts$", () => {
Expand Down Expand Up @@ -182,6 +197,38 @@ describe("DatasetEffects", () => {
const expected = cold("--b", { b: outcome });
expect(effects.fetchFacetCounts$).toBeObservable(expected);
});

it("should cancel a previous in-flight request when a new action is dispatched", () => {
const facetCounts: FacetCounts = {
creationLocation: [],
creationTime: [],
keywords: [],
ownerGroup: [],
type: [],
};
const action = fromActions.fetchFacetCountsAction();
const outcome = fromActions.fetchFacetCountsCompleteAction({
facetCounts,
allCounts: 0,
});
const responseArray = [
{
all: [{ totalSets: 0 }],
creationLocation: [],
creationTime: [],
keywords: [],
ownerGroup: [],
type: [],
},
];

actions = hot("-a-b", { a: action, b: action });
const response = cold("--a|", { a: responseArray });
datasetApi.datasetsControllerFullfacetV3.and.returnValue(response);

const expected = cold("-----b", { b: outcome });
expect(effects.fetchFacetCounts$).toBeObservable(expected);
});
});

describe("fetchMetadataKeys$", () => {
Expand Down Expand Up @@ -211,6 +258,21 @@ describe("DatasetEffects", () => {
const expected = cold("--b", { b: outcome });
expect(effects.fetchMetadataKeys$).toBeObservable(expected);
});

it("should cancel a previous in-flight request when a new action is dispatched", () => {
const metadataKeys = ["test"];
const action = fromActions.fetchMetadataKeysAction();
const outcome = fromActions.fetchMetadataKeysCompleteAction({
metadataKeys,
});

actions = hot("-a-b", { a: action, b: action });
const response = cold("--a|", { a: metadataKeys });
datasetApi.datasetsControllerMetadataKeysV3.and.returnValue(response);

const expected = cold("-----b", { b: outcome });
expect(effects.fetchMetadataKeys$).toBeObservable(expected);
});
});

describe("updateUserDatasetsLimit$", () => {
Expand Down
6 changes: 3 additions & 3 deletions src/app/state-management/effects/datasets.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class DatasetEffects {
}
return params;
}),
mergeMap(({ query, limits }) =>
switchMap(({ query, limits }) =>
this.datasetsService
.datasetsControllerFullqueryV3(
JSON.stringify(limits),
Expand All @@ -102,7 +102,7 @@ export class DatasetEffects {
),
concatLatestFrom(() => this.fullfacetParams$),
map(([, params]) => params),
mergeMap(({ fields, facets }) =>
switchMap(({ fields, facets }) =>
this.datasetsService
.datasetsControllerFullfacetV3(
JSON.stringify(facets),
Expand All @@ -129,7 +129,7 @@ export class DatasetEffects {
ofType(fromActions.fetchMetadataKeysAction),
concatLatestFrom(() => this.fullqueryParams$),
map(([, params]) => params),
mergeMap(({ query }) => {
switchMap(({ query }) => {
return this.datasetsService
.datasetsControllerMetadataKeysV3(JSON.stringify(query))
.pipe(
Expand Down
26 changes: 26 additions & 0 deletions src/app/state-management/effects/proposals.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,32 @@ describe("ProposalEffects", () => {
const expected = cold("--b", { b: outcome });
expect(effects.fetchProposalDatasets$).toBeObservable(expected);
});

it("should cancel a previous in-flight request when a new action is dispatched", () => {
const datasets = [dataset];
const skip = 0;
const limit = 50;
const action = fromActions.fetchProposalDatasetsAction({
proposalId,
skip,
limit,
});
const outcome1 = fromActions.fetchProposalDatasetsCompleteAction({
datasets,
skip,
limit,
});
const outcome2 = fromActions.fetchProposalDatasetsCountAction({
proposalId,
});

actions = hot("-a-b", { a: action, b: action });
const response = cold("--a|", { a: datasets });
datasetApi.datasetsControllerFindAllV3.and.returnValue(response);

const expected = cold("-----(bc)", { b: outcome1, c: outcome2 });
expect(effects.fetchProposalDatasets$).toBeObservable(expected);
});
});

describe("fetchProposalDatasetsCount$", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/state-management/effects/proposals.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class ProposalEffects {
fetchProposalDatasets$ = createEffect(() => {
return this.actions$.pipe(
ofType(fromActions.fetchProposalDatasetsAction),
mergeMap(({ skip, limit, sortColumn, sortDirection, proposalId }) => {
switchMap(({ skip, limit, sortColumn, sortDirection, proposalId }) => {
return this.datasetsService
.datasetsControllerFindAllV3(
JSON.stringify({
Expand Down
Loading