Skip to content

Commit c4e7ee3

Browse files
committed
feat: add tests for pages/login.ts
1 parent 3524f03 commit c4e7ee3

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ VS Code v0.00.0
6565
### Development
6666

6767
- fix(publish): update cdrci fork in brew-bump.sh #3468 @jsjoeio
68+
- chore(dev): migrate away from parcel #3578 @jsjoeio
6869

6970
## 3.10.2
7071

test/browser/pages/login.test.ts

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { JSDOM } from "jsdom"
2+
import { LocationLike } from "../../unit/util.test"
3+
4+
describe("login", () => {
5+
describe("there is an element with id 'base'", () => {
6+
beforeEach(() => {
7+
const dom = new JSDOM()
8+
global.document = dom.window.document
9+
10+
const location: LocationLike = {
11+
pathname: "/healthz",
12+
origin: "http://localhost:8080",
13+
}
14+
15+
global.location = location as Location
16+
})
17+
afterEach(() => {
18+
// Reset the global.document
19+
global.document = undefined as any as Document
20+
global.location = undefined as any as Location
21+
})
22+
it("should set the value to options.base", () => {
23+
// Mock getElementById
24+
const spy = jest.spyOn(document, "getElementById")
25+
// Create a fake element and set the attribute
26+
const mockElement = document.createElement("input")
27+
mockElement.setAttribute("id", "base")
28+
mockElement.setAttribute(
29+
"data-settings",
30+
'{"base":"./hello-world","csStaticBase":"./static/development/Users/jp/Dev/code-server","logLevel":2,"disableTelemetry":false,"disableUpdateCheck":false}',
31+
)
32+
document.body.appendChild(mockElement)
33+
spy.mockImplementation(() => mockElement)
34+
// Load file
35+
require("../../../src/browser/pages/login")
36+
37+
const el: HTMLInputElement | null = document.querySelector("input#base")
38+
expect(el?.value).toBe("/hello-world")
39+
})
40+
})
41+
42+
describe("there is no element with id 'base'", () => {
43+
let initialDom: Document
44+
beforeEach(() => {
45+
const dom = new JSDOM()
46+
initialDom = dom.window.document
47+
global.document = dom.window.document
48+
49+
const location: LocationLike = {
50+
pathname: "/healthz",
51+
origin: "http://localhost:8080",
52+
}
53+
54+
global.location = location as Location
55+
})
56+
afterEach(() => {
57+
// Reset the global.document
58+
global.document = undefined as any as Document
59+
global.location = undefined as any as Location
60+
})
61+
62+
it("should not change the DOM", () => {
63+
// Load file
64+
require("../../../src/browser/pages/login")
65+
const currentDom = global.document
66+
expect(initialDom).toBe(currentDom)
67+
})
68+
})
69+
})

yarn.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -6435,9 +6435,9 @@ postcss-normalize-string@^4.0.2:
64356435
postcss-value-parser "^3.0.0"
64366436

64376437
postcss-normalize-string@^5.0.0:
6438-
version "5.0.0"
6439-
resolved "https://registry.yarnpkg.com/postcss-normalize-string/-/postcss-normalize-string-5.0.0.tgz#2ea08ff4cb8817ce160755e9fdc7e6ef6d495002"
6440-
integrity sha512-wSO4pf7GNcDZpmelREWYADF1+XZWrAcbFLQCOqoE92ZwYgaP/RLumkUTaamEzdT2YKRZAH8eLLKGWotU/7FNPw==
6438+
version "5.0.1"
6439+
resolved "https://registry.yarnpkg.com/postcss-normalize-string/-/postcss-normalize-string-5.0.1.tgz#d9eafaa4df78c7a3b973ae346ef0e47c554985b0"
6440+
integrity sha512-Ic8GaQ3jPMVl1OEn2U//2pm93AXUcF3wz+OriskdZ1AOuYV25OdgS7w9Xu2LO5cGyhHCgn8dMXh9bO7vi3i9pA==
64416441
dependencies:
64426442
postcss-value-parser "^4.1.0"
64436443

0 commit comments

Comments
 (0)