-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
figure-content-reducer.js
109 lines (88 loc) · 2.85 KB
/
figure-content-reducer.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
/**
* Internal dependencies
*/
import figureContentReducer from '../figure-content-reducer';
import { deepFilterHTML } from '../utils';
describe( 'figureContentReducer', () => {
const schema = {
figure: {
children: {
img: {},
a: {
children: {
img: {},
},
},
},
},
};
it( 'should wrap image in figure', () => {
const input = '<img>';
const output = '<figure><img></figure>';
expect(
deepFilterHTML( input, [ figureContentReducer ], schema )
).toEqual( output );
} );
it( 'should move lone embedded content from paragraph', () => {
const input = '<p><img></p>';
const output = '<figure><img></figure><p></p>';
expect(
deepFilterHTML( input, [ figureContentReducer ], schema )
).toEqual( output );
} );
it( 'should move multiple lone embedded content from paragraph', () => {
const input = '<p><img><img></p>';
const output = '<figure><img></figure><figure><img></figure><p></p>';
expect(
deepFilterHTML( input, [ figureContentReducer ], schema )
).toEqual( output );
} );
it( 'should move aligned embedded content from paragraph (1)', () => {
const input = '<p><img class="alignright">test</p>';
const output = '<figure><img class="alignright"></figure><p>test</p>';
expect(
deepFilterHTML( input, [ figureContentReducer ], schema )
).toEqual( output );
} );
it( 'should move aligned embedded content from paragraph (2)', () => {
const input = '<p>test<img class="alignright"></p>';
const output = '<figure><img class="alignright"></figure><p>test</p>';
expect(
deepFilterHTML( input, [ figureContentReducer ], schema )
).toEqual( output );
} );
it( 'should move aligned embedded content from paragraph (3)', () => {
const input = '<p>test<img class="alignright">test</p>';
const output =
'<figure><img class="alignright"></figure><p>testtest</p>';
expect(
deepFilterHTML( input, [ figureContentReducer ], schema )
).toEqual( output );
} );
it( 'should not move embedded content from paragraph (1)', () => {
const input = '<p><img>test</p>';
expect(
deepFilterHTML( input, [ figureContentReducer ], schema )
).toEqual( input );
} );
it( 'should not move embedded content from paragraph (2)', () => {
const input = '<p>test<img></p>';
expect(
deepFilterHTML( input, [ figureContentReducer ], schema )
).toEqual( input );
} );
it( 'should not move embedded content from paragraph (3)', () => {
const input = '<p>test<img>test</p>';
expect(
deepFilterHTML( input, [ figureContentReducer ], schema )
).toEqual( input );
} );
it( 'should move an anchor with an image', () => {
const input = '<p><a href="#"><img class="alignleft"></a>test</p>';
const output =
'<figure><a href="#"><img class="alignleft"></a></figure><p>test</p>';
expect(
deepFilterHTML( input, [ figureContentReducer ], schema )
).toEqual( output );
} );
} );