-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1758 from yuvipanda/urlsearchparamsagain
JS: Add unit tests (with coverage) & use `URL` object instead of strings to construct some URLs
- Loading branch information
Showing
8 changed files
with
318 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Runs jest based unit tests for frontend javascript and @jupyterhub/binderhub-client | ||
name: "JS Unit tests" | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- "binderhub/static/js/**" | ||
- "js/packages/binderhub-client/**" | ||
- ".github/workflows/jest.yml" | ||
push: | ||
paths: | ||
- "binderhub/static/js/**" | ||
- "js/packages/binderhub-client/**" | ||
- ".github/workflows/jest.yml" | ||
branches-ignore: | ||
- "dependabot/**" | ||
- "pre-commit-ci-update-config" | ||
- "update-*" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: "Setup dependencies" | ||
run: | | ||
npm install | ||
- name: "Run all unit tests" | ||
run: | | ||
npm test | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v3 |
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,17 @@ | ||
/** | ||
* Dynamically set current page's favicon. | ||
* | ||
* @param {String} href Path to Favicon to use | ||
*/ | ||
function updateFavicon(href) { | ||
let link = document.querySelector("link[rel*='icon']"); | ||
if(!link) { | ||
link = document.createElement('link'); | ||
document.getElementsByTagName('head')[0].appendChild(link); | ||
} | ||
link.type = 'image/x-icon'; | ||
link.rel = 'shortcut icon'; | ||
link.href = href; | ||
} | ||
|
||
export { updateFavicon }; |
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,29 @@ | ||
import { updateFavicon } from "./favicon"; | ||
|
||
afterEach(() => { | ||
// Clear out HEAD after each test run, so our DOM is clean. | ||
// Jest does *not* clear out the DOM between test runs on the same file! | ||
document.querySelector("head").innerHTML = ''; | ||
}); | ||
|
||
test("Setting favicon when there is none works", () => { | ||
expect(document.querySelector("link[rel*='icon']")).toBeNull(); | ||
|
||
updateFavicon("https://example.com/somefile.png"); | ||
|
||
expect(document.querySelector("link[rel*='icon']").href).toBe("https://example.com/somefile.png"); | ||
}); | ||
|
||
test("Setting favicon multiple times works without leaking link tags", () => { | ||
expect(document.querySelector("link[rel*='icon']")).toBeNull(); | ||
|
||
updateFavicon("https://example.com/somefile.png"); | ||
|
||
expect(document.querySelector("link[rel*='icon']").href).toBe("https://example.com/somefile.png"); | ||
expect(document.querySelectorAll("link[rel*='icon']").length).toBe(1); | ||
|
||
updateFavicon("https://example.com/some-other-file.png"); | ||
|
||
expect(document.querySelector("link[rel*='icon']").href).toBe("https://example.com/some-other-file.png"); | ||
expect(document.querySelectorAll("link[rel*='icon']").length).toBe(1); | ||
}); |
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
Oops, something went wrong.