forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.test.ts
More file actions
96 lines (80 loc) · 2.87 KB
/
view.test.ts
File metadata and controls
96 lines (80 loc) · 2.87 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
/* eslint-env jest */
import $rdf from 'rdflib'
import vocab from 'solid-namespace'
import { view } from './view'
const ns = vocab($rdf)
function addMockPad (mockStore: $rdf.IndexedFormula): $rdf.NamedNode {
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())
return mockPad
}
describe('View mode', () => {
it('should not show an edit button when the user is not logged in', async () => {
const mockStore = $rdf.graph()
const mockPad = addMockPad(mockStore)
const container = document.createElement('div')
view({
container: container,
subject: mockPad,
store: mockStore,
visitNode: jest.fn()
})
const button = container.querySelector('button')
expect(button).toBeNull()
})
it('should show an edit button when the user is logged in', async () => {
const mockStore = $rdf.graph()
const mockPad = addMockPad(mockStore)
const mockUser = $rdf.sym('https://mock-user')
const container = document.createElement('div')
view({
container: container,
subject: mockPad,
store: mockStore,
user: mockUser,
visitNode: jest.fn()
})
const button = container.querySelector('button')
expect(button).toBeDefined()
expect(button!.textContent).toBe('Edit')
})
it('should properly render the pad\'s contents', async () => {
const mockStore = $rdf.graph()
const mockPad = addMockPad(mockStore)
const container = document.createElement('div')
view({
container: container,
subject: mockPad,
store: mockStore,
visitNode: jest.fn()
})
expect(container.outerHTML).toMatchSnapshot()
})
})
describe('Edit mode', () => {
it('should switch to edit mode when clicking the edit button', async () => {
const mockStore = $rdf.graph()
const mockPad = addMockPad(mockStore)
const mockUser = $rdf.sym('https://mock-user')
const container = document.createElement('div')
view({
container: container,
subject: mockPad,
store: mockStore,
visitNode: jest.fn(),
user: mockUser
})
const button = container.querySelector('button')
button!.dispatchEvent(new Event('click'))
const textarea = container.querySelector('textarea')
expect(textarea).toBeDefined()
})
})