2013-07-03 01:30:10 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MediaWiki-specific SurfaceFragment tests.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; 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' },
|
|
|
|
'a',
|
|
|
|
'b',
|
|
|
|
{ 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'
|
|
|
|
);
|
|
|
|
} );
|