|
| 1 | +import { namedNode } from 'rdflib' |
| 2 | +import ns from '../../../../src/ns' |
| 3 | +import uiStore from '../../../../src/store' |
| 4 | + |
| 5 | +import { |
| 6 | + commentField |
| 7 | +} from '../../../../src/widgets/forms/comment' |
| 8 | +import { clearStore } from '../../helpers/clearStore' |
| 9 | + |
| 10 | +afterEach(clearStore) |
| 11 | + |
| 12 | +describe('Comment', () => { |
| 13 | + |
| 14 | + it('exists', () => { |
| 15 | + expect(commentField).toBeInstanceOf(Object) |
| 16 | + }) |
| 17 | + it('runs', () => { |
| 18 | + const container = document.createElement('div') |
| 19 | + const already = {} |
| 20 | + const subject = namedNode('http://example.com/#this') |
| 21 | + const form = namedNode('http://example.com/#form') |
| 22 | + const store = namedNode('http://example.com/#store') |
| 23 | + const callbackFunction = jest.fn() // TODO: https://github.com/solid/solid-ui/issues/263 |
| 24 | + uiStore.add(form, ns.rdf('type'), ns.ui('Comment'), namedNode('http://example.com/')) |
| 25 | + uiStore.add(form, ns.ui('contents'), namedNode('http://example.com/#bla'), namedNode('http://example.com/')) |
| 26 | + expect( |
| 27 | + commentField( |
| 28 | + document, |
| 29 | + container, |
| 30 | + already, |
| 31 | + subject, |
| 32 | + form, |
| 33 | + store, |
| 34 | + callbackFunction |
| 35 | + ) |
| 36 | + ).toMatchSnapshot() |
| 37 | + }) |
| 38 | + it('deals with missing content', () => { |
| 39 | + const container = document.createElement('div') |
| 40 | + const already = {} |
| 41 | + const subject = namedNode('http://example.com/#this') |
| 42 | + const form = namedNode('http://example.com/#form') |
| 43 | + const store = namedNode('http://example.com/#store') |
| 44 | + const callbackFunction = jest.fn() // TODO: https://github.com/solid/solid-ui/issues/263 |
| 45 | + uiStore.add(form, ns.rdf('type'), ns.ui('Comment'), namedNode('http://example.com/')) |
| 46 | + expect( |
| 47 | + commentField( |
| 48 | + document, |
| 49 | + container, |
| 50 | + already, |
| 51 | + subject, |
| 52 | + form, |
| 53 | + store, |
| 54 | + callbackFunction |
| 55 | + ) |
| 56 | + ).toMatchSnapshot() |
| 57 | + }) |
| 58 | + it('deals with missing field params in non-bottom field type', () => { |
| 59 | + const container = document.createElement('div') |
| 60 | + const already = {} |
| 61 | + const subject = namedNode('http://example.com/#this') |
| 62 | + const form = namedNode('http://example.com/#form') |
| 63 | + const store = namedNode('http://example.com/#store') |
| 64 | + const callbackFunction = jest.fn() // TODO: https://github.com/solid/solid-ui/issues/263 |
| 65 | + uiStore.add(form, ns.rdf('type'), namedNode('http://example.com/#custom2'), namedNode('http://example.com/')) |
| 66 | + uiStore.add(namedNode('http://example.com/#custom2'), ns.rdfs('subClassOf'), namedNode('http://example.com/#custom1'), namedNode('http://example.com/')) |
| 67 | + uiStore.add(form, ns.ui('contents'), namedNode('http://example.com/#bla'), namedNode('http://example.com/')) |
| 68 | + |
| 69 | + expect( |
| 70 | + commentField( |
| 71 | + document, |
| 72 | + container, |
| 73 | + already, |
| 74 | + subject, |
| 75 | + form, |
| 76 | + store, |
| 77 | + callbackFunction |
| 78 | + ) |
| 79 | + ).toMatchSnapshot() |
| 80 | + }) |
| 81 | + it('deals with missing container', () => { |
| 82 | + const already = {} |
| 83 | + const subject = namedNode('http://example.com/#this') |
| 84 | + const form = namedNode('http://example.com/#form') |
| 85 | + const store = namedNode('http://example.com/#store') |
| 86 | + const callbackFunction = jest.fn() // TODO: https://github.com/solid/solid-ui/issues/263 |
| 87 | + uiStore.add(form, ns.rdf('type'), ns.ui('Comment'), namedNode('http://example.com/')) |
| 88 | + uiStore.add(form, ns.ui('contents'), namedNode('http://example.com/#bla'), namedNode('http://example.com/')) |
| 89 | + expect( |
| 90 | + commentField( |
| 91 | + document, |
| 92 | + undefined, |
| 93 | + already, |
| 94 | + subject, |
| 95 | + form, |
| 96 | + store, |
| 97 | + callbackFunction |
| 98 | + ) |
| 99 | + ).toMatchSnapshot() |
| 100 | + }) |
| 101 | + it('deals with custom style', () => { |
| 102 | + const already = {} |
| 103 | + const subject = namedNode('http://example.com/#this') |
| 104 | + const form = namedNode('http://example.com/#form') |
| 105 | + const store = namedNode('http://example.com/#store') |
| 106 | + const callbackFunction = jest.fn() // TODO: https://github.com/solid/solid-ui/issues/263 |
| 107 | + uiStore.add(form, ns.rdf('type'), ns.ui('Comment'), namedNode('http://example.com/')) |
| 108 | + uiStore.add(form, ns.ui('style'), 'custom: true;', namedNode('http://example.com/')) |
| 109 | + uiStore.add(form, ns.ui('contents'), namedNode('http://example.com/#bla'), namedNode('http://example.com/')) |
| 110 | + expect( |
| 111 | + commentField( |
| 112 | + document, |
| 113 | + undefined, |
| 114 | + already, |
| 115 | + subject, |
| 116 | + form, |
| 117 | + store, |
| 118 | + callbackFunction |
| 119 | + ) |
| 120 | + ).toMatchSnapshot() |
| 121 | + }) |
| 122 | +}) |
| 123 | + |
0 commit comments