| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
QUnit.module( 've.dm.SurfaceFragment (MW)', ve.test.utils.newMwEnvironment() ); |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
QUnit.test( 'isolateAndUnwrap (MWheading)', ( assert ) => { |
| 13 |
const cases = [ |
| 14 |
{ |
| 15 |
type: 'mwHeading', |
| 16 |
range: new ve.Range( 12, 20 ), |
| 17 |
expected: ( data ) => { |
| 18 |
data.splice( 11, 0, { type: '/list' } ); |
| 19 |
data.splice( 12, 1 ); |
| 20 |
data.splice( 20, 1, { type: 'list', attributes: { style: 'bullet' } } ); |
| 21 |
}, |
| 22 |
base: ve.dm.mwExample.baseUri, |
| 23 |
msg: 'isolating paragraph in list item "Item 2" for MWheading' |
| 24 |
}, |
| 25 |
{ |
| 26 |
type: 'mwHeading', |
| 27 |
range: new ve.Range( 202, 212 ), |
| 28 |
expected: ( data ) => { |
| 29 |
data.splice( 201, 1, |
| 30 |
{ type: '/list' }, { type: '/listItem' }, { type: '/list' } |
| 31 |
); |
| 32 |
data.splice( 214, 1, |
| 33 |
{ type: 'list', attributes: { style: 'bullet' } }, |
| 34 |
{ type: 'listItem' }, |
| 35 |
{ type: 'list', attributes: { style: 'number' } } |
| 36 |
); |
| 37 |
}, |
| 38 |
base: ve.dm.mwExample.baseUri, |
| 39 |
msg: 'isolating paragraph in list item "Nested 2" for MWheading' |
| 40 |
} |
| 41 |
]; |
| 42 |
cases.forEach( ( caseItem ) => ve.test.utils.runIsolateTest( assert, caseItem ) ); |
| 43 |
} ); |
| 44 |
|
| 45 |
QUnit.test( 'insertContent (MWheading)', ( assert ) => { |
| 46 |
const doc = new ve.dm.Document( [ |
| 47 |
{ type: 'list', attributes: { style: 'bullet' } }, |
| 48 |
{ type: 'listItem' }, |
| 49 |
{ type: 'paragraph' }, |
| 50 |
...'ab', |
| 51 |
{ type: '/paragraph' }, |
| 52 |
{ type: '/listItem' }, |
| 53 |
{ type: '/list' }, |
| 54 |
{ type: 'internalList' }, |
| 55 |
{ type: '/internalList' } |
| 56 |
] ), |
| 57 |
surface = new ve.dm.Surface( doc ), |
| 58 |
headingData = [ { type: 'mwHeading', attributes: { level: 3 } }, 'x', { type: '/mwHeading' } ]; |
| 59 |
|
| 60 |
let fragment = surface.getLinearFragment( new ve.Range( 4, 4 ) ); |
| 61 |
fragment.insertContent( headingData ); |
| 62 |
assert.deepEqual( |
| 63 |
doc.getData( new ve.Range( 3, 14 ) ), |
| 64 |
[ |
| 65 |
'a', |
| 66 |
{ type: '/paragraph' }, |
| 67 |
{ type: '/listItem' }, |
| 68 |
{ type: '/list' }, |
| 69 |
{ type: 'mwHeading', attributes: { level: 3 } }, |
| 70 |
'x', |
| 71 |
{ type: '/mwHeading' }, |
| 72 |
{ type: 'list', attributes: { style: 'bullet' } }, |
| 73 |
{ type: 'listItem' }, |
| 74 |
{ type: 'paragraph' }, |
| 75 |
'b' |
| 76 |
], |
| 77 |
'inserting a mwheading into a listitem should isolate it from the list' |
| 78 |
); |
| 79 |
|
| 80 |
surface.undo(); |
| 81 |
fragment = surface.getLinearFragment( new ve.Range( 8, 8 ) ); |
| 82 |
fragment.insertContent( headingData ); |
| 83 |
assert.deepEqual( |
| 84 |
doc.getData( new ve.Range( 7, 11 ) ), |
| 85 |
[ |
| 86 |
{ type: '/list' }, |
| 87 |
{ type: 'mwHeading', attributes: { level: 3 } }, |
| 88 |
'x', |
| 89 |
{ type: '/mwHeading' } |
| 90 |
], |
| 91 |
'inserting a mwheading to the document root should not add any extra closing elements' |
| 92 |
); |
| 93 |
} ); |