-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.html
485 lines (435 loc) · 12.1 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
<html>
<head>
<title>AnnotationSurvey Content Annotation</title>
<link rel="stylesheet" href="https://jonudell.info/hlib/hlib.css" />
<script src="https://jonudell.info/hlib/hlib2.bundle.js"></script>
<script src="https://jonudell.info/hlib/showdown.js"></script>
<script src="questions.js"></script>
<script async src="index.js"></script>
<script src="tinytest.js"></script>
<style>
@import url(https://fonts.googleapis.com/css?family=Raleway:500,400,300,800,700);
body {
font-family: Raleway;
word-break: break-word;
margin-top:.25in;
width: 65%;
background-color: lightgreen;
}
li {
margin-bottom: 1em;
}
div.inspector {
white-space: pre;
font-size: smaller;
}
svg {
width: 100%;
height: auto;
}
.clinGenSelection {
font-style: italic;
}
a {
text-decoration: underline;
}
.annotationTags a {
text-decoration: none;
}
#params {
position: fixed;
left: 70%;
right: 20px;
margin-left: 20px;
padding-left: 8px;
padding-right: 8px;
border-width: thin;
border-style: solid;
background-color: #faf9f9d6;
}
#formContainer {
margin-bottom: 20px;
}
#postAnswerButton {
display: none;
}
#skipButton {
display: none;
}
#endRepeatButton {
display: none;
}
.question {
display: none
}
textarea {
width: 60%;
height: 6em;
}
.choice {
line-height: 1.5;
}
.buttons {
margin-top: 1em;
}
.asterisk {
font-size: larger;
cursor: pointer;
}
div.message {
font-weight: bold;
}
</style>
</head>
<body>
<h1>AnnotationSurvey</h1>
<div id="formContainer">
<div id="userContainer"></div>
<div id="tokenContainer"></div>
<div id="groupContainer"></div>
</div>
<div id="params"></div>
<div id="questions"></div>
<div class="buttons">
<button id="postAnswerButton" onclick="postAnswer()">post answer</button>
<button id="endRepeatButton" onclick="endRepeat()">next question</button>
</div>
<p id="finished"></p>
<!-- this duplicates hlib.setUser because forms created in tests can't see the module -->
<script>
function setUser() {
let value = document.getElementById('userForm').value;
localStorage.setItem('h_user', value);
}
</script>
<script type="module">
async function deleteTestAnnotation(rowId) {
let token = hlib.getToken()
assert(rowId)
const data = await hlib.deleteAnnotation(rowId, token)
console.log('deleted test annotation', data)
}
function clearAnswers() {
let questionKeys = getQuestionKeys()
questionKeys.forEach(questionKey => {
questions[questionKey].answer = null
})
}
async function delay(seconds) {
return new Promise(resolve => setTimeout(resolve, seconds * 1000))
}
function log(msg) {
document.body.innerHTML += `<div class="logMessage">${msg}</div>`
}
async function cleanup() {
return new Promise(resolve => {
async function worker() {
const data = await hlib.search({
url: `https://hypothes.is/api/search?group=${hlib.getSelectedGroup()}&limit=200`,
})
const rows = data[0].concat(data[1])
rows.forEach(row => {
hlib.deleteAnnotation(row.id)
.then(r => { console.log(r) })
})
resolve()
}
worker()
})
}
function allQuestionsAreRendered(resolve) {
const allQuestions = Array.from(document.querySelectorAll('.question'))
eq(23, allQuestions.length)
const firstQuestion = allQuestions[0]
const firstQuestionChoices = Array.from(firstQuestion.querySelectorAll('.choice'))
eq(5, firstQuestionChoices.length)
eq('1.01.05', firstQuestionChoices[4].querySelector('input').value)
const lastQuestion = allQuestions.slice(-1)[0]
const title = lastQuestion.querySelector('h2').innerText
eq('Exaggerated/minimized claims*', title)
resolve()
}
function firstQuestionIsDisplayed(resolve) {
const question = hlib.getById('Q01')
const title = question.querySelector('h2').innerText
eq('Overall Credibility', title)
eq('block', question.style.display)
resolve()
}
async function firstAnswerIsPosted(resolve) {
const questionKey = findFirstUnansweredQuestionKey()
hlib.getById(questionKey).querySelector('input').checked = true
hlib.getById('postAnswerButton').click()
await delay(3)
eq('1.01.01', questions['Q01'].answer)
eq('1.01.01', getRadioVal('Q01'))
resolve()
}
function secondAnswerIsRendered(resolve) {
const question = hlib.getById('Q02')
const title = question.querySelector('h2').innerText
eq('Title Representativeness*', title)
const subtitle = question.querySelector('h3').innerText
eq('Does the title of the article accurately reflect the content of the article?', subtitle)
resolve()
}
tests({
'gets token': function () {
return new Promise( (resolve, reject) => {
let token = hlib.getToken()
let slice = token.slice(0,9)
eq('6879-358c', slice)
resolve()
})
},
'public group is gone and test group is selected' : function () {
return new Promise( resolve => {
async function runTest() {
await delay(2)
const options = Array.from(hlib.getById('groupsList').options)
options.forEach (option => {
if (option.value === testGroup) {
option.selected = true
}
})
const firstGroupValue = hlib.getById('groupsList').querySelectorAll('option')[0].value
assertNotEquals (firstGroupValue, '__world__')
eq( testGroup, hlib.getSelectedGroup() )
resolve()
}
runTest()
})
},
'all questions are rendered' : function () {
return new Promise( resolve => {
allQuestionsAreRendered(resolve)
})
},
'first question is displayed' : function () {
return new Promise( resolve => {
firstQuestionIsDisplayed(resolve)
})
},
'first answer is posted': function() {
return new Promise( (resolve) => {
firstAnswerIsPosted(resolve)
})
},
'second question is rendered': function() {
return new Promise( (resolve) => {
secondAnswerIsRendered(resolve)
})
},
'redo first question': function() {
return new Promise( (resolve) => {
async function runTest() {
const redoButton = hlib.getById('redo_Q01')
redoButton.click()
await delay(3)
resolve()
}
runTest()
})
},
'all questions are rendered again' : function () {
return new Promise( resolve => {
allQuestionsAreRendered(resolve)
})
},
'first question is rendered again' : function () {
return new Promise( resolve => {
firstQuestionIsDisplayed(resolve)
})
},
'first answer is posted again': function() {
return new Promise( (resolve) => {
firstAnswerIsPosted(resolve)
})
},
'second question is rendered again': function() {
return new Promise( (resolve) => {
secondAnswerIsRendered(resolve)
})
},
'second answer posted with no answer provokes alert': function() {
return new Promise( (resolve, reject) => {
async function runTest() {
const questionKey = findFirstUnansweredQuestionKey()
hlib.getById('postAnswerButton').click()
await delay(3)
eq('selection required', localStorage.getItem('h_alert'))
resolve()
}
runTest()
})
},
'second answer is posted': function() {
return new Promise( resolve => {
async function runTest() {
let questionKey = findFirstUnansweredQuestionKey()
const question = hlib.getById('Q02')
hlib.getById(questionKey).querySelector('input').checked = true
appVars.SELECTION = 'The title'
hlib.getById('postAnswerButton').click()
await delay(3)
eq('1.02.01', questions['Q02'].answer)
eq('1.02.01', getRadioVal('Q02'))
resolve()
}
runTest()
})
},
'third question is rendered': function() {
return new Promise( (resolve) => {
const question = hlib.getById('Q03')
const title = question.querySelector('h2').innerText
eq('Title Representativeness*', title)
const subtitle = question.querySelector('h3').innerText
eq('How is the title unrepresentative? (select all that apply)', subtitle)
resolve()
})
},
'third answer is posted': function() {
return new Promise( resolve => {
async function runTest() {
const questionKey = findFirstUnansweredQuestionKey()
hlib.getById(questionKey).querySelectorAll('input')[0].checked = true
hlib.getById(questionKey).querySelectorAll('input')[6].checked = true
appVars.SELECTION = 'The title'
hlib.getById('postAnswerButton').click()
await delay(3)
eq('1.03.01, 1.03.07', questions[questionKey].answer)
resolve()
}
runTest()
})
},
'fourth answer is posted': function() {
return new Promise( resolve => {
async function runTest() {
const questionKey = findFirstUnansweredQuestionKey()
setTextAreaVal(questionKey, 'A very silly title')
hlib.getById('postAnswerButton').click()
await delay(3)
eq('A very silly title', questions[questionKey].answer)
resolve()
}
runTest()
})
},
'fifth answer is posted': function() {
return new Promise( resolve => {
async function runTest() {
const questionKey = findFirstUnansweredQuestionKey()
hlib.getById(questionKey).querySelectorAll('input')[3].checked = true
hlib.getById('postAnswerButton').click()
await delay(3)
eq('1.04.04', questions[questionKey].answer)
resolve()
}
runTest()
})
},
'sixth answer is posted': function() {
return new Promise( resolve => {
async function runTest() {
const questionKey = findFirstUnansweredQuestionKey()
hlib.getById(questionKey).querySelectorAll('input')[1].checked = true
hlib.getById('postAnswerButton').click()
await delay(3)
eq('1.07.02', questions[questionKey].answer)
resolve()
}
runTest()
})
},
'seventh answer is posted': function() {
return new Promise( resolve => {
async function runTest() {
const questionKey = findFirstUnansweredQuestionKey()
hlib.getById(questionKey).querySelectorAll('input')[0].checked = true
hlib.getById('postAnswerButton').click()
await delay(3)
eq('1.08a.01', questions[questionKey].answer)
resolve()
}
runTest()
})
},
'eighth answer is posted': function() {
return new Promise( resolve => {
async function runTest() {
let questionKey = findFirstUnansweredQuestionKey()
hlib.getById(questionKey).querySelectorAll('input')[0].checked = true
hlib.getById('postAnswerButton').click()
await delay(3)
eq('1.08.01', questions[questionKey].answer)
resolve()
}
runTest()
})
},
'ninth answer posted with unchanged selection provokes alert': function() {
return new Promise( resolve => {
async function runTest() {
localStorage.setItem('h_alert', '')
const questionKey = findFirstUnansweredQuestionKey()
hlib.getById('postAnswerButton').click()
await delay(3)
eq('new selection required', localStorage.getItem('h_alert'))
resolve()
}
runTest()
})
},
'ninth answer posted with changed selection': function() {
return new Promise( (resolve) => {
async function runTest() {
const questionKey = findFirstUnansweredQuestionKey()
appVars.SELECTION = 'Expert #1'
hlib.getById('postAnswerButton').click()
await delay(3)
assert(questions[questionKey].answer.startsWith('https://hypothes.is/a/'))
assert(questions[questionKey].answerQuote.indexOf(`<span title="exact quote"
class="quoteExact">Expert #1</span>` > 0))
resolve()
}
runTest()
})
},
'ninth answer invoked repeat': function() {
return new Promise( (resolve) => {
const repeatedQuestion = hlib.getById('Q09_02')
assert(repeatedQuestion)
const title = repeatedQuestion.querySelector('h2').innerText
eq('Expert sources*', title)
const subtitle = repeatedQuestion.querySelector('h3').innerText
eq('Highlight expert source', subtitle)
resolve()
})
},
'next question button ends repeat': function() {
return new Promise( resolve => {
async function runTest() {
hlib.getById('endRepeatButton').click()
await delay(3)
eq('Q13', findFirstUnansweredQuestionKey())
resolve()
}
runTest()
})
},
'cleanup' : function() {
return new Promise (resolve => {
async function worker() {
await cleanup()
softReload()
resolve()
}
worker()
})
},
})
</script>
</body>
</html>