mediawiki-extensions-Visual.../modules/ve-mw/tests/ce/ve.ce.Surface.test.js

133 lines
4.7 KiB
JavaScript
Raw Normal View History

/*!
* VisualEditor MediaWiki-specific ContentEditable Surface tests.
*
* @copyright 2011-2019 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 ) {
Update VE core submodule to master (6c288b44f) New changes: 7c9fe89b8 Simplify ve.test.utils.runSurfaceHandleSpecialKeyTest API 0e3c75e66 Add more tests to LinearArrowKeyDownHandler 058362830 LinearArrowKeyDownHandler: Test Selection#extend fallback 8c6617d90 Keydown test refactor 91a909d63 Assert defaultPrevented state in KeyDown tests 003dacf3b LinearDeleteKeyDownHandler: Test shift+delete 1872158c5 LinearDeleteKeyDownHandler: Test delete next to link b2af2a2c3 LinearEnterKeyDownHandler: Add more tests 4e5efa956 KeyDownTests: Remove unused constructor calls for all static classes 1cafb7328 KeyDown tests: Add tests for missing cases to cover tab/escape/enter 58af8d497 Add tests for ve.ce.AnnotationFactory/NodeFactory 617bc24a4 Delete unused ve.ce.modelChangeFromContentChange 50704fa1c Keydown tests: run asynchronously af9a01b97 Use native promises instead of jQuery promises df212669a Localisation updates from https://translatewiki.net. f6af901dc Fix test in Chrome 70 9cc6dae7e Remove broken checks for DM code coverage ce3a9199a LinearEnterKeyDownHandler: Add test for edge case 0a9dd3636 Remove false coverage of TableNode/TableSelection code 16679a3c0 Remove setupToolbar from DummyTarget to avoid false code coverage 7ac88df77 Basic tests for getClientRects in ve.ce.Selection and FocusableNode 78f14ac1f ve.ce.Selection: Add getDirection tests 7ec7efff0 KeyDown tests: Remove unnecessary setTimeout 26e022d23 KeyDown tests: Un-nest functions df1e0af6c KeyDown tests: rename defer -> then f03a9f90b Allow ES6 in tests 0ee55022b ES6 eslint follow-up 6c288b44f ve.ce.Surface tests: Trim when asserting expected text Local changes. Bug: T207077 Bug: T207078 Bug: T207079 Bug: T207080 Bug: T207083 Bug: T207654 Change-Id: I2e1f664d6f657e2ac26a271f401dc790c2a8b193
2018-10-23 18:49:34 +00:00
var done = assert.async(),
promise = Promise.resolve(),
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 +
'<ul><li><p>Foo</p></li><li><p>Bar</p></li></ul>',
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 +
'<ul><li><p></p></li></ul>',
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'
}
];
Update VE core submodule to master (6c288b44f) New changes: 7c9fe89b8 Simplify ve.test.utils.runSurfaceHandleSpecialKeyTest API 0e3c75e66 Add more tests to LinearArrowKeyDownHandler 058362830 LinearArrowKeyDownHandler: Test Selection#extend fallback 8c6617d90 Keydown test refactor 91a909d63 Assert defaultPrevented state in KeyDown tests 003dacf3b LinearDeleteKeyDownHandler: Test shift+delete 1872158c5 LinearDeleteKeyDownHandler: Test delete next to link b2af2a2c3 LinearEnterKeyDownHandler: Add more tests 4e5efa956 KeyDownTests: Remove unused constructor calls for all static classes 1cafb7328 KeyDown tests: Add tests for missing cases to cover tab/escape/enter 58af8d497 Add tests for ve.ce.AnnotationFactory/NodeFactory 617bc24a4 Delete unused ve.ce.modelChangeFromContentChange 50704fa1c Keydown tests: run asynchronously af9a01b97 Use native promises instead of jQuery promises df212669a Localisation updates from https://translatewiki.net. f6af901dc Fix test in Chrome 70 9cc6dae7e Remove broken checks for DM code coverage ce3a9199a LinearEnterKeyDownHandler: Add test for edge case 0a9dd3636 Remove false coverage of TableNode/TableSelection code 16679a3c0 Remove setupToolbar from DummyTarget to avoid false code coverage 7ac88df77 Basic tests for getClientRects in ve.ce.Selection and FocusableNode 78f14ac1f ve.ce.Selection: Add getDirection tests 7ec7efff0 KeyDown tests: Remove unnecessary setTimeout 26e022d23 KeyDown tests: Un-nest functions df1e0af6c KeyDown tests: rename defer -> then f03a9f90b Allow ES6 in tests 0ee55022b ES6 eslint follow-up 6c288b44f ve.ce.Surface tests: Trim when asserting expected text Local changes. Bug: T207077 Bug: T207078 Bug: T207079 Bug: T207080 Bug: T207083 Bug: T207654 Change-Id: I2e1f664d6f657e2ac26a271f401dc790c2a8b193
2018-10-23 18:49:34 +00:00
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 ) {
var i,
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'
},
{
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'
},
{
documentHtml: '<p></p>',
rangeOrSelection: new ve.Range( 1 ),
pasteHtml: 'a<sup id="cite_ref-1" class="reference"><a href="./Article#cite_note-1">[1]</a></sup>b',
expectedRangeOrSelection: new ve.Range( 3 ),
expectedHtml: '<p>ab</p>',
msg: 'Read mode references stripped'
},
{
documentHtml: '<p></p>',
rangeOrSelection: new ve.Range( 1 ),
pasteHtml: 'a<sup typeof="mw:Extension/ref" data-mw="{}" class="mw-ref" about="#mwt1" id="cite_ref-foo-0" rel="dc:references"><a href="./Article#cite_note-foo-0"><span class="mw-reflink-text ve-pasteProtect">[1]</span></a></sup>b',
expectedRangeOrSelection: new ve.Range( 5 ),
expectedHtml: '<p>a<sup typeof="mw:Extension/ref" data-mw="{&quot;name&quot;:&quot;ref&quot;}" class="mw-ref"><a style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup>b</p>',
msg: 'VE references not stripped'
}
];
for ( i = 0; i < cases.length; i++ ) {
ve.test.utils.runSurfacePasteTest(
/* assert */ assert,
/* htmlOrView */ cases[ i ].documentHtml,
/* pasteData */
{
'text/html': cases[ i ].pasteHtml,
'text/plain': cases[ i ].pasteText
},
/* 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
);
}
} );