Skip to content

Commit 2a761a0

Browse files
committed
wip
1 parent 7cc26aa commit 2a761a0

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

test/browser/pages/login.test.ts

+47-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,53 @@ import { LocationLike } from "../../unit/util.test"
33

44
describe("login", () => {
55
// TODO test for when el is defined
6-
describe.skip("when navigator and serviceWorker are NOT defined", () => {
7-
it("should log an error", () => {
8-
// Load service worker like you would in the browser
9-
require("../../src/browser/register")
6+
describe("there is an element with id base", () => {
7+
// let initialDom: Document
8+
beforeEach(() => {
9+
const dom = new JSDOM()
10+
// initialDom = dom.window.document
11+
global.document = dom.window.document
12+
13+
const location: LocationLike = {
14+
pathname: "/healthz",
15+
origin: "http://localhost:8080",
16+
}
17+
18+
global.location = location as Location
19+
})
20+
afterEach(() => {
21+
// Reset the global.document
22+
global.document = undefined as any as Document
23+
global.location = undefined as any as Location
24+
})
25+
it("should set the value to options.base", () => {
26+
// Mock getElementById
27+
// const oldGetElementByIdFn = document.getElementById
28+
// const spy = jest.spyOn(document, "getElementById")
29+
// Create a fake element and set the attribute
30+
const mockElement = document.createElement("div")
31+
mockElement.setAttribute("id", "base")
32+
mockElement.setAttribute(
33+
"data-settings",
34+
'{"base":"./hello-world","csStaticBase":"./static/development/Users/jp/Dev/code-server","logLevel":2,"disableTelemetry":false,"disableUpdateCheck":false}',
35+
)
36+
mockElement.setAttribute("value", "initial")
37+
// spy.mockImplementation(() => mockElement)
38+
// Load file
39+
require("../../../src/browser/pages/login")
40+
// Called once by getOptions and the second in
41+
// expect(spy).toHaveBeenCalledTimes(2)
42+
// spy.mockRestore()
43+
// document.getElementById = oldGetElementByIdFn
44+
45+
const currentDom = document
46+
47+
const el = currentDom.getElementById("base")
48+
console.log(document.querySelectorAll("div"))
49+
expect(el?.getAttribute("value")).toBe("hello-joe")
1050
})
1151
})
12-
// TODO test for when el is undefined
52+
1353
describe("there is no element with id 'base'", () => {
1454
let initialDom: Document
1555
beforeEach(() => {
@@ -27,7 +67,9 @@ describe("login", () => {
2767
afterEach(() => {
2868
// Reset the global.document
2969
global.document = undefined as any as Document
70+
global.location = undefined as any as Location
3071
})
72+
3173
it("should not change the DOM", () => {
3274
// Load file
3375
require("../../../src/browser/pages/login")

0 commit comments

Comments
 (0)