Skip to content

Commit 891c0fb

Browse files
branch coverage except in 4 places
1 parent 0928c17 commit 891c0fb

4 files changed

Lines changed: 687 additions & 12 deletions

File tree

__mocks__/rdflib.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,23 @@ export class Fetcher {
7171

7272
export class UpdateManager {
7373
// mock as needed
74+
updated: boolean = false
75+
reportSuccess: boolean = true
7476

7577
editable (uri: string) {
76-
if (uri === 'http://example.com/') {
77-
return true
78-
}
7978
if (uri === 'http://not.editable/') {
8079
return false
8180
}
82-
console.error('please use only http://editable.com/ and http://not.editable/ as docs in test')
8381
return true
8482
}
8583

8684
put () {
8785
return Promise.resolve()
8886
}
8987

90-
update () {
88+
update (_deletes, _inserts, onDone: (uri: string, ok: boolean, body: string) => void) {
89+
this.updated = true
90+
onDone('uri', this.reportSuccess, 'body')
9191
return Promise.resolve()
9292
}
9393
}

src/widgets/forms/basic.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export function fieldLabel (dom: HTMLDocument, property: NamedNode | undefined,
2424
return dom.createTextNode('@@Internal error: undefined property')
2525
}
2626
const anchor = dom.createElement('a')
27+
/* istanbul ignore next */
2728
if (property.uri) anchor.setAttribute('href', property.uri)
2829
anchor.setAttribute('style', 'color: #3B5998; text-decoration: none;') // Not too blue and no underline
2930
anchor.textContent = lab
@@ -103,7 +104,7 @@ export function basicField (
103104
const uri = mostSpecificClassURI(form)
104105
let params = fieldParams[uri]
105106
if (params === undefined) params = {} // non-bottom field types can do this
106-
const style = params.style || textInputStyle || 'font-size: 100%; margin: 0.1em; padding: 0.1em;'
107+
const style = params.style || textInputStyle
107108
// box.appendChild(dom.createTextNode(' uri='+uri+', pattern='+ params.pattern))
108109
const field = dom.createElement('input')
109110
;(field as any).style = textInputStyle // Do we have to override length etc?
@@ -129,6 +130,7 @@ export function basicField (
129130
field.value = decodeURIComponent(obj.uri.replace(params.uriPrefix, '')) // should have no spaces but in case
130131
.replace(/ /g, '')
131132
} else if (obj) {
133+
/* istanbul ignore next */
132134
field.value = obj.value || obj.uri || ''
133135
}
134136
field.setAttribute('style', style)
@@ -178,7 +180,7 @@ export function basicField (
178180
result = new Literal(field.value)
179181
}
180182
}
181-
let is = ds.map(st => st(st.subject, st.predicate, result, st.why)) // can include >1 doc
183+
let is = ds.map(statement => st(statement.subject, statement.predicate, result, statement.why)) // can include >1 doc
182184
if (is.length === 0) {
183185
// or none
184186
is = [st(subject, property, result, doc as Node)]
@@ -190,8 +192,10 @@ export function basicField (
190192
if (!docs.includes(st.why.uri)) docs.push(st.why.uri)
191193
})
192194
ds.forEach(st => {
195+
/* istanbul ignore next */
193196
if (!docs.includes(st.why.uri)) docs.push(st.why.uri)
194197
})
198+
/* istanbul ignore next */
195199
if (docs.length === 0) {
196200
throw new Error('updateMany has no docs to patch')
197201
}
@@ -209,7 +213,6 @@ export function basicField (
209213
if (ok) {
210214
updateMany(ds2, is2, callback)
211215
} else {
212-
console.log('Update many failed on: ' + doc)
213216
callback(uri, ok, body)
214217
}
215218
})

test/unit/widgets/forms/__snapshots__/basic.test.ts.snap

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`basicField adds the basic field to the container, if provided 1`] = `
4+
<div>
5+
<tr>
6+
<td
7+
class="formFieldName"
8+
style=" vertical-align: middle;"
9+
>
10+
<a
11+
href="http://example.com/#some-property"
12+
style="color: #3B5998; text-decoration: none;"
13+
>
14+
Some property
15+
</a>
16+
</td>
17+
<td
18+
class="formFieldValue"
19+
>
20+
<input
21+
maxlength="4096"
22+
size="20"
23+
style="background-color: #eef; padding: 0.5em; border: .05em solid #88c; border-radius:0.2em; font-size: 100%; margin:0.2em; "
24+
type="text"
25+
/>
26+
</td>
27+
</tr>
28+
</div>
29+
`;
30+
331
exports[`basicField creates a basic field 1`] = `
432
<tr>
533
<td

0 commit comments

Comments
 (0)