-
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.
Add a unit test for binderhub source code too
- Loading branch information
Showing
5 changed files
with
71 additions
and
21 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 |
---|---|---|
@@ -1,29 +1,32 @@ | ||
# Runs jest based unit tests for the binderhub-client JS package | ||
name: "binderhub-client unit tests" | ||
# Runs jest based unit tests for frontend javascript and @jupyterhub/binderhub-client | ||
name: "JS Unit tests" | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
paths: &paths | ||
- "binderhub/static/js/**" | ||
- "js/packages/binderhub-client/**" | ||
push: | ||
paths: | ||
- "js/**" | ||
paths: *paths | ||
branches-ignore: | ||
- "dependabot/**" | ||
- "pre-commit-ci-update-config" | ||
- "update-*" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- run: | | ||
cd js/packages/binderhub-client | ||
- name: "binderhub unit tests" | ||
run: | | ||
npm install | ||
npm test | ||
- run: | | ||
- name: "@jupyterhub/binderhub-client unit tests" | ||
run: | | ||
cd js/packages/binderhub-client | ||
npm install | ||
npm test |
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