/*! * VisualEditor MediaWiki-specific ContentEditable Surface tests. * * @copyright See AUTHORS.txt * @license The MIT License (MIT); see LICENSE.txt */ QUnit.module( 've.ce.Surface (MW)', ve.test.utils.newMwEnvironment() ); /* Tests */ QUnit.test( 'beforePaste/afterPaste', ( 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: '--', clipboardHandlerHtml: '--', 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' }, { documentHtml: '

', rangeOrSelection: new ve.Range( 1 ), pasteHtml: 'Lorem ipsum dolor sit amet', expectedRangeOrSelection: new ve.Range( 27 ), // hrefs with invalid protocols get removed by DOMPurify, and these links become spans in // ve.dm.LinkAnnotation.static.toDataElement (usually the span is stripped later) expectedHtml: '

Lorem ipsum dolor sit amet

', config: { importRules: { external: { blacklist: { 'link/mwExternal': true } } } }, msg: 'External links stripped' }, { documentHtml: '

', rangeOrSelection: new ve.Range( 1 ), pasteHtml: 'Lorem ipsum dolor sit amet', expectedRangeOrSelection: new ve.Range( 27 ), // hrefs with invalid protocols get removed by DOMPurify, and these links become spans in // ve.dm.LinkAnnotation.static.toDataElement (usually the span is stripped later) expectedHtml: '

Lorem ipsum dolor sit amet

', config: { importRules: { external: { blacklist: { 'link/mwExternal': false } } } }, msg: 'External links not stripped, but only some protocols allowed' } ]; const done = assert.async(); ( async function () { for ( const caseItem of cases ) { await ve.test.utils.runSurfacePasteTest( assert, caseItem ); } done(); }() ); } );