11import { JSDOM } from 'jsdom'
22import * as RdfLib from 'rdflib'
3-
43import * as pad from '../../src/pad'
4+ const widgets = require ( '../../src/widgets' )
5+ const store = require ( '../../src/store' )
56
67jest . mock ( 'rdflib' )
78jest . mock ( 'solid-auth-client' )
89const window = new JSDOM ( '<!DOCTYPE html><p>Hello world</p>' ) . window
910const dom = window . document
10- const element = dom . createElement ( 'div' )
1111
1212describe ( 'lightColorHash' , ( ) => {
1313 it ( 'exists' , ( ) => {
1414 expect ( ( pad as any ) . lightColorHash ) . toBeInstanceOf ( Function )
1515 } )
16- it ( 'runs ' , ( ) => {
16+ it ( 'returns #ffffff when an author is not provided ' , ( ) => {
1717 expect ( ( pad as any ) . lightColorHash ( null ) ) . toBe ( '#ffffff' )
1818 } )
19+ it ( 'returns a value when given an author' , ( ) => {
20+ const author = { uri : 'https://sharonstrats.inrupt.net/profile/card#me' }
21+ expect ( ( pad as any ) . lightColorHash ( author ) ) . toBe ( '#dac2dc' )
22+ } )
1923} )
2024describe ( 'renderPartipants' , ( ) => {
2125 it ( 'exists' , ( ) => {
2226 expect ( ( pad as any ) . renderPartipants ) . toBeInstanceOf ( Function )
2327 } )
2428 it ( 'runs' , ( ) => {
25- const table = dom . createElement ( )
29+ const table = dom . createElement ( 'table' )
2630 const padDoc = null
2731 const subject = RdfLib . sym ( '' )
2832 const me = 'webId'
2933 const options = { }
3034 expect (
3135 ( pad as any ) . renderPartipants ( dom , table , padDoc , subject , me , options )
32- ) . toBeTruthy ( )
36+ ) . toMatchInlineSnapshot ( `
37+ <table
38+ style="margin: 0.8em;"
39+ />
40+ ` )
41+ } )
42+ it ( 'returns without crashing when a person is not returned' , ( ) => {
43+ // @@ TODO need to mock kb.any and kb.each - not working for some reason
44+ // kb is a store
45+ const table = dom . createElement ( 'table' )
46+ const padDoc = null
47+ debugger
48+ const subject = RdfLib . sym ( 'participation' )
49+ const me = 'webId'
50+ const options = { }
51+ expect (
52+ ( pad as any ) . renderPartipants ( dom , table , padDoc , subject , me , options )
53+ ) . toMatchInlineSnapshot ( `
54+ <table
55+ style="margin: 0.8em;"
56+ />
57+ ` )
3358 } )
3459} )
3560describe ( 'participationObject' , ( ) => {
3661 it ( 'exists' , ( ) => {
3762 expect ( ( pad as any ) . participationObject ) . toBeInstanceOf ( Function )
3863 } )
39- // TODO: check on arguments
40- const subject = null
41- const padDoc = null
42- const me = null
64+
4365 it ( 'runs' , ( ) => {
44- expect ( ( pad as any ) . participationObject ( subject , padDoc , me ) ) . resolves . toBe ( { } )
66+ // TODO: check on arguments
67+
68+ const subject = null
69+ const padDoc = null
70+ const me = null
71+ expect ( ( pad as any ) . participationObject ( subject , padDoc , me ) ) . resolves . toBe (
72+ { }
73+ )
74+ } )
75+ it ( 'runs 2' , ( ) => {
76+ // TODO: check on arguments
77+ const spy = jest . spyOn ( widgets , 'newThing' )
78+ const subject = null
79+ const padDoc = document
80+ const me = 'https://sharonstrats.inrupt.net/profile/card#me'
81+ expect ( ( pad as any ) . participationObject ( subject , padDoc , me ) ) . resolves . toBe (
82+ { }
83+ )
84+ expect ( spy ) . toBeCalled ( )
4585 } )
4686} )
4787describe ( 'recordParticipation' , ( ) => {
@@ -61,15 +101,26 @@ describe('manageParticipation', () => {
61101 it ( 'exists' , ( ) => {
62102 expect ( ( pad as any ) . manageParticipation ) . toBeInstanceOf ( Function )
63103 } )
64- const container = dom . createElement ( )
104+ const container = dom . createElement ( 'div' )
65105 const padDoc = null
66106 const subject = null
67107 const me = null
68108 const options = { }
69109 it ( 'runs' , ( ) => {
70110 expect (
71- ( pad as any ) . manageParticipation ( dom , container , padDoc , subject , me , options )
72- ) . toBeTruthy ( )
111+ ( pad as any ) . manageParticipation (
112+ dom ,
113+ container ,
114+ padDoc ,
115+ subject ,
116+ me ,
117+ options
118+ )
119+ ) . toMatchInlineSnapshot ( `
120+ <table
121+ style="margin: 0.8em;"
122+ />
123+ ` )
73124 } )
74125} )
75126describe ( 'notepad' , ( ) => {
@@ -82,7 +133,12 @@ describe('notepad', () => {
82133 const subject = null
83134 const me = RdfLib . sym ( '' )
84135 const options = { }
85- expect ( ( pad as any ) . notepad ( dom , padDoc , subject , me , options ) ) . toBe ( element )
136+ expect ( ( pad as any ) . notepad ( dom , padDoc , subject , me , options ) )
137+ . toMatchInlineSnapshot ( `
138+ <table
139+ style="padding: 1em; overflow: auto; resize: horizontal; min-width: 40em;"
140+ />
141+ ` )
86142 } )
87143
88144 it ( 'should log error that you need to be logged in for pad to be edited' , ( ) => {
@@ -91,7 +147,26 @@ describe('notepad', () => {
91147 const me = null
92148 const options = { }
93149 ; ( window as any ) . console = { log : jest . fn ( ) }
94- expect ( ( pad as any ) . notepad ( dom , padDoc , subject , me , options ) ) . toBe ( element )
95- expect ( console . log ) . toBeCalledWith ( 'Warning: must be logged in for pad to be edited' )
150+ expect ( ( pad as any ) . notepad ( dom , padDoc , subject , me , options ) )
151+ . toMatchInlineSnapshot ( `
152+ <table
153+ style="padding: 1em; overflow: auto; resize: horizontal; min-width: 40em;"
154+ />
155+ ` )
156+ expect ( console . log ) . toBeCalledWith (
157+ 'Warning: must be logged in for pad to be edited'
158+ )
159+ } )
160+ // @@ TODO the code itself seems to error where it says 'new'
161+ // need to research further
162+ it ( 'should throw an error when me is provided but no uri' , ( ) => {
163+ const padDoc = null
164+ const subject = null
165+ const me = { }
166+ const options = { }
167+
168+ expect (
169+ ( pad as any ) . notepad ( dom , padDoc , subject , me , options )
170+ ) . resolves . toBe ( { } )
96171 } )
97172} )
0 commit comments