mediawiki-extensions-Visual.../modules/ve-mw/tests/dm/ve.dm.SurfaceFragment.test.js
David Lynch 7e678dc81a Update VE core submodule to master (b528a5321)
New changes:
44d2d666c Remove custom icon sizing from block slugs
793d131f9 Ignore covering annotations when looking for plain text pastes
b0025f3ab dm.Document fixupInsertion: check suggestedParents as well
73ce638f1 ve.ui.TableLineContext: Fancier popups
9d54d531e Visual Diff: add internal list diff
4f4e121b5 DiffElement: Add hacky support for template-defined references

Local changes:

dm.SurfaceFragment tests: exercise fixupInsertion for mwHeadings

Core VE doesn't have any elements with suggestedParents, so make sure this is
properly tested.

Bug: T153315
Bug: T162819
Bug: T164017
Bug: T165865
Change-Id: I01489226d282abe71020e65358ead24fe07692f7
2017-06-28 20:57:19 +01:00

79 lines
2.4 KiB
JavaScript

/*!
* VisualEditor DataModel MediaWiki-specific SurfaceFragment tests.
*
* @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
QUnit.module( 've.dm.SurfaceFragment (MW)', ve.test.utils.mwEnvironment );
/* Tests */
QUnit.test( 'isolateAndUnwrap (MWheading)', function ( assert ) {
ve.test.utils.runIsolateTest( assert, 'mwHeading', new ve.Range( 12, 20 ), function ( data ) {
data.splice( 11, 0, { type: '/list' } );
data.splice( 12, 1 );
data.splice( 20, 1, { type: 'list', attributes: { style: 'bullet' } } );
}, 'isolating paragraph in list item "Item 2" for MWheading' );
ve.test.utils.runIsolateTest( assert, 'mwHeading', new ve.Range( 202, 212 ), function ( 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' } }
);
}, 'isolating paragraph in list item "Nested 2" for MWheading' );
} );
QUnit.test( 'insertContent (MWheading)', function ( assert ) {
var doc = new ve.dm.Document( [
{ type: 'list', attributes: { style: 'bullet' } },
{ type: 'listItem' },
{ type: 'paragraph' },
'a',
'b',
{ type: '/paragraph' },
{ type: '/listItem' },
{ type: '/list' }
] ),
surface = new ve.dm.Surface( doc ),
fragment = surface.getLinearFragment( new ve.Range( 4, 4 ) ),
headingData = [ { type: 'mwHeading', attributes: { level: 3 } }, 'x', { type: '/mwHeading' } ];
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'
);
} );