Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed May 16, 2023
1 parent 7d9d90b commit d99b695
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
removeScientificConditionAction,
setDateRangeFilterAction,
addScientificConditionAction,
setPidTermsAction,
} from "state-management/actions/datasets.actions";
import { of } from "rxjs";
import {
Expand Down Expand Up @@ -479,8 +480,9 @@ describe("DatasetsFilterComponent", () => {

component.clearFacets();

expect(dispatchSpy).toHaveBeenCalledTimes(2);
expect(dispatchSpy).toHaveBeenCalledTimes(3);
expect(dispatchSpy).toHaveBeenCalledWith(clearFacetsAction());
expect(dispatchSpy).toHaveBeenCalledWith(setPidTermsAction({ pid: "" }));
expect(dispatchSpy).toHaveBeenCalledWith(
deselectAllCustomColumnsAction()
);
Expand Down Expand Up @@ -545,4 +547,34 @@ describe("DatasetsFilterComponent", () => {
);
});
});

describe("#pidSearchChanged()", () => {
it("should dispatch a SetSearchTermsAction", () => {
dispatchSpy = spyOn(store, "dispatch");

const pid = "1";
component.pidSearchChanged(pid);

expect(dispatchSpy).toHaveBeenCalledTimes(1);
expect(dispatchSpy).toHaveBeenCalledWith(setPidTermsAction({ pid }));
});
});

describe("#buildPidTermsCondition()", () => {
const tests = [
["", "", ""],
["1", "startsWith", {"$regex": "^1"}],
["1", "contains", {"$regex": "1"}],
["1", "equals", "1"],
["1", "", "1"]
];
tests.forEach((t, i) => {
it(`should return buildPidTermsCondition ${i}`, () => {
component.appConfig.pidSeachMethod = t[1] as string;
const condition = component["buildPidTermsCondition"](t[0] as string);
expect(condition).toEqual(t[2]);
});
});
});

});
16 changes: 16 additions & 0 deletions src/app/state-management/actions/datasets.actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,4 +746,20 @@ describe("Dataset Actions", () => {
expect({ ...action }).toEqual({ type: "[Dataset] Clear State" });
});
});

describe("setPidTermsAction", () => {
it("should create an action", () => {
const pid = "1";
const action = fromActions.setPidTermsAction({ pid });
expect({ ...action }).toEqual({ type: "[Dataset] Set Pid Terms", pid });
});
});

describe("setPidTermsFilterAction", () => {
it("should create an action", () => {
const pid = {"$regex": "1"};
const action = fromActions.setPidTermsFilterAction({ pid });
expect({ ...action }).toEqual({ type: "[Dataset] Set Text Filter", pid });
});
});
});
20 changes: 20 additions & 0 deletions src/app/state-management/reducers/datasets.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,24 @@ describe("DatasetsReducer", () => {
expect(state).toEqual(initialDatasetState);
});
});

describe("on setPidTermsAction", () => {
it("should set dataset state to initialDatasetStata", () => {
const pid = "1";
const action = fromActions.setPidTermsAction({ pid });
const state = fromDatasets.datasetsReducer(initialDatasetState, action);

expect(state.pidTerms).toEqual(pid);
});
});

describe("on setPidTermsFilterAction", () => {
it("should set dataset state to initialDatasetStata", () => {
const pid = {"$regex": "1"};
const action = fromActions.setPidTermsFilterAction({ pid });
const state = fromDatasets.datasetsReducer(initialDatasetState, action);

expect(state.filters.pid).toEqual(pid);
});
});
});
13 changes: 12 additions & 1 deletion src/app/state-management/selectors/datasets.selectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const initialDatasetState: DatasetState = {
hasPrefilledFilters: false,
searchTerms: "run",
keywordsTerms: "",
pidTerms: "",
pidTerms: "pid",
batch: [],

openwhiskResult: {},
Expand All @@ -39,6 +39,7 @@ const initialDatasetState: DatasetState = {
keywords: [],
scientific: [],
isPublished: false,
pid: "",
},
relatedDatasetsFilters: {
skip: 0,
Expand Down Expand Up @@ -403,4 +404,14 @@ describe("test dataset selectors", () => {
});
});
});

describe("selectPidTerms", () => {
it("should select the current pid terms", () => {
expect(
fromDatasetSelectors.selectPidTerms.projector(initialDatasetState)
).toEqual("pid");
});
});


});

0 comments on commit d99b695

Please sign in to comment.