aboutsummaryrefslogtreecommitdiff
path: root/__tests__/index.js
blob: 805ba42cf22e76d6e686a6a9b1fce2b4489cf107 (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
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('line-input', t => {
  const {contents} = render(file(join(__dirname, 'input-simple.md')));
  t.snapshot(contents);
});

test('line-input-simple', t => {
  const {contents} = render('[__here__]');
  t.is(contents, '<p><input type="text" placeholder="here"></p>');
});

test('line-input-empty', t => {
  const {contents} = render('[____]');
  t.is(contents, '<p><input type="text"></p>');
});
test('line-input-simple-raw', t => {
  const {contents} = renderRaw('[__here__]');
  t.is(contents, '<p><input type="text" placeholder="here"></p>');
});

test('line-input-empty-raw', t => {
  const {contents} = renderRaw('[____]');
  t.is(contents, '<p><input type="text"></p>');
});

test('line-input-id', t => {
  const {contents} = render('[__Some text__]{#unicorn}');
  t.is(contents, '<p><input id="unicorn" type="text" placeholder="Some text"></p>');
});

test('line-input-class', t => {
  const {contents} = render('[__panda__]{.unicorn}');
  t.is(contents, '<p><input class="unicorn" type="text" placeholder="panda"></p>');
});

test('line-input-classes', t => {
  const {contents} = render('[__strong unicorn__]{.unicorn .fox}');
  t.is(contents, '<p><input class="unicorn fox" type="text" placeholder="strong unicorn"></p>');
});

test('line-input-key-value', t => {
  const {contents} = render('[__math exercice__]{unicorn="horse + horn"}');
  t.is(contents, '<p><input type="text" unicorn="horse + horn" placeholder="math exercice"></p>');
});

test('line-input-overwrite-type', t => {
  const {contents} = render('[__Good answer__]{type=buttom}');
  t.is(contents, '<p><input type="text" placeholder="Good answer"></p>');
});

test('line-input-overwrite-placeholder', t => {
  const {contents} = render('[__Please not a bad answer__]{placeholder=\'not here\'}');
  t.is(contents, '<p><input type="text" placeholder="Please not a bad answer"></p>');
});

test('line-input-overwrite-class', t => {
  const {contents} = render('[__A result__]{class=\'unicorn\' .fox}');
  t.is(contents, '<p><input class="fox" type="text" placeholder="A result"></p>');
});

test('line-input-overwrite-id', t => {
  const {contents} = render('[__email__]{id=unicorn #fox}');
  t.is(contents, '<p><input id="fox" type="text" placeholder="email"></p>');
});

test('line-input-multi-id', t => {
  const {contents} = render('[__Login__]{#unicorn #fox}');
  t.is(contents, '<p><input id="unicorn" type="text" placeholder="Login"></p>');
});

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

test('line-input-password', t => {
  const {contents} = render('[__Password__]{#passwd type=password}');
  t.is(contents, '<p><input id="passwd" type="password" placeholder="Password"></p>');
});