mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-11 05:56:11 +00:00
120 lines
3.9 KiB
JavaScript
120 lines
3.9 KiB
JavaScript
|
/* eslint-env node, es6 */
|
||
|
/* global seleniumUtils, langs */
|
||
|
|
||
|
( function () {
|
||
|
'use strict';
|
||
|
var createScreenshotEnvironment = require( './screenshots.js' ).createScreenshotEnvironment,
|
||
|
test = require( 'selenium-webdriver/testing' );
|
||
|
|
||
|
function runTests( lang ) {
|
||
|
var runScreenshotTest = createScreenshotEnvironment( test, lang, function () {
|
||
|
var done = arguments[ arguments.length - 1 ];
|
||
|
|
||
|
window.seleniumUtils.runDiffTest = function ( oldHtml, newHtml, done ) {
|
||
|
var target = ve.init.target,
|
||
|
surface = target.surface;
|
||
|
|
||
|
if ( target.saveDialog ) {
|
||
|
target.saveDialog.clearDiff();
|
||
|
target.saveDialog.close();
|
||
|
while ( surface.getModel().canUndo() ) {
|
||
|
surface.getModel().undo();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
target.originalDmDoc = target.createModelFromDom( target.parseDocument( oldHtml ), 'visual' );
|
||
|
|
||
|
surface.getModel().getDocument().getStore().merge( target.originalDmDoc.getStore() );
|
||
|
|
||
|
surface.getModel().getLinearFragment( new ve.Range( 0 ) ).insertDocument(
|
||
|
target.createModelFromDom( target.parseDocument( newHtml ), 'visual' )
|
||
|
).collapseToEnd().adjustLinearSelection( 0, 3 ).removeContent();
|
||
|
|
||
|
target.once( 'saveReview', function () {
|
||
|
setTimeout( function () {
|
||
|
var dialog = surface.dialogs.currentWindow;
|
||
|
dialog.reviewModeButtonSelect.selectItemByData( 'visual' );
|
||
|
|
||
|
// Fake parsed edit summary
|
||
|
dialog.$reviewEditSummary.text( '(Lorem ipsum)' );
|
||
|
|
||
|
done(
|
||
|
seleniumUtils.getBoundingRect( [
|
||
|
dialog.$frame[ 0 ]
|
||
|
] )
|
||
|
);
|
||
|
}, 500 );
|
||
|
} );
|
||
|
surface.execute( 'mwSaveDialog', 'review' );
|
||
|
};
|
||
|
|
||
|
done();
|
||
|
} );
|
||
|
|
||
|
test.describe( 'Screenshots: ' + lang, function () {
|
||
|
test.it( 'Simple diff', function () {
|
||
|
runScreenshotTest( 'VisualEditor_diff_simple',
|
||
|
// This function is converted to a string and executed in the browser
|
||
|
function () {
|
||
|
var done = arguments[ arguments.length - 1 ];
|
||
|
|
||
|
seleniumUtils.runDiffTest(
|
||
|
'<h2>Lorem ipsum</h2>' +
|
||
|
'<p>Lorem ipsum dolor sit <b>amet</b>, consectetur adipiscing elit.</p>',
|
||
|
'<h2>Lorem ipsum</h2>' +
|
||
|
'<p>Lorem ipsum dolor sit <i>amet</i>, consectetur adipiscing elit.</p>',
|
||
|
done
|
||
|
);
|
||
|
}
|
||
|
);
|
||
|
runScreenshotTest( 'VisualEditor_diff_move_and_change',
|
||
|
// This function is converted to a string and executed in the browser
|
||
|
function () {
|
||
|
var done = arguments[ arguments.length - 1 ];
|
||
|
|
||
|
seleniumUtils.runDiffTest(
|
||
|
'<h2>Lorem ipsum</h2>' +
|
||
|
'<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>' +
|
||
|
'<p>Maecenas fringilla turpis et nunc bibendum mattis.</p>',
|
||
|
'<h2>Lorem ipsum</h2>' +
|
||
|
'<p>Maecenas fringilla turpis et nunc bibendum mattis.</p>' +
|
||
|
'<p>Lorem ipsum dolor sit amat, consectetur adipiscing elit.</p>',
|
||
|
done
|
||
|
);
|
||
|
}
|
||
|
);
|
||
|
runScreenshotTest( 'VisualEditor_diff_link_change',
|
||
|
// This function is converted to a string and executed in the browser
|
||
|
function () {
|
||
|
var done = arguments[ arguments.length - 1 ];
|
||
|
|
||
|
seleniumUtils.runDiffTest(
|
||
|
'<h2>Lorem ipsum</h2>' +
|
||
|
'<p><a rel="mw:WikiLink" href="./Lipsum">Lorem ipsum</a> dolor sit amet, consectetur adipiscing elit.</p>',
|
||
|
'<h2>Lorem ipsum</h2>' +
|
||
|
'<p><a rel="mw:WikiLink" href="./Lorem ipsum">Lorem ipsum</a> dolor sit amet, consectetur adipiscing elit.</p>',
|
||
|
done
|
||
|
);
|
||
|
}
|
||
|
);
|
||
|
runScreenshotTest( 'VisualEditor_diff_list_change',
|
||
|
// This function is converted to a string and executed in the browser
|
||
|
function () {
|
||
|
var done = arguments[ arguments.length - 1 ];
|
||
|
|
||
|
seleniumUtils.runDiffTest(
|
||
|
'<ul><li>Lorem</li><li>ipsum</li><li>dolor</li><li>sit</li><li>amet</li></ul>',
|
||
|
'<ul><li>Lorem</li><li>ipsum</li><li>sit</li><li>amat</li></ul>',
|
||
|
done
|
||
|
);
|
||
|
}
|
||
|
);
|
||
|
} );
|
||
|
} );
|
||
|
}
|
||
|
|
||
|
for ( let i = 0, l = langs.length; i < l; i++ ) {
|
||
|
runTests( langs[ i ] );
|
||
|
}
|
||
|
}() );
|