aboutsummaryrefslogtreecommitdiff
path: root/__tests__/index.js
blob: 59afa381bfd9e3ec75a6d63c75e38595b5386939 (plain)
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
import {readFileSync as file} from 'fs';
import {join} from 'path';
import unified from 'unified';

import test from 'ava';
import raw from 'rehype-raw';
import reParse from 'remark-parse';
import stringify from 'rehype-stringify';
import remark2rehype from 'remark-rehype';

import plugin from '../app';

const render = text => unified()
  .use(reParse)
  .use(plugin)
  .use(remark2rehype)
  .use(stringify)
  .processSync(text);

const renderRaw = text => unified()
  .use(reParse)
  .use(plugin)
  .use(remark2rehype, {allowDangerousHTML: true})
  .use(raw)
  .use(stringify)
  .processSync(text);

test('simple', t => {
  const {contents} = render(`
 - [x] ! False
 - [ ] ~ None
 - [x] = True`);
  t.is(contents,
`<fieldset class="mc check" id="mc_0"><ul>\
<li><input checked type="checkbox" id="mc_0_0" class="!"><label for="mc_0_0">False</label></li>\
<li><input type="checkbox" id="mc_0_1" class="~"><label for="mc_0_1">None</label></li>\
<li><input checked type="checkbox" id="mc_0_2" class="="><label for="mc_0_2">True</label></li>\
</ul><input onclick="check(&#x27;mc_0&#x27;,[0,0.5,1])" value="Validate" type="button"></fieldset>`);
});

test('mchoide-snap', t => {
  const {contents} = render(file(join(__dirname, 'mchoice.md')));
  t.snapshot(contents);
});

test('all-checked', t => {
  const {contents} = render(`
 - [x] ! False
 - [x] ~ None
 - [x] = True`);
  t.is(contents,
`<fieldset class="mc check" id="mc_0"><ul>\
<li><input checked type="checkbox" id="mc_0_0" class="!"><label for="mc_0_0">False</label></li>\
<li><input checked type="checkbox" id="mc_0_1" class="~"><label for="mc_0_1">None</label></li>\
<li><input checked type="checkbox" id="mc_0_2" class="="><label for="mc_0_2">True</label></li>\
</ul><input onclick="check(&#x27;mc_0&#x27;,[0,0.5,1])" value="Validate" type="button"></fieldset>`);
});

test('none-checked', t => {
  const {contents} = render(`
 - [ ] ! False
 - [ ] ~ None
 - [ ] = True`);
  t.is(contents,
`<fieldset class="mc check" id="mc_0"><ul>\
<li><input type="checkbox" id="mc_0_0" class="!"><label for="mc_0_0">False</label></li>\
<li><input type="checkbox" id="mc_0_1" class="~"><label for="mc_0_1">None</label></li>\
<li><input type="checkbox" id="mc_0_2" class="="><label for="mc_0_2">True</label></li>\
</ul><input onclick="check(&#x27;mc_0&#x27;,[0,0.5,1])" value="Validate" type="button"></fieldset>`);
});

test('caps-checked', t => {
  const {contents} = render(`
 - [X] ! False
 - [X] ~ None
 - [X] = True`);
  t.is(contents,
`<fieldset class="mc check" id="mc_0"><ul>\
<li><input checked type="checkbox" id="mc_0_0" class="!"><label for="mc_0_0">False</label></li>\
<li><input checked type="checkbox" id="mc_0_1" class="~"><label for="mc_0_1">None</label></li>\
<li><input checked type="checkbox" id="mc_0_2" class="="><label for="mc_0_2">True</label></li>\
</ul><input onclick="check(&#x27;mc_0&#x27;,[0,0.5,1])" value="Validate" type="button"></fieldset>`);
});

test('empty-square-check', t => {
  const {contents} = render(`
 - [] ! False
 - [] ~ None
 - [] = True`);
  t.is(contents,
`<fieldset class="mc check" id="mc_0"><ul>\
<li><input type="checkbox" id="mc_0_0" class="!"><label for="mc_0_0">False</label></li>\
<li><input type="checkbox" id="mc_0_1" class="~"><label for="mc_0_1">None</label></li>\
<li><input type="checkbox" id="mc_0_2" class="="><label for="mc_0_2">True</label></li>\
</ul><input onclick="check(&#x27;mc_0&#x27;,[0,0.5,1])" value="Validate" type="button"></fieldset>`);
});

test('multi-check', t => {
  const {contents} = render(`
 - [X] = caps
 - [] ! empty
 - [ ] ! space
 - [x] = checkmark`);
  t.is(contents,
`<fieldset class="mc check" id="mc_0"><ul>\
<li><input checked type="checkbox" id="mc_0_0" class="="><label for="mc_0_0">caps</label></li>\
<li><input type="checkbox" id="mc_0_1" class="!"><label for="mc_0_1">empty</label></li>\
<li><input type="checkbox" id="mc_0_2" class="!"><label for="mc_0_2">space</label></li>\
<li><input checked type="checkbox" id="mc_0_3" class="="><label for="mc_0_3">checkmark</label></li>\
</ul><input onclick="check(&#x27;mc_0&#x27;,[1,0,0,1])" value="Validate" type="button"></fieldset>`);
});

test('mchoide-raw-snap', t => {
  const {contents} = renderRaw(file(join(__dirname, 'mchoice-raw.md')));
  t.snapshot(contents);
});

test.todo('Citation in a multiple-choice');
test.todo('Feedback feature test');

test.todo('raw render');

test.todo('Error about check');
test.todo('Error about list');
test.todo('Error about space');

test.todo('with brackets for single choice');

test.todo('real test 1');
test.todo('real test 2');
test.todo('real test 3');