| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
QUnit.module( 've.ui.FormatAction' ); |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
QUnit.test( 'convert', ( assert ) => { |
| 12 |
const cases = [ |
| 13 |
{ |
| 14 |
rangeOrSelection: new ve.Range( 14, 16 ), |
| 15 |
type: 'heading', |
| 16 |
attributes: { level: 2 }, |
| 17 |
expectedRangeOrSelection: new ve.Range( 14, 16 ), |
| 18 |
expectedData: function ( data ) { |
| 19 |
data.splice( 12, 1, { type: 'heading', attributes: { level: 2 } } ); |
| 20 |
data.splice( 19, 1, { type: '/heading' } ); |
| 21 |
}, |
| 22 |
undo: true, |
| 23 |
msg: 'converting partial selection of list item "Item 2" to level 2 heading' |
| 24 |
}, |
| 25 |
{ |
| 26 |
rangeOrSelection: new ve.Range( 15, 50 ), |
| 27 |
type: 'heading', |
| 28 |
attributes: { level: 3 }, |
| 29 |
expectedRangeOrSelection: new ve.Range( 15, 50 ), |
| 30 |
expectedData: function ( data ) { |
| 31 |
data.splice( 12, 1, { type: 'heading', attributes: { level: 3 } } ); |
| 32 |
data.splice( 19, 1, { type: '/heading' } ); |
| 33 |
data.splice( 22, 1, { type: 'heading', attributes: { level: 3 } } ); |
| 34 |
data.splice( 29, 1, { type: '/heading' } ); |
| 35 |
data.splice( 32, 1, { type: 'heading', attributes: { level: 3 } } ); |
| 36 |
data.splice( 42, 1, { type: '/heading' } ); |
| 37 |
data.splice( 45, 1, { type: 'heading', attributes: { level: 3 } } ); |
| 38 |
data.splice( 52, 1, { type: '/heading' } ); |
| 39 |
}, |
| 40 |
undo: true, |
| 41 |
msg: 'converting partial selection across two lists surrounding a paragraph' |
| 42 |
}, |
| 43 |
{ |
| 44 |
rangeOrSelection: new ve.Range( 4, 28 ), |
| 45 |
type: 'heading', |
| 46 |
attributes: { level: 1 }, |
| 47 |
expectedRangeOrSelection: new ve.Range( 4, 28 ), |
| 48 |
expectedData: function ( data ) { |
| 49 |
data.splice( 2, 1, { type: 'heading', attributes: { level: 1 } } ); |
| 50 |
data.splice( 9, 1, { type: '/heading' } ); |
| 51 |
data.splice( 12, 1, { type: 'heading', attributes: { level: 1 } } ); |
| 52 |
data.splice( 19, 1, { type: '/heading' } ); |
| 53 |
data.splice( 22, 1, { type: 'heading', attributes: { level: 1 } } ); |
| 54 |
data.splice( 29, 1, { type: '/heading' } ); |
| 55 |
}, |
| 56 |
undo: true, |
| 57 |
msg: 'converting partial selection of all list items to level 1 headings' |
| 58 |
}, |
| 59 |
{ |
| 60 |
rangeOrSelection: new ve.Range( 5, 26 ), |
| 61 |
type: 'preformatted', |
| 62 |
attributes: undefined, |
| 63 |
expectedRangeOrSelection: new ve.Range( 5, 26 ), |
| 64 |
expectedData: function ( data ) { |
| 65 |
data.splice( 2, 1, { type: 'preformatted' } ); |
| 66 |
data.splice( 9, 1, { type: '/preformatted' } ); |
| 67 |
data.splice( 12, 1, { type: 'preformatted' } ); |
| 68 |
data.splice( 19, 1, { type: '/preformatted' } ); |
| 69 |
data.splice( 22, 1, { type: 'preformatted' } ); |
| 70 |
data.splice( 29, 1, { type: '/preformatted' } ); |
| 71 |
}, |
| 72 |
undo: true, |
| 73 |
msg: 'converting partial selection of some list items to preformatted text' |
| 74 |
}, |
| 75 |
{ |
| 76 |
rangeOrSelection: new ve.Range( 146, 159 ), |
| 77 |
type: 'paragraph', |
| 78 |
attributes: undefined, |
| 79 |
expectedRangeOrSelection: new ve.Range( 146, 159 ), |
| 80 |
expectedData: function ( data ) { |
| 81 |
data.splice( 145, 1, { type: 'paragraph' } ); |
| 82 |
data.splice( 159, 1, { type: '/paragraph' } ); |
| 83 |
}, |
| 84 |
undo: true, |
| 85 |
msg: 'converting heading in list item to paragraph' |
| 86 |
}, |
| 87 |
{ |
| 88 |
rangeOrSelection: new ve.Range( 165, 180 ), |
| 89 |
type: 'paragraph', |
| 90 |
attributes: undefined, |
| 91 |
expectedRangeOrSelection: new ve.Range( 165, 180 ), |
| 92 |
expectedData: function ( data ) { |
| 93 |
data.splice( 162, 1, { type: 'paragraph' } ); |
| 94 |
data.splice( 183, 1, { type: '/paragraph' } ); |
| 95 |
}, |
| 96 |
undo: true, |
| 97 |
msg: 'converting preformatted in list item to paragraph' |
| 98 |
}, |
| 99 |
{ |
| 100 |
html: '<p>a</p><p></p>', |
| 101 |
rangeOrSelection: new ve.Range( 4 ), |
| 102 |
type: 'heading', |
| 103 |
attributes: { level: 2 }, |
| 104 |
expectedRangeOrSelection: new ve.Range( 4 ), |
| 105 |
expectedData: function ( data ) { |
| 106 |
data.splice( 3, 1, { type: 'heading', attributes: { level: 2 } } ); |
| 107 |
data.splice( 4, 1, { type: '/heading' } ); |
| 108 |
}, |
| 109 |
undo: true, |
| 110 |
msg: 'converting empty paragraph to heading' |
| 111 |
}, |
| 112 |
{ |
| 113 |
html: '<p>foo</p><p>bar</p>', |
| 114 |
rangeOrSelection: new ve.Range( 1, 6 ), |
| 115 |
type: 'heading', |
| 116 |
attributes: { level: 2 }, |
| 117 |
expectedRangeOrSelection: new ve.Range( 1, 6 ), |
| 118 |
expectedData: function ( data ) { |
| 119 |
data.splice( 0, 1, { type: 'heading', attributes: { level: 2 } } ); |
| 120 |
data.splice( 4, 1, { type: '/heading' } ); |
| 121 |
}, |
| 122 |
undo: true, |
| 123 |
msg: 'covering first paragraph but empty in the second paragraph: only converts first paragraph' |
| 124 |
}, |
| 125 |
{ |
| 126 |
html: '<p>foo</p><p>bar</p>', |
| 127 |
rangeOrSelection: new ve.Range( 2 ), |
| 128 |
type: 'heading', |
| 129 |
attributes: { level: 2 }, |
| 130 |
expectedRangeOrSelection: new ve.Range( 2 ), |
| 131 |
expectedData: function ( data ) { |
| 132 |
data.splice( 0, 1, { type: 'heading', attributes: { level: 2 } } ); |
| 133 |
data.splice( 4, 1, { type: '/heading' } ); |
| 134 |
}, |
| 135 |
undo: true, |
| 136 |
msg: 'collapsed in paragraph' |
| 137 |
} |
| 138 |
]; |
| 139 |
|
| 140 |
cases.forEach( ( caseItem ) => { |
| 141 |
ve.test.utils.runActionTest( |
| 142 |
assert, |
| 143 |
{ |
| 144 |
actionName: 'format', |
| 145 |
method: 'convert', |
| 146 |
html: ve.dm.example.isolationHtml, |
| 147 |
args: [ caseItem.type, caseItem.attributes ], |
| 148 |
...caseItem |
| 149 |
} |
| 150 |
); |
| 151 |
} ); |
| 152 |
} ); |