forked from SolidOS/solid-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfieldFunction.test.ts
More file actions
100 lines (90 loc) · 4.04 KB
/
Copy pathfieldFunction.test.ts
File metadata and controls
100 lines (90 loc) · 4.04 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
import { silenceDebugMessages } from '../../helpers/debugger'
// console.log('@@ solidLogicSingleton', solidLogicSingleton)
// @ts-ignore
import {
mostSpecificClassURI
} from '../../../../src/widgets/forms'
import { // trying to import this way lead to bizarre chaos
// field,
// fieldFunction,
// mostSpecificClassURI
} from '../../../../src/widgets/forms/fieldFunction' // '../../../../src/widgets/forms/fieldFunction'
import { clearStore } from '../../helpers/clearStore'
silenceDebugMessages()
afterEach(clearStore)
describe('mostSpecificClassURI', () => {
it('exists', () => {
expect(mostSpecificClassURI).toBeInstanceOf(Function)
})
/*
it('reports the RDF type if there is only one', () => {
const form = namedNode('http://example.com/#form')
solidLogicSingleton.store.add(form, ns.rdf('type'), namedNode('http://example.com/#type'), namedNode('http://example.com/'))
expect(mostSpecificClassURI(form)).toEqual('http://example.com/#type')
})
it('reports the subtype if there are one super and one sub type', () => {
const node = namedNode('http://example.com/#form')
solidLogicSingleton.store.add(node, ns.rdf('type'), namedNode('http://example.com/#human'), namedNode('http://example.com/'))
solidLogicSingleton.store.add(node, ns.rdf('type'), namedNode('http://example.com/#employee'), namedNode('http://example.com/'))
solidLogicSingleton.store.add(namedNode('http://example.com/#employee'), ns.rdfs('subClassOf'), namedNode('http://example.com/#human'), namedNode('http://example.com/'))
expect(mostSpecificClassURI(node)).toEqual('http://example.com/#employee')
})
})
describe('fieldFunction', () => {
it('exists', () => {
expect(fieldFunction).toBeInstanceOf(Object)
})
it('returns the field function if it exists', () => {
// create a function for type http://example.com/#type
const myFunction = () => document.createElement('div')
field['http://example.com/#type'] = myFunction
// create a field of type http://example.com/#type
const form = namedNode('http://example.com/#form')
solidLogicSingleton.store.add(form, ns.rdf('type'), namedNode('http://example.com/#type'), namedNode('http://example.com/'))
expect(fieldFunction(undefined, form)).toEqual(myFunction)
})
describe('function returned if subject type undefined', () => {
const fn = fieldFunction(undefined, namedNode('http://example.com/#doesnt-exist'))
it('returns an error block', () => {
const result = fn(document, document.createElement('div'), {},
namedNode('http://example.com/#subject'),
namedNode('http://example.com/#form'),
namedNode('http://example.com/'),
() => {})
expect(result).toMatchSnapshot()
})
it('appends an error block to a container', () => {
const container = document.createElement('div')
fn(document, container, {},
namedNode('http://example.com/#subject'),
namedNode('http://example.com/#form'),
namedNode('http://example.com/'),
() => {})
expect(container).toMatchSnapshot()
})
})
describe('function returned if no matching function exists', () => {
// create a field of type http://example.com/#unknown-type
const form = namedNode('http://example.com/#form')
solidLogicSingleton.store.add(form, ns.rdf('type'), namedNode('http://example.com/#unknown-type'), namedNode('http://example.com/'))
const fn = fieldFunction(undefined, form)
it('returns an error block', () => {
const result = fn(document, undefined, {},
namedNode('http://example.com/#subject'),
namedNode('http://example.com/#form'),
namedNode('http://example.com/'),
() => {})
expect(result).toMatchSnapshot()
})
it('appends an error block to a container', () => {
const container = document.createElement('div')
fn(document, container, {},
namedNode('http://example.com/#subject'),
namedNode('http://example.com/#form'),
namedNode('http://example.com/'),
() => {})
expect(container).toMatchSnapshot()
})
})
*/
})