mirror of
https://git.tuxpa.in/a/code-server.git
synced 2024-12-26 12:15:26 +00:00
feat(test): add tests for src/browser/login
This commit is contained in:
parent
be7ea8f3f7
commit
b597519ab5
69
test/browser/pages/login.test.ts
Normal file
69
test/browser/pages/login.test.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import { JSDOM } from "jsdom"
|
||||
import { LocationLike } from "../../unit/util.test"
|
||||
|
||||
describe("login", () => {
|
||||
describe("there is an element with id 'base'", () => {
|
||||
beforeEach(() => {
|
||||
const dom = new JSDOM()
|
||||
global.document = dom.window.document
|
||||
|
||||
const location: LocationLike = {
|
||||
pathname: "/healthz",
|
||||
origin: "http://localhost:8080",
|
||||
}
|
||||
|
||||
global.location = location as Location
|
||||
})
|
||||
afterEach(() => {
|
||||
// Reset the global.document
|
||||
global.document = undefined as any as Document
|
||||
global.location = undefined as any as Location
|
||||
})
|
||||
it("should set the value to options.base", () => {
|
||||
// Mock getElementById
|
||||
const spy = jest.spyOn(document, "getElementById")
|
||||
// Create a fake element and set the attribute
|
||||
const mockElement = document.createElement("input")
|
||||
mockElement.setAttribute("id", "base")
|
||||
mockElement.setAttribute(
|
||||
"data-settings",
|
||||
'{"base":"./hello-world","csStaticBase":"./static/development/Users/jp/Dev/code-server","logLevel":2,"disableTelemetry":false,"disableUpdateCheck":false}',
|
||||
)
|
||||
document.body.appendChild(mockElement)
|
||||
spy.mockImplementation(() => mockElement)
|
||||
// Load file
|
||||
require("../../../src/browser/pages/login")
|
||||
|
||||
const el: HTMLInputElement | null = document.querySelector("input#base")
|
||||
expect(el?.value).toBe("/hello-world")
|
||||
})
|
||||
})
|
||||
|
||||
describe("there is no element with id 'base'", () => {
|
||||
let initialDom: Document
|
||||
beforeEach(() => {
|
||||
const dom = new JSDOM()
|
||||
initialDom = dom.window.document
|
||||
global.document = dom.window.document
|
||||
|
||||
const location: LocationLike = {
|
||||
pathname: "/healthz",
|
||||
origin: "http://localhost:8080",
|
||||
}
|
||||
|
||||
global.location = location as Location
|
||||
})
|
||||
afterEach(() => {
|
||||
// Reset the global.document
|
||||
global.document = undefined as any as Document
|
||||
global.location = undefined as any as Location
|
||||
})
|
||||
|
||||
it("should not change the DOM", () => {
|
||||
// Load file
|
||||
require("../../../src/browser/pages/login")
|
||||
const currentDom = global.document
|
||||
expect(initialDom).toBe(currentDom)
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user