2013-07-03 01:30:10 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MediaWiki-specific SurfaceFragment tests.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2013-07-03 01:30:10 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2022-03-04 13:48:14 +00:00
|
|
|
QUnit.module( 've.dm.SurfaceFragment (MW)', ve.test.utils.newMwEnvironment() );
|
2013-07-03 01:30:10 +00:00
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
2021-04-30 09:33:22 +00:00
|
|
|
QUnit.test( 'isolateAndUnwrap (MWheading)', ( assert ) => {
|
2024-05-17 14:46:05 +00:00
|
|
|
const cases = [
|
|
|
|
{
|
|
|
|
type: 'mwHeading',
|
|
|
|
range: new ve.Range( 12, 20 ),
|
|
|
|
expected: ( data ) => {
|
|
|
|
data.splice( 11, 0, { type: '/list' } );
|
|
|
|
data.splice( 12, 1 );
|
|
|
|
data.splice( 20, 1, { type: 'list', attributes: { style: 'bullet' } } );
|
|
|
|
},
|
|
|
|
base: ve.dm.mwExample.baseUri,
|
|
|
|
msg: 'isolating paragraph in list item "Item 2" for MWheading'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'mwHeading',
|
|
|
|
range: new ve.Range( 202, 212 ),
|
|
|
|
expected: ( data ) => {
|
|
|
|
data.splice( 201, 1,
|
|
|
|
{ type: '/list' }, { type: '/listItem' }, { type: '/list' }
|
|
|
|
);
|
|
|
|
data.splice( 214, 1,
|
|
|
|
{ type: 'list', attributes: { style: 'bullet' } },
|
|
|
|
{ type: 'listItem' },
|
|
|
|
{ type: 'list', attributes: { style: 'number' } }
|
|
|
|
);
|
|
|
|
},
|
|
|
|
base: ve.dm.mwExample.baseUri,
|
|
|
|
msg: 'isolating paragraph in list item "Nested 2" for MWheading'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
cases.forEach( ( caseItem ) => ve.test.utils.runIsolateTest( assert, caseItem ) );
|
2013-07-03 01:30:10 +00:00
|
|
|
} );
|
2017-06-28 15:48:38 +00:00
|
|
|
|
2021-04-30 09:33:22 +00:00
|
|
|
QUnit.test( 'insertContent (MWheading)', ( assert ) => {
|
2021-04-29 14:42:18 +00:00
|
|
|
const doc = new ve.dm.Document( [
|
2017-06-28 15:48:38 +00:00
|
|
|
{ type: 'list', attributes: { style: 'bullet' } },
|
|
|
|
{ type: 'listItem' },
|
|
|
|
{ type: 'paragraph' },
|
2024-05-24 21:23:42 +00:00
|
|
|
...'ab',
|
2017-06-28 15:48:38 +00:00
|
|
|
{ type: '/paragraph' },
|
|
|
|
{ type: '/listItem' },
|
2019-12-20 11:58:09 +00:00
|
|
|
{ type: '/list' },
|
|
|
|
{ type: 'internalList' },
|
|
|
|
{ type: '/internalList' }
|
2017-06-28 15:48:38 +00:00
|
|
|
] ),
|
|
|
|
surface = new ve.dm.Surface( doc ),
|
|
|
|
headingData = [ { type: 'mwHeading', attributes: { level: 3 } }, 'x', { type: '/mwHeading' } ];
|
|
|
|
|
2021-04-29 14:42:18 +00:00
|
|
|
let fragment = surface.getLinearFragment( new ve.Range( 4, 4 ) );
|
2017-06-28 15:48:38 +00:00
|
|
|
fragment.insertContent( headingData );
|
|
|
|
assert.deepEqual(
|
|
|
|
doc.getData( new ve.Range( 3, 14 ) ),
|
|
|
|
[
|
|
|
|
'a',
|
|
|
|
{ type: '/paragraph' },
|
|
|
|
{ type: '/listItem' },
|
|
|
|
{ type: '/list' },
|
|
|
|
{ type: 'mwHeading', attributes: { level: 3 } },
|
|
|
|
'x',
|
|
|
|
{ type: '/mwHeading' },
|
|
|
|
{ type: 'list', attributes: { style: 'bullet' } },
|
|
|
|
{ type: 'listItem' },
|
|
|
|
{ type: 'paragraph' },
|
|
|
|
'b'
|
|
|
|
],
|
|
|
|
'inserting a mwheading into a listitem should isolate it from the list'
|
|
|
|
);
|
|
|
|
|
|
|
|
surface.undo();
|
|
|
|
fragment = surface.getLinearFragment( new ve.Range( 8, 8 ) );
|
|
|
|
fragment.insertContent( headingData );
|
|
|
|
assert.deepEqual(
|
|
|
|
doc.getData( new ve.Range( 7, 11 ) ),
|
|
|
|
[
|
|
|
|
{ type: '/list' },
|
|
|
|
{ type: 'mwHeading', attributes: { level: 3 } },
|
|
|
|
'x',
|
|
|
|
{ type: '/mwHeading' }
|
|
|
|
],
|
|
|
|
'inserting a mwheading to the document root should not add any extra closing elements'
|
|
|
|
);
|
|
|
|
} );
|