forked from SolidOS/solid-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-agent-buttons.test.ts
More file actions
175 lines (163 loc) · 5.72 KB
/
Copy pathadd-agent-buttons.test.ts
File metadata and controls
175 lines (163 loc) · 5.72 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { silenceDebugMessages } from '../../helpers/setup'
import { AddAgentButtons } from '../../../src/acl/add-agent-buttons'
import { instantiateAccessGroups } from '../helpers/instantiateAccessGroups'
import { JSDOM } from 'jsdom'
import { solidLogicSingleton } from 'solid-logic'
const store = solidLogicSingleton.store
silenceDebugMessages()
const dom = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window.document
function instantiateAddAgentButtons () {
const groupList = instantiateAccessGroups(dom, store)
return new AddAgentButtons(groupList)
}
function getButtonName (element: HTMLElement): string {
expect(element.tagName).toEqual('BUTTON')
expect((element.childNodes[0] as HTMLElement).tagName).toEqual('IMG')
return (element.childNodes[0] as HTMLImageElement).title
}
describe('AddAgentButtons', () => {
it('exists', () => {
expect(AddAgentButtons).toBeInstanceOf(Function)
})
it('runs', () => {
expect(instantiateAddAgentButtons()).toBeInstanceOf(Object)
})
})
describe('AddAgentButtons#render', () => {
it('exists', () => {
expect(instantiateAddAgentButtons().render).toBeInstanceOf(Function)
})
it('runs', () => {
expect(instantiateAddAgentButtons().render()).toBeInstanceOf(Object)
})
})
describe('AgentButtons', () => {
let agentButtons: any
beforeEach(() => {
agentButtons = instantiateAddAgentButtons().render()
})
it('exists', () => {
expect(agentButtons.constructor).toBeTruthy()
expect(agentButtons.childNodes.length).toEqual(2)
})
it('contains an add button', () => {
expect(getButtonName(agentButtons.childNodes[0])).toEqual('Add ...')
})
it('contains a bar element', () => {
expect(agentButtons.childNodes[1].tagName).toEqual('DIV')
expect(agentButtons.childNodes[1].innerHTML).toEqual('')
})
})
const barButtons = [
'Add Person',
'Add Group',
'Add Everyone',
'Anyone logged In',
'A Software Agent (bot)',
'A Web App (origin)'
]
describe('When add button is clicked', () => {
let bar: any
beforeEach(() => {
const agentButtons = instantiateAddAgentButtons().render()
const addButton = agentButtons.childNodes[0] as HTMLButtonElement
addButton.click()
bar = agentButtons.childNodes[1] as HTMLDivElement
})
it('bar is filled', () => {
expect(bar.childNodes.length).toEqual(barButtons.length)
})
for (let i = 0; i < barButtons.length; i++) {
it(`Bar contains a "${barButtons[i]}" button`, () => {
expect(getButtonName(bar.childNodes[i])).toEqual(barButtons[i])
})
}
})
describe('When "Add Person" button is clicked', () => {
let bar
const buttonIndex = 0
beforeEach(() => {
const agentButtons = instantiateAddAgentButtons().render()
const addButton = agentButtons.childNodes[0] as HTMLButtonElement
addButton.click()
bar = agentButtons.childNodes[1] as HTMLDivElement
const buttonToClick = bar.childNodes[buttonIndex] as HTMLButtonElement
buttonToClick.click()
})
it('bar is simplified', () => {
// expect(bar.childNodes.length).toEqual(1) ???
expect(bar.childNodes.length).toEqual(2)
})
it('Bar still contains the button that was clicked', () => {
expect(getButtonName(bar.childNodes[0])).toEqual(barButtons[buttonIndex])
})
it('Bar now contains askName form', () => {
expect(bar.childNodes[1].tagName).toEqual('DIV')
})
})
describe('When "Add Group" button is clicked', () => {
let bar
const buttonIndex = 1
beforeEach(() => {
const agentButtons = instantiateAddAgentButtons().render()
const addButton = agentButtons.childNodes[0] as HTMLButtonElement
addButton.click()
bar = agentButtons.childNodes[1] as HTMLDivElement
const buttonToClick = bar.childNodes[buttonIndex] as HTMLButtonElement
buttonToClick.click()
})
it('bar is simplified', () => {
expect(bar.childNodes.length).toEqual(2)
})
it('Bar still contains the button that was clicked', () => {
expect(getButtonName(bar.childNodes[0])).toEqual(barButtons[buttonIndex])
})
it('Bar now contains askName form', () => {
expect(bar.childNodes[1].tagName).toEqual('DIV')
})
})
describe('When "Add Bot" button is clicked', () => {
let bar
const buttonIndex = 4
beforeEach(() => {
const agentButtons = instantiateAddAgentButtons().render()
const addButton = agentButtons.childNodes[0] as HTMLButtonElement
addButton.click()
bar = agentButtons.childNodes[1] as HTMLDivElement
const buttonToClick = bar.childNodes[buttonIndex] as HTMLButtonElement
buttonToClick.click()
})
it('bar is simplified', () => {
expect(bar.childNodes.length).toEqual(2)
})
it('Bar still contains the button that was clicked', () => {
expect(getButtonName(bar.childNodes[0])).toEqual(barButtons[buttonIndex])
})
it('Bar now contains askName form', () => {
expect(bar.childNodes[1].tagName).toEqual('DIV')
})
})
describe('When "Add App" button is clicked', () => {
let bar
const buttonIndex = 5
beforeEach(() => {
const agentButtons = instantiateAddAgentButtons().render()
const addButton = agentButtons.childNodes[0] as HTMLButtonElement
addButton.click()
bar = agentButtons.childNodes[1] as HTMLDivElement
const buttonToClick = bar.childNodes[buttonIndex] as HTMLButtonElement
buttonToClick.click()
})
it('bar is simplified', () => {
expect(bar.childNodes.length).toEqual(3)
// Adds a third element to list, for reason I cannot understand - This does
// not happen when I "manually test" it, ie run it in the browser
// https://github.com/solidos/solid-ui/issues/236
})
it('Bar still contains the button that was clicked', () => {
expect(getButtonName(bar.childNodes[0])).toEqual(barButtons[buttonIndex])
})
it('Bar now contains apss table', () => {
expect(bar.childNodes[1].tagName).toEqual('DIV')
})
})