@@ -3,13 +3,53 @@ import { LocationLike } from "../../unit/util.test"
3
3
4
4
describe ( "login" , ( ) => {
5
5
// 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" )
10
50
} )
11
51
} )
12
- // TODO test for when el is undefined
52
+
13
53
describe ( "there is no element with id 'base'" , ( ) => {
14
54
let initialDom : Document
15
55
beforeEach ( ( ) => {
@@ -27,7 +67,9 @@ describe("login", () => {
27
67
afterEach ( ( ) => {
28
68
// Reset the global.document
29
69
global . document = undefined as any as Document
70
+ global . location = undefined as any as Location
30
71
} )
72
+
31
73
it ( "should not change the DOM" , ( ) => {
32
74
// Load file
33
75
require ( "../../../src/browser/pages/login" )
0 commit comments