|
1 | | -// SHARON IS WORKING ON THIS FILE |
2 | | -// NOT DOING ANYTHING FOR NOW AS SHE WILL CLEAN IT UP LATER |
| 1 | +import { JSDOM } from 'jsdom' |
| 2 | +import * as RdfLib from 'rdflib' |
| 3 | +import { lightColorHash, notepad } from '../../src/pad' |
| 4 | +import { log } from '../../src/debug' |
3 | 5 |
|
4 | | -it.skip('only here to make tests run', () => null) |
5 | | - |
6 | | -// |
7 | | -// import { JSDOM } from 'jsdom' |
8 | | -// import * as RdfLib from 'rdflib' |
9 | | -// import * as pad from '../../src/pad' |
10 | | -// const widgets = require('../../src/widgets') |
11 | | -// |
12 | 6 | // jest.mock('rdflib') |
13 | 7 | // jest.mock('solid-auth-client') |
14 | | -// const window = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window |
15 | | -// const dom = window.document |
16 | | -// |
17 | | -// describe('lightColorHash', () => { |
18 | | -// it('exists', () => { |
19 | | -// expect((pad as any).lightColorHash).toBeInstanceOf(Function) |
20 | | -// }) |
21 | | -// it('returns #ffffff when an author is not provided', () => { |
22 | | -// // #ffffff is specifically stated in the code to be returned |
23 | | -// // when there is no author |
24 | | -// expect((pad as any).lightColorHash(null)).toBe('#ffffff') |
25 | | -// }) |
26 | | -// it('returns a value when given an author', () => { |
27 | | -// // #dac2dc is the hash of 'https://sharonstrats.inrupt.net/profile/card#me' |
28 | | -// const author = { uri: 'https://sharonstrats.inrupt.net/profile/card#me' } |
29 | | -// expect((pad as any).lightColorHash(author)).toBe('#dac2dc') |
30 | | -// }) |
31 | | -// }) |
32 | | -// describe('renderPartipants', () => { |
33 | | -// it('exists', () => { |
34 | | -// expect((pad as any).renderPartipants).toBeInstanceOf(Function) |
35 | | -// }) |
36 | | -// it('runs', () => { |
37 | | -// const table = dom.createElement('table') |
38 | | -// const padDoc = null |
39 | | -// const subject = RdfLib.sym('') |
40 | | -// const me = 'webId' |
41 | | -// const options = {} |
42 | | -// expect( |
43 | | -// (pad as any).renderPartipants(dom, table, padDoc, subject, me, options) |
44 | | -// ).toMatchInlineSnapshot(` |
45 | | -// <table |
46 | | -// style="margin: 0.8em;" |
47 | | -// /> |
48 | | -// `) |
49 | | -// }) |
50 | | -// it('returns without crashing when a person is not returned', () => { |
51 | | -// // @@ TODO need to mock kb.any and kb.each - not working for some reason |
52 | | -// // kb is a store |
53 | | -// const table = dom.createElement('table') |
54 | | -// const padDoc = null |
55 | | -// const subject = RdfLib.sym('participation') |
56 | | -// const me = 'webId' |
57 | | -// const options = {} |
58 | | -// expect( |
59 | | -// (pad as any).renderPartipants(dom, table, padDoc, subject, me, options) |
60 | | -// ).toMatchInlineSnapshot(` |
61 | | -// <table |
62 | | -// style="margin: 0.8em;" |
63 | | -// /> |
64 | | -// `) |
65 | | -// }) |
66 | | -// }) |
67 | | -// describe('participationObject', () => { |
68 | | -// it('exists', () => { |
69 | | -// expect((pad as any).participationObject).toBeInstanceOf(Function) |
70 | | -// }) |
71 | | -// |
72 | | -// it('runs', () => { |
73 | | -// // TODO: check on arguments |
74 | | -// |
75 | | -// const subject = null |
76 | | -// const padDoc = null |
77 | | -// const me = null |
78 | | -// expect((pad as any).participationObject(subject, padDoc, me)).resolves.toBe( |
79 | | -// {} |
80 | | -// ) |
81 | | -// }) |
82 | | -// it('runs 2', () => { |
83 | | -// // TODO: check on arguments |
84 | | -// const spy = jest.spyOn(widgets, 'newThing') |
85 | | -// const subject = null |
86 | | -// const padDoc = document |
87 | | -// const me = 'https://sharonstrats.inrupt.net/profile/card#me' |
88 | | -// expect((pad as any).participationObject(subject, padDoc, me)).resolves.toBe( |
89 | | -// {} |
90 | | -// ) |
91 | | -// expect(spy).toBeCalled() |
92 | | -// }) |
93 | | -// }) |
94 | | -// describe('recordParticipation', () => { |
95 | | -// it('exists', () => { |
96 | | -// expect((pad as any).recordParticipation).toBeInstanceOf(Function) |
97 | | -// }) |
98 | | -// const subject = null |
99 | | -// const padDoc = null |
100 | | -// const refreshable = true |
101 | | -// it('runs', () => { |
102 | | -// expect((pad as any).recordParticipation(subject, padDoc, refreshable)).toBe( |
103 | | -// undefined |
104 | | -// ) |
105 | | -// }) |
106 | | -// }) |
107 | | -// describe('manageParticipation', () => { |
108 | | -// it('exists', () => { |
109 | | -// expect((pad as any).manageParticipation).toBeInstanceOf(Function) |
110 | | -// }) |
111 | | -// const container = dom.createElement('div') |
112 | | -// const padDoc = null |
113 | | -// const subject = null |
114 | | -// const me = null |
115 | | -// const options = {} |
116 | | -// it('runs', () => { |
117 | | -// expect( |
118 | | -// (pad as any).manageParticipation( |
119 | | -// dom, |
120 | | -// container, |
121 | | -// padDoc, |
122 | | -// subject, |
123 | | -// me, |
124 | | -// options |
125 | | -// ) |
126 | | -// ).toMatchInlineSnapshot(` |
127 | | -// <table |
128 | | -// style="margin: 0.8em;" |
129 | | -// /> |
130 | | -// `) |
131 | | -// }) |
132 | | -// }) |
133 | | -// describe('notepad', () => { |
134 | | -// it('exists', () => { |
135 | | -// expect((pad as any).notepad).toBeInstanceOf(Function) |
136 | | -// }) |
137 | | -// |
138 | | -// it('runs', () => { |
139 | | -// const padDoc = null |
140 | | -// const subject = null |
141 | | -// const me = RdfLib.sym('') |
142 | | -// const options = {} |
143 | | -// expect((pad as any).notepad(dom, padDoc, subject, me, options)) |
144 | | -// .toMatchInlineSnapshot(` |
145 | | -// <table |
146 | | -// style="padding: 1em; overflow: auto; resize: horizontal; min-width: 40em;" |
147 | | -// /> |
148 | | -// `) |
149 | | -// }) |
150 | | -// |
151 | | -// it.skip('should log error that you need to be logged in for pad to be edited', () => { |
152 | | -// const padDoc = null |
153 | | -// const subject = null |
154 | | -// const me = null |
155 | | -// const options = {} |
156 | | -// ;(window as any).console = { log: jest.fn() } |
157 | | -// expect((pad as any).notepad(dom, padDoc, subject, me, options)) |
158 | | -// .toMatchInlineSnapshot(` |
159 | | -// <table |
160 | | -// style="padding: 1em; overflow: auto; resize: horizontal; min-width: 40em;" |
161 | | -// /> |
162 | | -// `) |
163 | | -// expect(debug.log).toBeCalledWith( |
164 | | -// 'Warning: must be logged in for pad to be edited' |
165 | | -// ) |
166 | | -// }) |
167 | | -// |
168 | | -// it.skip('status area ...', () => { |
169 | | -// const padDoc = null |
170 | | -// const subject = null |
171 | | -// const me = { uri: 'https://sharonstrats.inrupt.net/profile/card#me' } |
172 | | -// const options = { statusArea: document.createElement('p') } |
173 | | -// |
174 | | -// expect( |
175 | | -// (pad as any).notepad(dom, padDoc, subject, me, options) |
176 | | -// ).resolves.toMatchInlineSnapshot() |
177 | | -// }) |
178 | | -// |
179 | | -// // @@ TODO the code itself seems to error where it says 'new' |
180 | | -// // need to research further |
181 | | -// |
182 | | -// it.skip('should throw an error when me is provided but no uri', () => { |
183 | | -// const padDoc = null |
184 | | -// const subject = null |
185 | | -// const me = {} |
186 | | -// const options = {} |
187 | | -// |
188 | | -// expect( |
189 | | -// (pad as any).notepad(dom, padDoc, subject, me, options) |
190 | | -// ).resolves.toBe({}) |
191 | | -// }) |
192 | | -// }) |
| 8 | +const window = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window |
| 9 | +const dom = window.document |
| 10 | + |
| 11 | +describe('lightColorHash', () => { |
| 12 | + it('to be exposed by the Public API', () => { |
| 13 | + expect(lightColorHash).toBe(lightColorHash) |
| 14 | + }) |
| 15 | + it('returns #ffffff when an author is not provided', () => { |
| 16 | + // #ffffff is specifically stated in the code to be returned |
| 17 | + // when there is no author |
| 18 | + expect(lightColorHash()).toBe('#ffffff') |
| 19 | + }) |
| 20 | + it('returns a value when given an author', () => { |
| 21 | + // #dac2dc is the hash of 'https://sharonstrats.inrupt.net/profile/card#me' |
| 22 | + const author = new RdfLib.NamedNode('https://sharonstrats.inrupt.net/profile/card#me') |
| 23 | + expect(lightColorHash(author)).toBe('#dac2dc') |
| 24 | + }) |
| 25 | +}) |
| 26 | + |
| 27 | +describe('notepad', () => { |
| 28 | + it('to be exposed by the Public API', () => { |
| 29 | + expect(notepad).toBe(notepad) |
| 30 | + }) |
| 31 | + |
| 32 | + it('runs', () => { |
| 33 | + const padDoc = new RdfLib.NamedNode('https://document#') |
| 34 | + const subject = new RdfLib.NamedNode('https://subject#') |
| 35 | + const me = new RdfLib.NamedNode('https://sharonstrats.inrupt.net/profile/card#me') |
| 36 | + const options = {} |
| 37 | + expect(notepad(dom, padDoc, subject, me, options)) |
| 38 | + .toMatchSnapshot() |
| 39 | + }) |
| 40 | + // Below isn't correct just getting rid of the error for a moment shouldn't provide a me... |
| 41 | + it.skip('should log error that you need to be logged in for pad to be edited', () => { |
| 42 | + const padDoc = new RdfLib.NamedNode('https://document#') |
| 43 | + const subject = new RdfLib.NamedNode('https://subject#') |
| 44 | + const me = new RdfLib.NamedNode('https://sharonstrats.inrupt.net/profile/card#me') |
| 45 | + const options = {} |
| 46 | + |
| 47 | + // use this instead jest.spyOn(window.console, 'log') Arne's PR Comments |
| 48 | + ; (window as any).console = { log: jest.fn() } |
| 49 | + expect(notepad(dom, padDoc, subject, me, options)) |
| 50 | + .toMatchSnapshot() |
| 51 | + expect(log).toBeCalledWith( |
| 52 | + 'Warning: must be logged in for pad to be edited' |
| 53 | + ) |
| 54 | + }) |
| 55 | + |
| 56 | + it('status area ...', () => { |
| 57 | + const padDoc = new RdfLib.NamedNode('https://document#') |
| 58 | + const subject = new RdfLib.NamedNode('https://subject#') |
| 59 | + const me = new RdfLib.NamedNode('https://sharonstrats.inrupt.net/profile/card#me') |
| 60 | + const options = { statusArea: dom.createElement('div') } |
| 61 | + |
| 62 | + expect(notepad(dom, padDoc, subject, me, options) |
| 63 | + ).toMatchSnapshot() |
| 64 | + }) |
| 65 | + |
| 66 | + // @@ TODO the code itself seems to error where it says 'new' |
| 67 | + // need to research further |
| 68 | + |
| 69 | + it.skip('should throw an error when me is provided but no uri', () => { |
| 70 | + const padDoc = new RdfLib.NamedNode('https://document#') |
| 71 | + const subject = new RdfLib.NamedNode('https://subject#') |
| 72 | + const me = new RdfLib.NamedNode('https://sharonstrats.inrupt.net/profile/card#me') |
| 73 | + const options = {} |
| 74 | + |
| 75 | + expect(notepad(dom, padDoc, subject, me, options) |
| 76 | + ).resolves.toBe({}) |
| 77 | + }) |
| 78 | +}) |
0 commit comments