2013-10-05 10:27:39 +00:00
|
|
|
/*!
|
2017-06-22 19:55:28 +00:00
|
|
|
* VisualEditor MediaWiki-specific ContentEditable Surface tests.
|
2013-10-05 10:27:39 +00:00
|
|
|
*
|
2018-01-03 00:54:47 +00:00
|
|
|
* @copyright 2011-2018 VisualEditor Team and others; see AUTHORS.txt
|
2013-10-05 10:27:39 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2015-05-17 09:37:34 +00:00
|
|
|
QUnit.module( 've.ce.Surface (MW)', ve.test.utils.mwEnvironment );
|
2013-10-05 10:27:39 +00:00
|
|
|
|
|
|
|
/* Tests */
|
|
|
|
|
2014-10-10 09:20:35 +00:00
|
|
|
QUnit.test( 'handleLinearDelete', function ( assert ) {
|
2018-10-23 18:49:34 +00:00
|
|
|
var done = assert.async(),
|
|
|
|
promise = Promise.resolve(),
|
2013-12-02 14:05:24 +00:00
|
|
|
blocklength = ve.dm.mwExample.MWBlockImage.data.length,
|
2013-10-05 10:27:39 +00:00
|
|
|
cases = [
|
2014-09-18 20:15:24 +00:00
|
|
|
// This asserts that getRelativeRange (via getRelativeOffset) doesn't try to
|
|
|
|
// enter a handleOwnChildren node
|
2013-12-03 17:28:04 +00:00
|
|
|
{
|
2016-03-22 14:38:33 +00:00
|
|
|
htmlOrDoc:
|
2013-12-03 17:28:04 +00:00
|
|
|
ve.dm.mwExample.MWBlockImage.html +
|
|
|
|
'<ul><li><p>Foo</p></li><li><p>Bar</p></li></ul>',
|
2016-03-22 14:38:33 +00:00
|
|
|
rangeOrSelection: new ve.Range( blocklength + 3 ),
|
|
|
|
keys: [ 'BACKSPACE' ],
|
2013-12-02 14:05:24 +00:00
|
|
|
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' } }
|
|
|
|
);
|
|
|
|
},
|
2016-03-22 14:38:33 +00:00
|
|
|
expectedRangeOrSelection: new ve.Range( blocklength + 1 ),
|
2014-08-22 20:50:48 +00:00
|
|
|
msg: 'Backspace in a list next to a block image doesn\'t merge into the caption'
|
2013-12-02 14:05:24 +00:00
|
|
|
},
|
|
|
|
{
|
2016-03-22 14:38:33 +00:00
|
|
|
htmlOrDoc:
|
2013-12-02 14:05:24 +00:00
|
|
|
ve.dm.mwExample.MWBlockImage.html +
|
|
|
|
'<ul><li><p></p></li></ul>',
|
2016-03-22 14:38:33 +00:00
|
|
|
rangeOrSelection: new ve.Range( blocklength + 3 ),
|
|
|
|
keys: [ 'BACKSPACE' ],
|
2013-12-02 14:05:24 +00:00
|
|
|
expectedData: function ( data ) {
|
|
|
|
data.splice(
|
|
|
|
blocklength, 6,
|
|
|
|
{ type: 'paragraph' },
|
|
|
|
{ type: '/paragraph' }
|
|
|
|
);
|
|
|
|
},
|
2016-03-22 14:38:33 +00:00
|
|
|
expectedRangeOrSelection: new ve.Range( blocklength + 1 ),
|
2013-12-02 14:05:24 +00:00
|
|
|
msg: 'Backspace in an empty list next to a block image removes the list'
|
2013-10-05 10:27:39 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2018-10-23 18:49:34 +00:00
|
|
|
cases.forEach( function ( caseItem ) {
|
|
|
|
promise = promise.then( function () {
|
|
|
|
return ve.test.utils.runSurfaceHandleSpecialKeyTest( assert, caseItem );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2018-10-29 23:19:16 +00:00
|
|
|
promise.finally( function () {
|
|
|
|
done();
|
|
|
|
} );
|
2013-10-05 10:27:39 +00:00
|
|
|
} );
|
2016-10-11 19:48:02 +00:00
|
|
|
|
|
|
|
QUnit.test( 'beforePaste/afterPaste', function ( assert ) {
|
2017-04-28 15:48:52 +00:00
|
|
|
var i,
|
2016-10-11 19:48:02 +00:00
|
|
|
cases = [
|
|
|
|
{
|
|
|
|
documentHtml: '<p></p>',
|
|
|
|
rangeOrSelection: new ve.Range( 1 ),
|
|
|
|
pasteHtml: '<span typeof="mw:Entity" id="mwAB">-</span><span typeof="mw:Entity" id="mw-reference-cite">-</span>',
|
|
|
|
fromVe: true,
|
|
|
|
expectedRangeOrSelection: new ve.Range( 5 ),
|
|
|
|
expectedHtml: '<p><span typeof="mw:Entity">-</span><span typeof="mw:Entity" id="mw-reference-cite">-</span></p>',
|
|
|
|
msg: 'RESTBase IDs stripped'
|
2018-09-03 14:24:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
documentHtml: '<p></p>',
|
|
|
|
rangeOrSelection: new ve.Range( 1 ),
|
|
|
|
pasteHtml: '<span typeof="mw:Entity" id="mwAB">-</span><span typeof="mw:Entity" id="mw-reference-cite">-</span>',
|
|
|
|
pasteTargetHtml: '<span>-</span><span>-</span>',
|
|
|
|
fromVe: true,
|
|
|
|
expectedRangeOrSelection: new ve.Range( 5 ),
|
|
|
|
expectedHtml: '<p><span typeof="mw:Entity">-</span><span typeof="mw:Entity" id="mw-reference-cite">-</span></p>',
|
|
|
|
msg: 'RESTBase IDs still stripped if used when important attributes dropped'
|
2016-10-11 19:48:02 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
for ( i = 0; i < cases.length; i++ ) {
|
|
|
|
ve.test.utils.runSurfacePasteTest(
|
2018-04-13 18:33:43 +00:00
|
|
|
/* assert */ assert,
|
|
|
|
/* htmlOrView */ cases[ i ].documentHtml,
|
|
|
|
/* pasteData */
|
|
|
|
{
|
2018-04-05 23:58:31 +00:00
|
|
|
'text/html': cases[ i ].pasteHtml,
|
|
|
|
'text/plain': cases[ i ].pasteText
|
2018-04-13 18:33:43 +00:00
|
|
|
},
|
|
|
|
/* internalSourceRangeOrSelection */ cases[ i ].internalSourceRangeOrSelection,
|
|
|
|
/* noClipboardData */ cases[ i ].noClipboardData,
|
|
|
|
/* fromVe */ cases[ i ].fromVe,
|
|
|
|
/* useClipboardData */ cases[ i ].useClipboardData,
|
|
|
|
/* pasteTargetHtml */ cases[ i ].pasteTargetHtml,
|
|
|
|
/* rangeOrSelection */ cases[ i ].rangeOrSelection,
|
|
|
|
/* pasteSpecial */ cases[ i ].pasteSpecial,
|
|
|
|
/* expectedOps */ cases[ i ].expectedOps,
|
|
|
|
/* expectedRangeOrSelection */ cases[ i ].expectedRangeOrSelection,
|
|
|
|
/* expectedHtml */ cases[ i ].expectedHtml,
|
|
|
|
/* expectedDefaultPrevented */ cases[ i ].expectedDefaultPrevented,
|
|
|
|
/* store */ cases[ i ].store,
|
|
|
|
/* msg */ cases[ i ].msg
|
2016-10-11 19:48:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} );
|