Debian Codegraph @

extensions/VisualEditor/lib/ve/tests/ui/actions/ve.ui.AnnotationAction.test.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface Actions AnnotationAction tests.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 QUnit.module( 've.ui.AnnotationAction' );
8
9 /* Tests */
10
11 QUnit.test( 'toggle', ( assert ) => {
12 const newBold = { type: 'textStyle/bold' },
13 html = '<p>Foo<b>bar</b><strong>baz</strong><i>quux</i> white\u3000space</p>',
14 cases = [
15 {
16 html: html,
17 rangeOrSelection: new ve.Range( 1, 4 ),
18 method: 'toggle',
19 args: [ 'textStyle/bold' ],
20 expectedData: function ( data ) {
21 data.splice( 1, 3,
22 [ 'F', [ newBold ] ],
23 [ 'o', [ newBold ] ],
24 [ 'o', [ newBold ] ]
25 );
26 },
27 msg: 'toggle bold on plain text'
28 },
29 {
30 html: html,
31 rangeOrSelection: new ve.Range( 7, 10 ),
32 method: 'toggle',
33 args: [ 'textStyle/bold' ],
34 expectedData: function ( data ) {
35 data.splice( 7, 3, ...'baz' );
36 },
37 msg: 'toggle bold on strong text'
38 },
39 {
40 html: html,
41 rangeOrSelection: new ve.Range( 4, 10 ),
42 method: 'toggle',
43 args: [ 'textStyle/bold' ],
44 expectedData: function ( data ) {
45 data.splice( 4, 6, ...'barbaz' );
46 },
47 msg: 'toggle bold on bold then strong text'
48 },
49 {
50 html: html,
51 rangeOrSelection: new ve.Range( 1, 14 ),
52 method: 'toggle',
53 args: [ 'textStyle/bold' ],
54 expectedData: function ( data ) {
55 data.splice( 1, 3,
56 [ 'F', [ newBold ] ],
57 [ 'o', [ newBold ] ],
58 [ 'o', [ newBold ] ]
59 );
60 data.splice( 10, 4,
61 [ 'q', [ ve.dm.example.italic, newBold ] ],
62 [ 'u', [ ve.dm.example.italic, newBold ] ],
63 [ 'u', [ ve.dm.example.italic, newBold ] ],
64 [ 'x', [ ve.dm.example.italic, newBold ] ]
65 );
66 },
67 msg: 'toggle bold on plain, bold, strong then underlined text'
68 },
69 {
70 html: html,
71 rangeOrSelection: new ve.Range( 14, 21 ),
72 method: 'toggle',
73 args: [ 'textStyle/bold' ],
74 expectedData: function ( data ) {
75 data.splice( 15, 5,
76 [ 'w', [ newBold ] ],
77 [ 'h', [ newBold ] ],
78 [ 'i', [ newBold ] ],
79 [ 't', [ newBold ] ],
80 [ 'e', [ newBold ] ]
81 );
82 },
83 msg: 'trailing whitespace is not annotated'
84 },
85 {
86 html: ve.dm.example.annotatedTableHtml,
87 rangeOrSelection: {
88 type: 'table',
89 tableRange: new ve.Range( 0, 52 ),
90 fromCol: 0,
91 fromRow: 0,
92 toCol: 1,
93 toRow: 0
94 },
95 method: 'toggle',
96 args: [ 'textStyle/bold' ],
97 expectedData: function ( data ) {
98 data.splice( 5, 3, ...'Foo' );
99 data.splice( 12, 3, ...'Bar' );
100 },
101 msg: 'toggle bold on comparable bold annotations spanning multiple table cells'
102 },
103 {
104 html: '<table><tr><td><b>A</b></td><td></td></tr></table>',
105 rangeOrSelection: {
106 type: 'table',
107 tableRange: new ve.Range( 0, 15 ),
108 fromCol: 0,
109 fromRow: 0,
110 toCol: 1,
111 toRow: 0
112 },
113 method: 'toggle',
114 args: [ 'textStyle/bold' ],
115 expectedData: function ( data ) {
116 data.splice( 5, 1, 'A' );
117 },
118 msg: 'toggle bold off when selection includes an content-less cell'
119 },
120 {
121 html: '<table><tr><td></td><td><b>A</b></td></tr></table>',
122 rangeOrSelection: {
123 type: 'table',
124 tableRange: new ve.Range( 0, 15 ),
125 fromCol: 0,
126 fromRow: 0,
127 toCol: 1,
128 toRow: 0
129 },
130 method: 'toggle',
131 args: [ 'textStyle/bold' ],
132 expectedData: function ( data ) {
133 data.splice( 9, 1, 'A' );
134 },
135 msg: 'toggle bold off when first cell is content-less cell'
136 }
137 ];
138
139 cases.forEach( ( caseItem ) => {
140 ve.test.utils.runActionTest(
141 assert,
142 {
143 actionName: 'annotation',
144 ...caseItem
145 }
146 );
147 } );
148 } );