forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.test.ts
More file actions
210 lines (180 loc) · 8.51 KB
/
Copy pathdata.test.ts
File metadata and controls
210 lines (180 loc) · 8.51 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* eslint-env jest */
import $rdf from 'rdflib'
import { getInitialisationStatements, getSetContentsStatements, getContents, isPad, getTitle, getLatestAuthor } from './data'
import vocab from 'solid-namespace'
const ns = vocab($rdf)
describe('getInitialisationStatements()', () => {
it('should properly initialise a new notepad', async () => {
const mockStore = $rdf.graph()
mockStore.namespaces = { pub: 'https://localhost:8443/public/' }
const [_pad, additions] = getInitialisationStatements(new Date(0), mockStore)
expect(additions).toMatchSnapshot()
})
it('should include author information if available', async () => {
const mockStore = $rdf.graph()
mockStore.namespaces = { pub: 'https://localhost:8443/public/' }
const [_pad, additions] = getInitialisationStatements(
new Date(0),
mockStore,
$rdf.sym('https://mock-user')
)
expect(additions).toMatchSnapshot()
})
})
describe('getSetContentsStatements()', () => {
it('should properly set a notepad\'s contents', async () => {
const mockStore = $rdf.graph()
const mockPad = $rdf.sym('https://mock-pad')
const mockContents = `
Here's some arbitrary
multiline
content
`
const [deletions, additions] = getSetContentsStatements(
mockContents,
new Date(0),
mockPad,
mockStore
)
expect(deletions).toEqual([])
expect(additions).toMatchSnapshot()
})
it('should include author information if available', async () => {
const mockStore = $rdf.graph()
const mockPad = $rdf.sym('https://mock-pad')
const mockContents = 'Arbitrary content'
const [deletions, additions] = getSetContentsStatements(
mockContents,
new Date(0),
mockPad,
mockStore,
$rdf.sym('https://mock-user')
)
expect(deletions).toEqual([])
expect(additions).toMatchSnapshot()
})
it('should clear previous content, if any', async () => {
const mockStore = $rdf.graph()
const mockPad = $rdf.sym('https://mock-pad')
const mockExistingLine = $rdf.sym('https://arbitrary-line')
mockStore.add(mockPad, ns.pad('next'), mockExistingLine, mockPad.doc())
mockStore.add(mockExistingLine, ns.pad('content'), 'Existing content', mockPad.doc())
mockStore.add(mockExistingLine, ns.dc('created'), new Date(0), mockPad.doc())
const mockContents = 'Arbitrary content'
const [deletions, _additions] = getSetContentsStatements(
mockContents,
new Date(0),
mockPad,
mockStore,
$rdf.sym('https://mock-user')
)
expect(deletions).toMatchSnapshot()
})
})
describe('getContents()', () => {
it('should be able to reconstruct a multiline file', async () => {
const mockStore = $rdf.graph()
const mockPad = $rdf.sym('https://mock-pad')
const mockFirstLine = $rdf.sym('https://arbitrary-line-1')
mockStore.add(mockPad, ns.pad('next'), mockFirstLine, mockPad.doc())
mockStore.add(mockFirstLine, ns.sioc('content'), 'First line', mockPad.doc())
mockStore.add(mockFirstLine, ns.dc('created'), new Date(0), mockPad.doc())
const mockSecondLine = $rdf.sym('https://arbitrary-line-2')
mockStore.add(mockFirstLine, ns.pad('next'), mockSecondLine, mockPad.doc())
mockStore.add(mockSecondLine, ns.sioc('content'), 'Second line', mockPad.doc())
mockStore.add(mockSecondLine, ns.dc('created'), new Date(0), mockPad.doc())
mockStore.add(mockSecondLine, ns.pad('next'), mockPad, mockPad.doc())
expect(getContents(mockStore, mockPad)).toBe(
// eslint-disable-next-line indent
`First line
Second line`
)
})
it('should ignore lines without contents', async () => {
const mockStore = $rdf.graph()
const mockPad = $rdf.sym('https://mock-pad')
const mockFirstLine = $rdf.sym('https://arbitrary-line-1')
mockStore.add(mockPad, ns.pad('next'), mockFirstLine, mockPad.doc())
mockStore.add(mockFirstLine, ns.sioc('content'), 'First line', mockPad.doc())
mockStore.add(mockFirstLine, ns.dc('created'), new Date(0), mockPad.doc())
const mockSecondLine = $rdf.sym('https://arbitrary-line-2')
mockStore.add(mockFirstLine, ns.pad('next'), mockSecondLine, mockPad.doc())
mockStore.add(mockSecondLine, ns.dc('created'), new Date(0), mockPad.doc())
mockStore.add(mockSecondLine, ns.pad('next'), mockPad, mockPad.doc())
expect(getContents(mockStore, mockPad)).toBe('First line')
})
})
describe('getLatestAuthor()', () => {
it('should be able to get the latest author', async () => {
const mockStore = $rdf.graph()
const mockPad = $rdf.sym('https://mock-pad')
const mockEarlyAuthor = $rdf.sym('https:/mock-early-author')
const mockLateAuthor = $rdf.sym('https:/mock-late-author')
const mockFirstLine = $rdf.sym('https://arbitrary-line-1')
mockStore.add(mockPad, ns.pad('next'), mockFirstLine, mockPad.doc())
mockStore.add(mockFirstLine, ns.sioc('content'), 'First line', mockPad.doc())
mockStore.add(mockFirstLine, ns.dc('created'), new Date(0), mockPad.doc())
mockStore.add(mockFirstLine, ns.dc('author'), mockEarlyAuthor, mockPad.doc())
const mockSecondLine = $rdf.sym('https://arbitrary-line-2')
mockStore.add(mockFirstLine, ns.pad('next'), mockSecondLine, mockPad.doc())
mockStore.add(mockSecondLine, ns.sioc('content'), 'Second line', mockPad.doc())
mockStore.add(mockSecondLine, ns.dc('created'), new Date(24 * 60 * 60 * 1000), mockPad.doc())
mockStore.add(mockSecondLine, ns.dc('author'), mockLateAuthor, mockPad.doc())
mockStore.add(mockSecondLine, ns.pad('next'), mockPad, mockPad.doc())
expect(getLatestAuthor(mockStore, mockPad)).toEqual(mockLateAuthor)
})
it('should return an author even when all lines were authored at the same time', async () => {
const mockStore = $rdf.graph()
const mockPad = $rdf.sym('https://mock-pad')
const mockEarlyAuthor = $rdf.sym('https:/mock-early-author')
const mockLateAuthor = $rdf.sym('https:/mock-late-author')
const mockFirstLine = $rdf.sym('https://arbitrary-line-1')
mockStore.add(mockPad, ns.pad('next'), mockFirstLine, mockPad.doc())
mockStore.add(mockFirstLine, ns.sioc('content'), 'First line', mockPad.doc())
mockStore.add(mockFirstLine, ns.dc('created'), new Date(0), mockPad.doc())
mockStore.add(mockFirstLine, ns.dc('author'), mockEarlyAuthor, mockPad.doc())
const mockSecondLine = $rdf.sym('https://arbitrary-line-2')
mockStore.add(mockFirstLine, ns.pad('next'), mockSecondLine, mockPad.doc())
mockStore.add(mockSecondLine, ns.sioc('content'), 'Second line', mockPad.doc())
mockStore.add(mockSecondLine, ns.dc('created'), new Date(0), mockPad.doc())
mockStore.add(mockSecondLine, ns.dc('author'), mockLateAuthor, mockPad.doc())
mockStore.add(mockSecondLine, ns.pad('next'), mockPad, mockPad.doc())
expect(getLatestAuthor(mockStore, mockPad)).not.toBeNull()
})
it('should return null if no author data is present', async () => {
const mockStore = $rdf.graph()
const mockPad = $rdf.sym('https://mock-pad')
const mockFirstLine = $rdf.sym('https://arbitrary-line-1')
mockStore.add(mockPad, ns.pad('next'), mockFirstLine, mockPad.doc())
mockStore.add(mockFirstLine, ns.sioc('content'), 'First line', mockPad.doc())
mockStore.add(mockFirstLine, ns.dc('created'), new Date(0), mockPad.doc())
const mockSecondLine = $rdf.sym('https://arbitrary-line-2')
mockStore.add(mockFirstLine, ns.pad('next'), mockSecondLine, mockPad.doc())
mockStore.add(mockSecondLine, ns.sioc('content'), 'Second line', mockPad.doc())
mockStore.add(mockSecondLine, ns.dc('created'), new Date(0), mockPad.doc())
mockStore.add(mockSecondLine, ns.pad('next'), mockPad, mockPad.doc())
expect(getLatestAuthor(mockStore, mockPad)).toBeNull()
})
})
describe('getTitle()', () => {
it('should return a document\'s title', async () => {
const mockStore = $rdf.graph()
const mockPad = $rdf.sym('https://mock-pad')
mockStore.add(mockPad, ns.dc('title'), 'Some title', mockPad.doc())
expect(getTitle(mockStore, mockPad)).toBe('Some title')
})
})
describe('isPad()', () => {
it('should recognise when a subject is not a Pad', async () => {
const mockStore = $rdf.graph()
const mockNotAPad = $rdf.sym('https://mock-chat')
mockStore.add(mockNotAPad, ns.rdf('type'), ns.meeting('Chat'), mockNotAPad.doc())
expect(isPad(mockNotAPad, mockStore)).toBe(false)
})
it('should recognise when a subject is a Pad', async () => {
const mockStore = $rdf.graph()
const mockPad = $rdf.sym('https://mock-pad')
mockStore.add(mockPad, ns.rdf('type'), ns.pad('Notepad'), mockPad.doc())
expect(isPad(mockPad, mockStore)).toBe(true)
})
})