1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
const jsdom = require('jsdom')
const { JSDOM } = jsdom
const http = require('http')
var enableDestroy = require('server-destroy')
describe("login", () => {
var server
var authResponse
beforeAll(() => {
var authListener = (req,res) => {
res.setHeader("Content-Type", "application/json")
res.writeHead(200)
res.end(authResponse)
}
server = http.createServer(authListener)
server.listen(15672)
enableDestroy(server)
})
afterAll(() => {
server.destroy()
})
describe("outer", () => {
it("should have an outer block", () => {
JSDOM.fromFile("../index.html").then(dom => {
expect(dom.window.document.getElementById('outer')).toBeDefined()
})
})
})
describe("when OAuth is not enabled", () => {
beforeEach(() => {
authResponse = `{
"enable_oauth": false,
"enable_uaa": false,
"client_id": "",
"oauth_location": "",
"uaa_client_id": "",
"uaa_location": ""
}`
})
it("should render the login form", () => {
JSDOM.fromFile("../index.html", { runScripts: "dangerously" }).then(dom => {
const login = dom.window.document.getElementById('login')
expect(login).toBeDefined()
const loginStatus = dom.window.document.getElementById('login-status')
expect(loginStatus).toBeDefined()
const inputs = [...dom.window.document.querySelectorAll('input')]
expect(inputs).toHaveSize(3)
expect(inputs[0].type).toEqual("text")
expect(inputs[1].type).toEqual("password")
expect(inputs[2].type).toEqual("submit")
})
})
})
describe("when OAuth is enabled", () => {
beforeEach(() => {
authResponse = `{
"enable_oauth": true,
"enable_uaa": false,
"client_id": "validID",
"oauth_location": "someURL",
"uaa_client_id": "",
"uaa_location": ""
}`
})
describe("when the OAuth provider is UAA", () => {
beforeEach(() => {
authResponse = `{
"enable_oauth": true,
"enable_uaa": true,
"client_id": "",
"oauth_location": "",
"uaa_client_id": "validID",
"uaa_location": "someURL"
}`
})
it("should render the link to UAA", () => {
JSDOM.fromFile("../index.html", { runScripts: "dangerously" }).then(dom => {
const login = dom.window.document.getElementById('login')
expect(login).toBeDefined()
const loginStatus = dom.window.document.getElementById('login-status')
expect(loginStatus).toBeDefined()
})
})
})
})
})
|