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
78 lines (68 loc) · 2.95 KB
/
pad.test.ts
File metadata and controls
78 lines (68 loc) · 2.95 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
import { silenceDebugMessages } from './helpers/debugger'
import { JSDOM } from 'jsdom'
import * as RdfLib from 'rdflib'
import { lightColorHash, notepad } from '../../src/pad'
import { log } from '../../src/debug'
silenceDebugMessages()
const window = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window
const dom = window.document
describe('lightColorHash', () => {
it('to be exposed by the Public API', () => {
expect(lightColorHash).toBe(lightColorHash)
})
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(lightColorHash()).toBe('#ffffff')
})
it('returns a value when given an author', () => {
// #dac2dc is the hash of 'https://sharonstrats.inrupt.net/profile/card#me'
const author = new RdfLib.NamedNode('https://sharonstrats.inrupt.net/profile/card#me')
expect(lightColorHash(author)).toBe('#dac2dc')
})
})
describe('notepad', () => {
it('to be exposed by the Public API', () => {
expect(notepad).toBe(notepad)
})
it('runs', () => {
const padDoc = new RdfLib.NamedNode('https://document#')
const subject = new RdfLib.NamedNode('https://subject#')
const me = new RdfLib.NamedNode('https://sharonstrats.inrupt.net/profile/card#me')
const options = {}
expect(notepad(dom, padDoc, subject, me, options))
.toMatchSnapshot()
})
// Below isn't correct just getting rid of the error for a moment shouldn't provide a me...
it.skip('should log error that you need to be logged in for pad to be edited', () => {
const padDoc = new RdfLib.NamedNode('https://document#')
const subject = new RdfLib.NamedNode('https://subject#')
const me = new RdfLib.NamedNode('https://sharonstrats.inrupt.net/profile/card#me')
const options = {}
// use this instead jest.spyOn(window.console, 'log') Arne's PR Comments
; (window as any).console = { log: jest.fn() }
expect(notepad(dom, padDoc, subject, me, options))
.toMatchSnapshot()
expect(log).toBeCalledWith(
'Warning: must be logged in for pad to be edited'
)
})
it('status area ...', () => {
const padDoc = new RdfLib.NamedNode('https://document#')
const subject = new RdfLib.NamedNode('https://subject#')
const me = new RdfLib.NamedNode('https://sharonstrats.inrupt.net/profile/card#me')
const options = { statusArea: dom.createElement('div') }
expect(notepad(dom, padDoc, subject, me, options)
).toMatchSnapshot()
})
// @@ 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 = new RdfLib.NamedNode('https://document#')
const subject = new RdfLib.NamedNode('https://subject#')
const me = new RdfLib.NamedNode('https://sharonstrats.inrupt.net/profile/card#me')
const options = {}
expect(notepad(dom, padDoc, subject, me, options)
).resolves.toBe({})
})
})