|
| 1 | +/* eslint-env jest */ |
| 2 | +import $rdf from 'rdflib' |
| 3 | +import vocab from 'solid-namespace' |
| 4 | +import { view } from './view' |
| 5 | + |
| 6 | +const ns = vocab($rdf) |
| 7 | + |
| 8 | +function addMockPad (mockStore: $rdf.IndexedFormula): $rdf.NamedNode { |
| 9 | + const mockPad = $rdf.sym('https://mock-pad') |
| 10 | + const mockFirstLine = $rdf.sym('https://arbitrary-line-1') |
| 11 | + mockStore.add(mockPad, ns.pad('next'), mockFirstLine, mockPad.doc()) |
| 12 | + mockStore.add(mockFirstLine, ns.sioc('content'), 'First line', mockPad.doc()) |
| 13 | + mockStore.add(mockFirstLine, ns.dc('created'), new Date(0), mockPad.doc()) |
| 14 | + const mockSecondLine = $rdf.sym('https://arbitrary-line-2') |
| 15 | + mockStore.add(mockFirstLine, ns.pad('next'), mockSecondLine, mockPad.doc()) |
| 16 | + mockStore.add(mockSecondLine, ns.sioc('content'), 'Second line', mockPad.doc()) |
| 17 | + mockStore.add(mockSecondLine, ns.dc('created'), new Date(0), mockPad.doc()) |
| 18 | + mockStore.add(mockSecondLine, ns.pad('next'), mockPad, mockPad.doc()) |
| 19 | + |
| 20 | + return mockPad |
| 21 | +} |
| 22 | + |
| 23 | +describe('View mode', () => { |
| 24 | + it('should not show an edit button when the user is not logged in', async () => { |
| 25 | + const mockStore = $rdf.graph() |
| 26 | + const mockPad = addMockPad(mockStore) |
| 27 | + |
| 28 | + const container = document.createElement('div') |
| 29 | + |
| 30 | + view({ |
| 31 | + container: container, |
| 32 | + subject: mockPad, |
| 33 | + store: mockStore |
| 34 | + }) |
| 35 | + const button = container.querySelector('button') |
| 36 | + expect(button).toBeNull() |
| 37 | + }) |
| 38 | + |
| 39 | + it('should show an edit button when the user is logged in', async () => { |
| 40 | + const mockStore = $rdf.graph() |
| 41 | + const mockPad = addMockPad(mockStore) |
| 42 | + const mockUser = $rdf.sym('https://mock-user') |
| 43 | + |
| 44 | + const container = document.createElement('div') |
| 45 | + |
| 46 | + view({ |
| 47 | + container: container, |
| 48 | + subject: mockPad, |
| 49 | + store: mockStore, |
| 50 | + user: mockUser |
| 51 | + }) |
| 52 | + const button = container.querySelector('button') |
| 53 | + expect(button).toBeDefined() |
| 54 | + expect(button!.textContent).toBe('Edit') |
| 55 | + }) |
| 56 | + |
| 57 | + it('should properly render the pad\'s contents', async () => { |
| 58 | + const mockStore = $rdf.graph() |
| 59 | + const mockPad = addMockPad(mockStore) |
| 60 | + |
| 61 | + const container = document.createElement('div') |
| 62 | + |
| 63 | + view({ |
| 64 | + container: container, |
| 65 | + subject: mockPad, |
| 66 | + store: mockStore |
| 67 | + }) |
| 68 | + expect(container.outerHTML).toMatchSnapshot() |
| 69 | + }) |
| 70 | +}) |
0 commit comments