-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |