-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
111 lines (105 loc) · 2.64 KB
/
test.js
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
import test from 'ava';
import 'babel-core/register';
import {filterText, mapText} from './index';
import {mergeDeep} from 'immutable-object-methods';
test('mapText()', t => {
const input = [{
type: 'paragraph',
children: [{content: 'foo bar', type: 'text'}]
}, {
type: 'embed',
embedType: 'image',
imageSrc: 'http://image-source.jpg',
attribution: [{
content: 'attribution',
type: 'text',
}],
caption: [{
content: 'caption',
type: 'text',
}]
}];
const actual = mapText(input, (child) => {
return mergeDeep(child, {bold: true});
});
const expected = [{
type: 'paragraph',
children: [
{content: 'foo bar', type: 'text', bold: true},
]
}, {
type: 'embed',
embedType: 'image',
imageSrc: 'http://image-source.jpg',
attribution: [{
content: 'attribution',
type: 'text',
bold: true
}],
caption: [{
content: 'caption',
type: 'text',
bold: true
}]
}];
t.deepEqual(actual, expected);
t.is(actual[0].children[1], input[0].children[1]);
});
test('mapText() no change', t => {
const input = [{
type: 'paragraph',
children: [{content: 'foo bar', type: 'text'}]
}];
t.is(mapText(input, (child) => child), input);
});
test('filterText(), no text removed', t => {
const input = [{
type: 'paragraph',
children: [{content: 'foo bar', type: 'text'}]
}];
const expected = input;
const actual = filterText(input, () => true);
t.is(actual, expected);
});
test('filterText(), remove one child', t => {
const input = [{
type: 'paragraph',
children: [{content: 'foo bar', type: 'text'}, {mark: true, type: 'text'}]
}];
const expected = [{
type: 'paragraph',
children: [{content: 'foo bar', type: 'text'}]
}];
const actual = filterText(input, (text) => !text.mark);
t.deepEqual(actual, expected);
});
test('filterText(), nested, no text removed', t => {
const input = [{
type: 'blockquote',
children: [{
type: 'paragraph',
children: [{content: 'foo bar', type: 'text'}]
}]
}];
const expected = input;
const actual = filterText(input, () => true);
t.is(actual, expected);
});
test('filterText(), nested, remove one child', t => {
const input = [{
type: 'blockquote',
children: [{
type: 'paragraph',
children: [{content: 'foo bar', type: 'text'}, {mark: true, type: 'text'}]
}]
}];
const expected = [{
type: 'blockquote',
children: [{
type: 'paragraph',
children: [{content: 'foo bar', type: 'text'}]
}]
}];
const actual = filterText(input, (text) => !text.mark);
t.deepEqual(actual, expected);
});