Revert "Revert "Follow-up I38eda4a: Add unit tests for lang/dir in target init""

Re-enable tests, but disable setEditorPreference API calls in setup.

This reverts commit d5fe71fd6e.

Change-Id: Ib6f0f18acc1ccb40cb6c055609dc1484b381bc8f
This commit is contained in:
Esanders 2018-09-04 12:28:50 +00:00 committed by Ed Sanders
parent 8ac5a03a05
commit a21e95b67a
2 changed files with 87 additions and 0 deletions

View file

@ -7,6 +7,89 @@
QUnit.module( 've.init.mw.DesktopArticleTarget', ve.test.utils.mwEnvironment );
QUnit.test( 'init', function ( assert ) {
var
response = {
visualeditor: {
result: 'success',
notices: [],
checkboxesDef: {
wpMinoredit: {
id: 'wpMinoredit',
'label-message': 'minoredit',
tooltip: 'minoredit',
'label-id': 'mw-editpage-minoredit',
'legacy-name': 'minor',
'default': false
},
wpWatchthis: {
id: 'wpWatchthis',
'label-message': 'watchthis',
tooltip: 'watch',
'label-id': 'mw-editpage-watch',
'legacy-name': 'watch',
'default': true
}
},
checkboxesMessages: {
'accesskey-minoredit': 'i',
'tooltip-minoredit': 'Mark this as a minor edit',
minoredit: 'This is a minor edit',
'accesskey-watch': 'w',
'tooltip-watch': 'Add this page to your watchlist',
watchthis: 'Watch this page'
},
templates: '<div class="templatesUsed"></div>',
links: {
missing: [],
known: 1
},
protectedClasses: '',
basetimestamp: '20161119005107',
starttimestamp: '20180831122319',
oldid: 1804,
content: '<!DOCTYPE html>\n' +
'<html prefix="dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/" about="http://localhost/MediaWiki/core/index.php/Special:Redirect/revision/1804">' +
'<head prefix="mwr: http://localhost/MediaWiki/core/index.php/Special:Redirect/"><meta property="mw:TimeUuid" content="a4fc0409-ad18-11e8-9b45-dd8cefbedb6d"/>' +
'<meta charset="utf-8"/>' +
'<meta property="mw:pageNamespace" content="0"/>' +
'<meta property="mw:pageId" content="643"/>' +
'<link rel="dc:replaces" resource="mwr:revision/0"/>' +
'<meta property="dc:modified" content="2016-11-19T00:51:07.000Z"/>' +
'<meta property="mw:revisionSHA1" content="da39a3ee5e6b4b0d3255bfef95601890afd80709"/>' +
'<meta property="mw:html:version" content="1.7.0"/>' +
'<link rel="dc:isVersionOf" href="http://localhost/MediaWiki/core/index.php/Empty"/>' +
'<title>Empty</title>' +
'<base href="http://localhost/MediaWiki/core/index.php/"/>' +
'<link rel="stylesheet" href="//localhost/MediaWiki/core/load.php?modules=mediawiki.legacy.commonPrint%2Cshared%7Cmediawiki.skinning.content.parsoid%7Cmediawiki.skinning.interface%7Cskins.vector.styles%7Csite.styles%7Cext.cite.style%7Cext.cite.styles%7Cmediawiki.page.gallery.styles&amp;only=styles&amp;skin=vector"/><!--[if lt IE 9]><script src="//localhost/MediaWiki/core/load.php?modules=html5shiv&amp;only=scripts&amp;skin=vector&amp;sync=1"></script><script>html5.addElements(\'figure-inline\');</script><![endif]-->' +
'</head>' +
'<body id="mwAA" lang="he" class="mw-content-rtl sitedir-rtl rtl mw-body-content parsoid-body mediawiki mw-parser-output" dir="rtl">' +
'<section data-mw-section-id="0" id="mwAQ"></section>' +
'</body>' +
'</html>',
etag: '"1804/a4fc0409-ad18-11e8-9b45-dd8cefbedb6d"',
switched: false,
fromEditedState: false
}
},
target = new ve.init.mw.DesktopArticleTarget(),
dataPromise = $.Deferred().resolve( response ).promise(),
done = assert.async();
target.on( 'surfaceReady', function () {
assert.strictEqual( target.getSurface().getModel().getDocument().getLang(), 'he', 'Page language is passed through from config' );
assert.strictEqual( target.getSurface().getModel().getDocument().getDir(), 'rtl', 'Page direction is passed through from config' );
target.destroy();
mw.config.get( 'wgVisualEditor' ).pageLanguageCode = 'en';
mw.config.get( 'wgVisualEditor' ).pageLanguageDir = 'ltr';
done();
} );
mw.config.get( 'wgVisualEditor' ).pageLanguageCode = 'he';
mw.config.get( 'wgVisualEditor' ).pageLanguageDir = 'rtl';
mw.config.get( 'wgVisualEditorConfig' ).showBetaWelcome = false;
target.activate( dataPromise );
} );
QUnit.test( 'compatibility', function ( assert ) {
var i, profile, matches, compatibility,
cases = [

View file

@ -51,6 +51,8 @@
ve.test.utils.mwEnvironment = ( function () {
var mwPlatform, corePlatform, mwTarget, coreTarget,
setEditorPreference = mw.libs.ve.setEditorPreference,
dummySetEditorPreference = function () { return $.Deferred().resolve().promise(); },
overrides = [
ve.dm.MWHeadingNode,
ve.dm.MWPreformattedNode,
@ -82,6 +84,7 @@
}
ve.init.platform = mwPlatform;
ve.init.target = mwTarget;
mw.libs.ve.setEditorPreference = dummySetEditorPreference;
// Ensure the current target is appended to the current fixture
$( '#qunit-fixture' ).append( ve.init.target.$element );
}
@ -96,6 +99,7 @@
}
ve.init.platform = corePlatform;
ve.init.target = coreTarget;
mw.libs.ve.setEditorPreference = setEditorPreference;
}
// On load, teardown overrides so the first core tests run correctly