Added tests to pad.test.ts and fixed a few others
MODIFY
test/unit/pad.test.ts
test/unit/pad.test.ts
import { JSDOM } from 'jsdom'
import * as RdfLib from 'rdflib'
-
import * as pad from '../../src/pad'
+const widgets = require('../../src/widgets')
+const store = require('../../src/store')
jest.mock('rdflib')
jest.mock('solid-auth-client')
const window = new JSDOM('<!DOCTYPE html><p>Hello world</p>').window
const dom = window.document
-const element = dom.createElement('div')
describe('lightColorHash', () => {
it('exists', () => {
expect((pad as any).lightColorHash).toBeInstanceOf(Function)
})
- it('runs', () => {
+ it('returns #ffffff when an author is not provided', () => {
expect((pad as any).lightColorHash(null)).toBe('#ffffff')
})
+ it('returns a value when given an author', () => {
+ const author = { uri: 'https://sharonstrats.inrupt.net/profile/card#me' }
+ expect((pad as any).lightColorHash(author)).toBe('#dac2dc')
+ })
})
describe('renderPartipants', () => {
it('exists', () => {
expect((pad as any).renderPartipants).toBeInstanceOf(Function)
})
it('runs', () => {
- const table = dom.createElement()
+ const table = dom.createElement('table')
const padDoc = null
const subject = RdfLib.sym('')
const me = 'webId'
const options = {}
expect(
(pad as any).renderPartipants(dom, table, padDoc, subject, me, options)
- ).toBeTruthy()
+ ).toMatchInlineSnapshot(`
+ <table
+ style="margin: 0.8em;"
+ />
+ `)
+ })
+ it('returns without crashing when a person is not returned', () => {
+ // @@ TODO need to mock kb.any and kb.each - not working for some reason
+ // kb is a store
+ const table = dom.createElement('table')
+ const padDoc = null
+ debugger
+ const subject = RdfLib.sym('participation')
+ const me = 'webId'
+ const options = {}
+ expect(
+ (pad as any).renderPartipants(dom, table, padDoc, subject, me, options)
+ ).toMatchInlineSnapshot(`
+<table
+ style="margin: 0.8em;"
+/>
+`)
})
})
describe('participationObject', () => {
it('exists', () => {
expect((pad as any).participationObject).toBeInstanceOf(Function)
})
+
+ it('runs', () => {
// TODO: check on arguments
+
const subject = null
const padDoc = null
const me = null
- it('runs', () => {
- expect((pad as any).participationObject(subject, padDoc, me)).resolves.toBe({})
+ expect((pad as any).participationObject(subject, padDoc, me)).resolves.toBe(
+ {}
+ )
+ })
+ it('runs 2', () => {
+ // TODO: check on arguments
+ const spy = jest.spyOn(widgets, 'newThing')
+ const subject = null
+ const padDoc = document
+ const me = 'https://sharonstrats.inrupt.net/profile/card#me'
+ expect((pad as any).participationObject(subject, padDoc, me)).resolves.toBe(
+ {}
+ )
+ expect(spy).toBeCalled()
})
})
describe('recordParticipation', () => {
@@ -61,15 +101,26 @@ describe('manageParticipation', () => {
it('exists', () => {
expect((pad as any).manageParticipation).toBeInstanceOf(Function)
})
- const container = dom.createElement()
+ const container = dom.createElement('div')
const padDoc = null
const subject = null
const me = null
const options = {}
it('runs', () => {
expect(
- (pad as any).manageParticipation(dom, container, padDoc, subject, me, options)
- ).toBeTruthy()
+ (pad as any).manageParticipation(
+ dom,
+ container,
+ padDoc,
+ subject,
+ me,
+ options
+ )
+ ).toMatchInlineSnapshot(`
+ <table
+ style="margin: 0.8em;"
+ />
+ `)
})
})
describe('notepad', () => {
@@ -82,7 +133,12 @@ describe('notepad', () => {
const subject = null
const me = RdfLib.sym('')
const options = {}
- expect((pad as any).notepad(dom, padDoc, subject, me, options)).toBe(element)
+ expect((pad as any).notepad(dom, padDoc, subject, me, options))
+ .toMatchInlineSnapshot(`
+ <table
+ style="padding: 1em; overflow: auto; resize: horizontal; min-width: 40em;"
+ />
+ `)
})
it('should log error that you need to be logged in for pad to be edited', () => {
@@ -91,7 +147,26 @@ describe('notepad', () => {
const me = null
const options = {}
;(window as any).console = { log: jest.fn() }
- expect((pad as any).notepad(dom, padDoc, subject, me, options)).toBe(element)
- expect(console.log).toBeCalledWith('Warning: must be logged in for pad to be edited')
+ expect((pad as any).notepad(dom, padDoc, subject, me, options))
+ .toMatchInlineSnapshot(`
+ <table
+ style="padding: 1em; overflow: auto; resize: horizontal; min-width: 40em;"
+ />
+ `)
+ expect(console.log).toBeCalledWith(
+ 'Warning: must be logged in for pad to be edited'
+ )
+ })
+ // @@ TODO the code itself seems to error where it says 'new'
+ // need to research further
+ it('should throw an error when me is provided but no uri', () => {
+ const padDoc = null
+ const subject = null
+ const me = {}
+ const options = {}
+
+ expect(
+ (pad as any).notepad(dom, padDoc, subject, me, options)
+ ).resolves.toBe({})
})
})

Added tests to pad.test.ts and fixed a few others