/*! * VisualEditor MediaWiki-specific ContentEditable Surface tests. * * @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt * @license The MIT License (MIT); see LICENSE.txt */ QUnit.module( 've.ce.Surface (MW)', ve.test.utils.mwEnvironment ); /* Tests */ QUnit.test( 'handleLinearDelete', function ( assert ) { const done = assert.async(), blocklength = ve.dm.mwExample.MWBlockImage.data.length, cases = [ // This asserts that getRelativeRange (via getRelativeOffset) doesn't try to // enter a handleOwnChildren node { htmlOrDoc: ve.dm.mwExample.MWBlockImage.html + '', rangeOrSelection: new ve.Range( blocklength + 3 ), keys: [ 'BACKSPACE' ], expectedData: function ( data ) { // remove the first list item, and replace its wrapped paragraph outside // the start of the list data.splice( blocklength, 8, { type: 'paragraph' }, 'F', 'o', 'o', { type: '/paragraph' }, { type: 'list', attributes: { style: 'bullet' } } ); }, expectedRangeOrSelection: new ve.Range( blocklength + 1 ), msg: 'Backspace in a list next to a block image doesn\'t merge into the caption' }, { htmlOrDoc: ve.dm.mwExample.MWBlockImage.html + '', rangeOrSelection: new ve.Range( blocklength + 3 ), keys: [ 'BACKSPACE' ], expectedData: function ( data ) { data.splice( blocklength, 6, { type: 'paragraph' }, { type: '/paragraph' } ); }, expectedRangeOrSelection: new ve.Range( blocklength + 1 ), msg: 'Backspace in an empty list next to a block image removes the list' } ]; let promise = Promise.resolve(); cases.forEach( function ( caseItem ) { promise = promise.then( function () { return ve.test.utils.runSurfaceHandleSpecialKeyTest( assert, caseItem ); } ); } ); promise.finally( function () { done(); } ); } ); QUnit.test( 'beforePaste/afterPaste', function ( assert ) { const cases = [ { documentHtml: '

', rangeOrSelection: new ve.Range( 1 ), pasteHtml: '--', fromVe: true, expectedRangeOrSelection: new ve.Range( 5 ), expectedHtml: '

--

', msg: 'RESTBase IDs stripped' }, { documentHtml: '

', rangeOrSelection: new ve.Range( 1 ), pasteHtml: '--', pasteTargetHtml: '--', fromVe: true, expectedRangeOrSelection: new ve.Range( 5 ), expectedHtml: '

--

', msg: 'RESTBase IDs still stripped if used when important attributes dropped' }, { documentHtml: '

', rangeOrSelection: new ve.Range( 1 ), pasteHtml: 'a[1]b', expectedRangeOrSelection: new ve.Range( 3 ), expectedHtml: '

ab

', msg: 'Read mode references stripped' }, { documentHtml: '

', rangeOrSelection: new ve.Range( 1 ), pasteHtml: 'a[1]b', expectedRangeOrSelection: new ve.Range( 5 ), expectedHtml: '

a[1]b

', msg: 'VE references not stripped' } ]; cases.forEach( ve.test.utils.runSurfacePasteTest.bind( this, assert ) ); } );