forked from SolidOS/solid-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpad.test.ts
More file actions
186 lines (175 loc) · 5.11 KB
/
Copy pathpad.test.ts
File metadata and controls
186 lines (175 loc) · 5.11 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
import { JSDOM } from 'jsdom'
import * as RdfLib from 'rdflib'
import * as pad from '../../src/pad'
const widgets = require('../../src/widgets')
jest.mock('rdflib')
jest.mock('solid-auth-client')
const window = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window
const dom = window.document
describe('lightColorHash', () => {
it('exists', () => {
expect((pad as any).lightColorHash).toBeInstanceOf(Function)
})
it('returns #ffffff when an author is not provided', () => {
// #ffffff is specifically stated in the code to be returned
// when there is no author
expect((pad as any).lightColorHash(null)).toBe('#ffffff')
})
it('returns a value when given an author', () => {
// #dac2dc is the hash of 'https://sharonstrats.inrupt.net/profile/card#me'
const author = { uri: 'https://sharonstrats.inrupt.net/profile/card#me' }
expect((pad as any).lightColorHash(author)).toBe('#dac2dc')
})
})
describe('renderPartipants', () => {
it('exists', () => {
expect((pad as any).renderPartipants).toBeInstanceOf(Function)
})
it('runs', () => {
const table = dom.createElement('table')
const padDoc = null
const subject = RdfLib.sym('')
const me = 'webId'
const options = {}
expect(
(pad as any).renderPartipants(dom, table, padDoc, subject, me, options)
).toMatchInlineSnapshot(`
<table
style="margin: 0.8em;"
/>
`)
})
it('returns without crashing when a person is not returned', () => {
// @@ TODO need to mock kb.any and kb.each - not working for some reason
// kb is a store
const table = dom.createElement('table')
const padDoc = null
const subject = RdfLib.sym('participation')
const me = 'webId'
const options = {}
expect(
(pad as any).renderPartipants(dom, table, padDoc, subject, me, options)
).toMatchInlineSnapshot(`
<table
style="margin: 0.8em;"
/>
`)
})
})
describe('participationObject', () => {
it('exists', () => {
expect((pad as any).participationObject).toBeInstanceOf(Function)
})
it('runs', () => {
// TODO: check on arguments
const subject = null
const padDoc = null
const me = null
expect((pad as any).participationObject(subject, padDoc, me)).resolves.toBe(
{}
)
})
it('runs 2', () => {
// TODO: check on arguments
const spy = jest.spyOn(widgets, 'newThing')
const subject = null
const padDoc = document
const me = 'https://sharonstrats.inrupt.net/profile/card#me'
expect((pad as any).participationObject(subject, padDoc, me)).resolves.toBe(
{}
)
expect(spy).toBeCalled()
})
})
describe('recordParticipation', () => {
it('exists', () => {
expect((pad as any).recordParticipation).toBeInstanceOf(Function)
})
const subject = null
const padDoc = null
const refreshable = true
it('runs', () => {
expect((pad as any).recordParticipation(subject, padDoc, refreshable)).toBe(
undefined
)
})
})
describe('manageParticipation', () => {
it('exists', () => {
expect((pad as any).manageParticipation).toBeInstanceOf(Function)
})
const container = dom.createElement('div')
const padDoc = null
const subject = null
const me = null
const options = {}
it('runs', () => {
expect(
(pad as any).manageParticipation(
dom,
container,
padDoc,
subject,
me,
options
)
).toMatchInlineSnapshot(`
<table
style="margin: 0.8em;"
/>
`)
})
})
describe('notepad', () => {
it('exists', () => {
expect((pad as any).notepad).toBeInstanceOf(Function)
})
it('runs', () => {
const padDoc = null
const subject = null
const me = RdfLib.sym('')
const options = {}
expect((pad as any).notepad(dom, padDoc, subject, me, options))
.toMatchInlineSnapshot(`
<table
style="padding: 1em; overflow: auto; resize: horizontal; min-width: 40em;"
/>
`)
})
it.skip('should log error that you need to be logged in for pad to be edited', () => {
const padDoc = null
const subject = null
const me = null
const options = {}
;(window as any).console = { log: jest.fn() }
expect((pad as any).notepad(dom, padDoc, subject, me, options))
.toMatchInlineSnapshot(`
<table
style="padding: 1em; overflow: auto; resize: horizontal; min-width: 40em;"
/>
`)
expect(console.log).toBeCalledWith(
'Warning: must be logged in for pad to be edited'
)
})
it.skip('status area ...', () => {
const padDoc = null
const subject = null
const me = { uri: 'https://sharonstrats.inrupt.net/profile/card#me' }
const options = { statusArea: document.createElement('p') }
expect(
(pad as any).notepad(dom, padDoc, subject, me, options)
).resolves.toMatchInlineSnapshot()
})
// @@ TODO the code itself seems to error where it says 'new'
// need to research further
it.skip('should throw an error when me is provided but no uri', () => {
const padDoc = null
const subject = null
const me = {}
const options = {}
expect(
(pad as any).notepad(dom, padDoc, subject, me, options)
).resolves.toBe({})
})
})