2018-06-19 15:04:08 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MW-specific DiffElement tests.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see http://ve.mit-license.org
|
2018-06-19 15:04:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
QUnit.module( 've.ui.DiffElement (MW)', ve.test.utils.mwEnvironment );
|
|
|
|
|
2021-04-30 09:33:22 +00:00
|
|
|
QUnit.test( 'Diffing', ( assert ) => {
|
|
|
|
const fixBase = ( body ) =>
|
|
|
|
'<html><head><base href="' + ve.dm.example.baseUri + '"></head><body>' + body + '</body>',
|
2018-06-19 15:04:08 +00:00
|
|
|
cases = [
|
|
|
|
{
|
|
|
|
msg: 'Change template param',
|
|
|
|
oldDoc: fixBase( ve.dm.mwExample.MWTransclusion.blockOpen + ve.dm.mwExample.MWTransclusion.blockContent ),
|
|
|
|
newDoc: fixBase( ve.dm.mwExample.MWTransclusion.blockOpenModified + ve.dm.mwExample.MWTransclusion.blockContent ),
|
|
|
|
expected:
|
|
|
|
'<div class="ve-ui-diffElement-doc-child-change">' +
|
|
|
|
( ve.dm.mwExample.MWTransclusion.blockOpenModified + ve.dm.mwExample.MWTransclusion.blockContent )
|
2019-01-17 12:58:29 +00:00
|
|
|
// FIXME: Use DOM modification instead of string replaces
|
2018-06-19 15:04:08 +00:00
|
|
|
.replace( /#mwt1"/g, '#mwt1" data-diff-action="structural-change" data-diff-id="0"' ) +
|
|
|
|
'</div>',
|
|
|
|
expectedDescriptions: [
|
|
|
|
'<div>visualeditor-changedesc-mwtransclusion</div>' +
|
2021-01-22 17:35:36 +00:00
|
|
|
'<div><ul><li>visualeditor-changedesc-changed-diff,1,<span>Hello, <del>world</del><ins>globe</ins>!</span></li></ul></div>'
|
2018-06-19 15:04:08 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
msg: 'Changed width of block image',
|
|
|
|
oldDoc: fixBase( ve.dm.mwExample.MWBlockImage.html ),
|
|
|
|
newDoc: fixBase( ve.dm.mwExample.MWBlockImage.html.replace( 'width="1"', 'width="3"' ) ),
|
|
|
|
expected:
|
|
|
|
'<div class="ve-ui-diffElement-doc-child-change">' +
|
|
|
|
ve.dm.mwExample.MWBlockImage.html
|
2019-01-17 12:58:29 +00:00
|
|
|
// FIXME: Use DOM modification instead of string replaces
|
2018-06-19 15:04:08 +00:00
|
|
|
.replace( 'width="1"', 'width="3"' )
|
Parse relative hrefs on image nodes like on regular links (try 2)
Previous, reverted attempt: da9b6fffbdba9007cfe893b1eafd1ccb42dbb537.
This attempt also includes 6037fefbe044fbf61e7734923f3b625f10e910a1,
and fixes minor conflicts with other changes.
* In normal images, parse relative 'href' attributes instead of
expanding them to absolute. This resolves Parsoid generating
|link= options for copy-pasted images (T193253).
Keep them in the underscore-form to avoid causing dirty diffs like
T237040 again. Unlike in the previous attempt, we don't need to be
super-careful about the 'resource' attribute, thanks to the Parsoid
changes in T108504.
* In gallery images stuff, prefix the 'resource' attribute with './',
same as normal images do. This causes no functional changes, but it
makes updating tests easier, and the consistency is probably good.
* Update test examples to also prefix 'resource' and relative 'href'
attributes with './', like the real Parsoid does.
Bug: T193253
Change-Id: I91131728a87c9406bf069d46d3c94c9a8905a003
2019-09-10 18:57:05 +00:00
|
|
|
.replace( 'href="./Foo"', 'href="' + ve.resolveUrl( './Foo', ve.dm.example.base ) + '"' )
|
2018-06-19 15:04:08 +00:00
|
|
|
.replace( 'foobar"', 'foobar" data-diff-action="structural-change" data-diff-id="0"' ) +
|
|
|
|
'</div>',
|
|
|
|
expectedDescriptions: [
|
|
|
|
'<div>visualeditor-changedesc-image-size,' +
|
|
|
|
'<del>1visualeditor-dimensionswidget-times2visualeditor-dimensionswidget-px</del>,' +
|
|
|
|
'<ins>3visualeditor-dimensionswidget-times2visualeditor-dimensionswidget-px</ins></div>'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2021-04-29 14:42:18 +00:00
|
|
|
for ( let i = 0; i < cases.length; i++ ) {
|
2018-06-19 15:04:08 +00:00
|
|
|
ve.test.utils.runDiffElementTest( assert, cases[ i ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
} );
|