Skip to content

Commit 46478b9

Browse files
Vinnlunknown
authored andcommitted
Pass test coverage threshold for scratchpad
1 parent dd1242e commit 46478b9

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

scratchpad/data.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ describe('getContents()', () => {
101101
Second line`
102102
)
103103
})
104+
105+
it('should ignore lines without contents', async () => {
106+
const mockStore = $rdf.graph()
107+
const mockPad = $rdf.sym('https://mock-pad')
108+
109+
const mockFirstLine = $rdf.sym('https://arbitrary-line-1')
110+
mockStore.add(mockPad, ns.pad('next'), mockFirstLine, mockPad.doc())
111+
mockStore.add(mockFirstLine, ns.sioc('content'), 'First line', mockPad.doc())
112+
mockStore.add(mockFirstLine, ns.dc('created'), new Date(0), mockPad.doc())
113+
const mockSecondLine = $rdf.sym('https://arbitrary-line-2')
114+
mockStore.add(mockFirstLine, ns.pad('next'), mockSecondLine, mockPad.doc())
115+
mockStore.add(mockSecondLine, ns.dc('created'), new Date(0), mockPad.doc())
116+
mockStore.add(mockSecondLine, ns.pad('next'), mockPad, mockPad.doc())
117+
118+
expect(getContents(mockStore, mockPad)).toBe('First line')
119+
})
104120
})
105121

106122
describe('getTitle()', () => {

scratchpad/data.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { InitialisationFunction } from './types'
55

66
const ns = vocab($rdf)
77

8+
/* istanbul ignore next [Side effects are contained to initialise(), so ignore just that for test coverage] */
89
export const initialise: InitialisationFunction = async (store, user) => {
910
const creationDate = new Date()
1011
const [pad, initialisationAdditions] = getInitialisationStatements(creationDate, store, user)

scratchpad/view.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,25 @@ describe('View mode', () => {
6868
expect(container.outerHTML).toMatchSnapshot()
6969
})
7070
})
71+
72+
describe('Edit mode', () => {
73+
it('should switch to edit mode when clicking the edit button', async () => {
74+
const mockStore = $rdf.graph()
75+
const mockPad = addMockPad(mockStore)
76+
const mockUser = $rdf.sym('https://mock-user')
77+
78+
const container = document.createElement('div')
79+
80+
view({
81+
container: container,
82+
subject: mockPad,
83+
store: mockStore,
84+
user: mockUser
85+
})
86+
const button = container.querySelector('button')
87+
button!.dispatchEvent(new Event('click'))
88+
89+
const textarea = container.querySelector('textarea')
90+
expect(textarea).toBeDefined()
91+
})
92+
})

scratchpad/view.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function view ({ container, subject, store, user }: ViewParams) {
2626
}
2727

2828
function toEditMode () {
29+
/* istanbul ignore if [This should not be able to happen, but since the view is not stateless, we cannot verify this in unit tests.] */
2930
if (!user) {
3031
return
3132
}
@@ -37,6 +38,7 @@ export function view ({ container, subject, store, user }: ViewParams) {
3738
textArea.textContent = content
3839

3940
const form = container.getElementsByTagName('form')[0]
41+
/* istanbul ignore next [Side effects get executed here, so do not run them in unit tests:] */
4042
form.addEventListener('submit', (event) => {
4143
event.preventDefault()
4244

0 commit comments

Comments
 (0)