Skip to content

Commit

Permalink
Add tests for URLWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
alisman committed Oct 4, 2019
1 parent 2d8d506 commit 0c6aeeb
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 128 deletions.
1 change: 0 additions & 1 deletion src/pages/resultsView/ResultsViewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {showCustomTab} from "../../shared/lib/customTabs";
import {getTabId, parseConfigDisabledTabs, parseSamplesSpecifications, ResultsViewTab} from "./ResultsViewPageHelpers";
import {buildResultsViewPageTitle, doesQueryHaveCNSegmentData} from "./ResultsViewPageStoreUtils";
import {AppStore} from "../../AppStore";
import {updateResultsViewQuery} from "./ResultsViewQuery";
import {trackQuery} from "../../shared/lib/tracking";
import {onMobxPromise} from "../../shared/lib/onMobxPromise";
import QueryAndDownloadTabs from "shared/components/query/QueryAndDownloadTabs";
Expand Down
1 change: 0 additions & 1 deletion src/pages/resultsView/ResultsViewPageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ import {
makeComparisonGroupClinicalAttributes,
makeProfiledInClinicalAttributes
} from "../../shared/components/oncoprint/ResultsViewOncoprintUtils";
import {ResultsViewQuery} from "./ResultsViewQuery";
import {annotateAlterationTypes} from "../../shared/lib/oql/annotateAlterationTypes";
import {ErrorMessages} from "../../shared/enums/ErrorEnums";
import {
Expand Down
125 changes: 0 additions & 125 deletions src/pages/resultsView/ResultsViewQuery.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/pages/resultsView/ResultsViewURLWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export type ResultsViewURLQuery = {
genetic_profile_ids_GENERIC_ASSAY:string;
genetic_profile_ids:string;


};

export default class ResultsViewURLWrapper extends URLWrapper<ResultsViewURLQuery> {
Expand Down
70 changes: 70 additions & 0 deletions src/shared/lib/URLWrapper.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { assert } from "chai";
import ResultsViewURLWrapper from "pages/resultsView/ResultsViewURLWrapper";
import { autorun, observable, reaction } from "mobx";
import ExtendedRouterStore from "shared/lib/ExtendedRouterStore";
import sinon from "sinon";

describe("URLWrapper", () => {
it("resolves properties aliases correctly", () => {
const fakeRouter = observable({
query: { cancer_study_id: "some_study_id", non_property: "foo" },
}) as any;

const wrapper = new ResultsViewURLWrapper(fakeRouter);

assert.equal(wrapper.query.cancer_study_list, "some_study_id", "alias resolves to correct param");
assert.notProperty(wrapper.query, "cancer_study_id");
});

it("resolves properties correctly", () => {
const fakeRouter = observable({
query: { case_ids: "bar", non_property: "foo" },
}) as any;

const wrapper = new ResultsViewURLWrapper(fakeRouter);

assert.notProperty(wrapper.query, "non_property");
assert.equal(wrapper.query.case_ids, "bar");
});

it("reacts to underling routing store according to rules", () => {
const fakeRouter = observable({
query: { case_ids: "bar", non_property: "foo" },
location: { pathname: "/results" },
}) as any;

const wrapper = new ResultsViewURLWrapper(fakeRouter);

const stub = sinon.stub();

const disposer = reaction(() => wrapper.query.case_ids, stub);

assert.equal(stub.args.length, 0, "stub hasn't been called");

fakeRouter.query.case_ids = "bar2";

assert.equal(stub.args.length, 1, "stub has been called due to update to property");

fakeRouter.query.case_ids = "bar2";

assert.equal(stub.args.length, 1, "setting property to existing value does not cause reaction");

fakeRouter.query.cancer_study_list = "study1";

assert.equal(
stub.args.length,
1,
"setting query property which is not referenced in reaction does not cause reaction"
);

fakeRouter.query.case_ids = "bar3";

assert.equal(stub.args.length, 2, "setting property to knew value DOES cause reaction");

fakeRouter.location.pathname = "/patient";
fakeRouter.query.case_ids = "bar4";
assert.equal(stub.args.length, 2, "does not react when pathname doesn't match");

disposer();
});
});

0 comments on commit 0c6aeeb

Please sign in to comment.