forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager.test.ts
More file actions
189 lines (179 loc) · 6.53 KB
/
Copy pathmanager.test.ts
File metadata and controls
189 lines (179 loc) · 6.53 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* eslint-env jest */
import { TextEncoder, TextDecoder } from 'util'
global.TextEncoder = TextEncoder as any
global.TextDecoder = TextDecoder as any
import OutlineManager from './manager'
import { lit, NamedNode, sym, blankNode } from 'rdflib'
import { findByText, getByText } from '@testing-library/dom'
const MockPane = {
render: (subject: NamedNode) => {
const div = document.createElement('div')
div.appendChild(document.createTextNode(`Mock Pane for ${subject.uri}`))
return div
}
}
const mockPaneRegistry = {
list: [],
byName: () => MockPane
}
describe('manager', () => {
describe('outline object td', () => {
describe('for a named node', () => {
let result
beforeAll(() => {
const table = document.createElement('table')
const row = document.createElement('tr')
table.appendChild(row)
const manager = new OutlineManager({ dom: document, session: { paneRegistry: mockPaneRegistry } })
result = manager.outlineObjectTD(sym('https://namednode.example/'), null, null, null)
row.appendChild(result)
})
it('is a html td element', () => {
expect(result.nodeName).toBe('TD')
})
it('about attribute refers to node', () => {
expect(result).toHaveAttribute('about', '<https://namednode.example/>')
})
it('has class obj', () => {
expect(result).toHaveClass('obj')
})
it('is selectable', () => {
expect(result).toHaveAttribute('notselectable', 'false')
})
it('has style', () => {
expect(result).toHaveStyle('margin: 0.2em; border: none; padding: 0; vertical-align: top;')
})
it('shows an expand icon', () => {
const img = result.firstChild
expect(img.nodeName).toBe('IMG')
expect(img).toHaveAttribute('src', 'https://solidos.github.io/solid-ui/src/originalIcons/tbl-expand-trans.png')
})
it('shows the node label', () => {
expect(result).toHaveTextContent('namednode.example')
})
it('label is draggable', () => {
const label = getByText(result, 'namednode.example')
expect(label).toHaveAttribute('draggable', 'true')
})
describe('link icon', () => {
let linkIcon
beforeEach(() => {
const label = getByText(result, 'namednode.example')
linkIcon = label.lastChild
})
it('is linked to named node URI', () => {
expect(linkIcon.nodeName).toBe('A')
expect(linkIcon).toHaveAttribute('href', 'https://namednode.example/')
})
})
describe('expanding', () => {
it('renders relevant pane', async () => {
const expand = result.firstChild
expand.click()
const error = await findByText(result.parentNode, /Mock Pane/)
expect(error).toHaveTextContent('Mock Pane for https://namednode.example/')
})
})
})
describe('for a tel uri', () => {
let result
beforeAll(() => {
const manager = new OutlineManager({ dom: document })
result = manager.outlineObjectTD(sym('tel:+1-201-555-0123'), null, null, null)
})
it('is a html td element', () => {
expect(result.nodeName).toBe('TD')
})
it('about attribute refers to tel uri', () => {
expect(result).toHaveAttribute('about', '<tel:+1-201-555-0123>')
})
it('has class obj', () => {
expect(result).toHaveClass('obj')
})
it('is selectable', () => {
expect(result).toHaveAttribute('notselectable', 'false')
})
it('has style', () => {
expect(result).toHaveStyle('margin: 0.2em; border: none; padding: 0; vertical-align: top;')
})
it('shows an expand icon', () => {
const img = result.firstChild
expect(img.nodeName).toBe('IMG')
expect(img).toHaveAttribute('src', 'https://solidos.github.io/solid-ui/src/originalIcons/tbl-expand-trans.png')
})
it('shows the phone number', () => {
expect(result).toHaveTextContent('+1-201-555-0123')
})
describe('phone link', () => {
let phoneLink
beforeAll(() => {
const label = getByText(result, '+1-201-555-0123')
phoneLink = label.lastChild
})
it('is linked to tel uri', () => {
expect(phoneLink.nodeName).toBe('A')
expect(phoneLink).toHaveAttribute('href', 'tel:+1-201-555-0123')
})
it('is represented by phone icon', () => {
const phoneIcon = phoneLink.lastChild
expect(phoneIcon.nodeName).toBe('IMG')
expect(phoneIcon).toHaveAttribute('src', 'https://solidos.github.io/solid-ui/src/originalIcons/silk/telephone.png')
})
})
})
describe('for a literal', () => {
let result
beforeAll(() => {
const manager = new OutlineManager({ dom: document })
result = manager.outlineObjectTD(lit('some text'), null, null, null)
})
it('is a html td element', () => {
expect(result.nodeName).toBe('TD')
})
it('has no about attribute', () => {
expect(result).not.toHaveAttribute('about')
})
it('has class obj', () => {
expect(result).toHaveClass('obj')
})
it('is selectable', () => {
expect(result).toHaveAttribute('notselectable', 'false')
})
it('has style', () => {
expect(result).toHaveStyle('margin: 0.2em; border: none; padding: 0; vertical-align: top;')
})
it('shows the literal text', () => {
expect(result).toHaveTextContent('some text')
})
it('literal text preserves white space', () => {
const text = getByText(result, 'some text')
expect(text).toHaveStyle('white-space: pre-wrap;')
})
})
describe('for a blank node', () => {
let result
beforeAll(() => {
const manager = new OutlineManager({ dom: document })
result = manager.outlineObjectTD(blankNode('blank-node'), null, null, null)
})
it('is a html td element', () => {
expect(result.nodeName).toBe('TD')
})
it('has about attribute', () => {
expect(result).toHaveAttribute('about', '_:blank-node')
})
it('has class obj', () => {
expect(result).toHaveClass('obj')
})
it('is selectable', () => {
expect(result).toHaveAttribute('notselectable', 'false')
})
it('has style', () => {
expect(result).toHaveStyle('margin: 0.2em; border: none; padding: 0; vertical-align: top;')
})
it('shows 3 dots', () => {
expect(result).toHaveTextContent('...')
})
})
})
})