-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(frame-router): add tests for the current host URL modification b…
…ehavior This behavior is somewhat inconsistent and should be re-worked in the future, but this will let us make small improvements and bugfixes without regressing current behavior in a way that could break existing usage.
- Loading branch information
1 parent
7043f32
commit 8abfc2e
Showing
1 changed file
with
70 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { FrameRouterElement } from "../host"; | ||
|
||
const ENV_DATA = { | ||
locale: "en-us", | ||
hostRootUrl: "https://example.com/root/", | ||
}; | ||
|
||
const ENV_DATA_WITH_HASH = { | ||
...ENV_DATA, | ||
hostRootUrl: "https://example.com/root/#/", | ||
}; | ||
|
||
describe("The frame router element", () => { | ||
beforeAll(() => { | ||
window.customElements.define("frame-router", FrameRouterElement); | ||
}); | ||
|
||
beforeEach(() => { | ||
// Reset window hash state | ||
window.location.hash = ""; | ||
}); | ||
|
||
/* NOTE: This behavior is inconsistent in practice and needs to be reworked. | ||
* For now, these tests prevent regressions against the current inconsistent | ||
* behavior. | ||
*/ | ||
describe("Host URL management", () => { | ||
it("Removes a trailing slash on the host URL if present", () => { | ||
const router = new FrameRouterElement(); | ||
router.clientConfig = { | ||
clients: {}, | ||
envData: ENV_DATA, | ||
}; | ||
//@ts-ignore | ||
expect(router._envData).toEqual({ | ||
...ENV_DATA, | ||
hostRootUrl: "https://example.com/root", | ||
}); | ||
}); | ||
|
||
it("Adds a fragment to the tracked host URL if one is present on window but not on the provided root URL", () => { | ||
window.location.hash = "foo"; | ||
const router = new FrameRouterElement(); | ||
router.clientConfig = { | ||
clients: {}, | ||
envData: ENV_DATA, | ||
}; | ||
//@ts-ignore | ||
expect(router._envData).toEqual({ | ||
...ENV_DATA, | ||
hostRootUrl: "https://example.com/root/#", | ||
}); | ||
}); | ||
|
||
it("Does not modify the provided host URL if it and the current location have a fragment", () => { | ||
window.location.hash = "foo"; | ||
const router = new FrameRouterElement(); | ||
router.clientConfig = { | ||
clients: {}, | ||
envData: ENV_DATA_WITH_HASH, | ||
}; | ||
//@ts-ignore | ||
expect(router._envData).toEqual({ | ||
...ENV_DATA_WITH_HASH, | ||
}); | ||
}); | ||
|
||
// TODO: Test expected query behavior here | ||
}); | ||
}); |