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 ) => {
|
|
|
|
ve.test.utils.runIsolateTest( assert, 'mwHeading', new ve.Range( 12, 20 ), ( data ) => {
|
2014-08-22 20:50:48 +00:00
|
|
|
data.splice( 11, 0, { type: '/list' } );
|
2013-07-03 01:30:10 +00:00
|
|
|
data.splice( 12, 1 );
|
2014-08-22 20:50:48 +00:00
|
|
|
data.splice( 20, 1, { type: 'list', attributes: { style: 'bullet' } } );
|
2023-01-21 17:00:26 +00:00
|
|
|
}, ve.dm.mwExample.baseUri, 'isolating paragraph in list item "Item 2" for MWheading' );
|
2013-07-03 01:30:10 +00:00
|
|
|
|
2021-04-30 09:33:22 +00:00
|
|
|
ve.test.utils.runIsolateTest( assert, 'mwHeading', new ve.Range( 202, 212 ), ( data ) => {
|
2013-07-03 01:30:10 +00:00
|
|
|
data.splice( 201, 1,
|
2014-08-22 20:50:48 +00:00
|
|
|
{ type: '/list' }, { type: '/listItem' }, { type: '/list' }
|
2013-07-03 01:30:10 +00:00
|
|
|
);
|
|
|
|
data.splice( 214, 1,
|
2014-08-22 20:50:48 +00:00
|
|
|
{ type: 'list', attributes: { style: 'bullet' } },
|
|
|
|
{ type: 'listItem' },
|
|
|
|
{ type: 'list', attributes: { style: 'number' } }
|
2013-07-03 01:30:10 +00:00
|
|
|
);
|
2023-01-21 17:00:26 +00:00
|
|
|
}, ve.dm.mwExample.baseUri, 'isolating paragraph in list item "Nested 2" for MWheading' );
|
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'
|
|
|
|
);
|
|
|
|
} );
|