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

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

test('emty', t => {
  const {contents} = render('[____\n____]');
  t.is(contents, '<textarea></textarea>');
});

test('emty-raw', t => {
  const {contents} = renderRaw('[____\n____]');
  t.is(contents, '<textarea></textarea>');
});

test('simple', t => {
  const {contents} = render('[____\nHere some text\n____]');
  t.is(contents, '<textarea>Here some text</textarea>');
});

test('simple-raw', t => {
  const {contents} = renderRaw('[____\nHere some text\n____]');
  t.is(contents, '<textarea>Here some text</textarea>');
});

test('long', t => {
  const {contents} = render(`
[_______

Here some awesome text !
With severale lines, ...

a good text area
_______]`);
  t.is(contents, `<textarea>
Here some awesome text !
With severale lines, ...

a good text area</textarea>`);
});

test('long-raw', t => {
  const {contents} = renderRaw(`
[_______

Here some awesome text !
With severale lines, ...

a good text area
_______]`);
  t.is(contents, `<textarea>
Here some awesome text !
With severale lines, ...

a good text area</textarea>`);
});

test('not a text-area', t => {
  const {contents} = renderRaw(`
[_______some text
Oups bad-formated text area
_______]`);
  t.notRegex(contents, /textarea/);
});

test.todo('id text');
test.todo('class');
test.todo('classes');
test.todo('key-value');
test.todo('classes key-value id');
test.todo('overwrite class');
test.todo('overwrite id');
test.todo('multiple id');

test.todo('real1');
test.todo('real2');
test.todo('real3');