2013-06-04 18:46:49 +00:00
|
|
|
/*!
|
2015-07-29 13:41:30 +00:00
|
|
|
* VisualEditor MediaWiki Initialization DesktopArticleTarget tests.
|
2013-06-04 18:46:49 +00:00
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2013-06-04 18:46:49 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2022-03-04 13:27:29 +00:00
|
|
|
QUnit.module( 've.init.mw.DesktopArticleTarget', ve.test.utils.newMwEnvironment( {
|
|
|
|
config: {
|
2022-03-04 13:48:14 +00:00
|
|
|
wgVisualEditor: ve.extendObject( {}, mw.config.get( 'wgVisualEditor' ), {
|
2022-03-04 13:27:29 +00:00
|
|
|
pageLanguageCode: 'he',
|
|
|
|
pageLanguageDir: 'rtl'
|
2022-03-04 13:48:14 +00:00
|
|
|
} ),
|
|
|
|
wgVisualEditorConfig: ve.extendObject( {}, mw.config.get( 'wgVisualEditorConfig' ), {
|
|
|
|
// Disable welcome dialog
|
|
|
|
showBetaWelcome: false
|
|
|
|
} ),
|
2022-03-04 13:27:29 +00:00
|
|
|
wgAction: 'view',
|
|
|
|
wgNamespaceNumber: 0,
|
|
|
|
wgCanonicalNamespace: ''
|
|
|
|
}
|
|
|
|
} ) );
|
2013-06-04 18:46:49 +00:00
|
|
|
|
2021-04-30 09:33:22 +00:00
|
|
|
QUnit.test( 'init', ( assert ) => {
|
2021-04-29 14:42:18 +00:00
|
|
|
const response = {
|
2018-09-04 12:28:50 +00:00
|
|
|
visualeditor: {
|
|
|
|
result: 'success',
|
2018-11-16 18:47:54 +00:00
|
|
|
notices: [
|
|
|
|
'<b>HTML string notice</b> message',
|
|
|
|
{
|
|
|
|
type: 'object notice',
|
|
|
|
message: '<b>object notice</b> message'
|
|
|
|
}
|
|
|
|
],
|
2022-04-04 22:53:04 +00:00
|
|
|
copyrightWarning: '<div id="editpage-copywarn">Blah blah</div>',
|
2018-09-04 12:28:50 +00:00
|
|
|
checkboxesDef: {
|
|
|
|
wpMinoredit: {
|
|
|
|
id: 'wpMinoredit',
|
|
|
|
'label-message': 'minoredit',
|
|
|
|
tooltip: 'minoredit',
|
|
|
|
'label-id': 'mw-editpage-minoredit',
|
|
|
|
'legacy-name': 'minor',
|
2019-01-08 17:00:09 +00:00
|
|
|
default: false
|
2018-09-04 12:28:50 +00:00
|
|
|
},
|
|
|
|
wpWatchthis: {
|
|
|
|
id: 'wpWatchthis',
|
|
|
|
'label-message': 'watchthis',
|
|
|
|
tooltip: 'watch',
|
|
|
|
'label-id': 'mw-editpage-watch',
|
|
|
|
'legacy-name': 'watch',
|
2019-01-08 17:00:09 +00:00
|
|
|
default: true
|
2018-09-04 12:28:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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'
|
|
|
|
},
|
|
|
|
protectedClasses: '',
|
|
|
|
basetimestamp: '20161119005107',
|
|
|
|
starttimestamp: '20180831122319',
|
|
|
|
oldid: 1804,
|
2019-05-24 21:08:17 +00:00
|
|
|
blockinfo: null,
|
2023-04-27 22:23:16 +00:00
|
|
|
wouldautocreate: false,
|
2019-05-24 21:08:17 +00:00
|
|
|
canEdit: true,
|
2023-06-01 13:21:55 +00:00
|
|
|
content: '<!DOCTYPE html>\n' + ve.dm.example.singleLine`
|
|
|
|
<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&only=styles&skin=vector"/>
|
|
|
|
</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>
|
|
|
|
`,
|
2023-04-20 21:55:48 +00:00
|
|
|
preloaded: false,
|
2022-04-04 22:53:04 +00:00
|
|
|
etag: '"1804/a4fc0409-ad18-11e8-9b45-dd8cefbedb6d"'
|
2018-09-04 12:28:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
target = new ve.init.mw.DesktopArticleTarget(),
|
2019-11-02 05:06:28 +00:00
|
|
|
dataPromise = ve.createDeferred().resolve( response ).promise(),
|
2018-09-04 12:28:50 +00:00
|
|
|
done = assert.async();
|
|
|
|
|
2024-03-20 13:59:39 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
$( '#qunit-fixture' ).append( target.$element );
|
|
|
|
|
2021-04-30 09:33:22 +00:00
|
|
|
target.on( 'surfaceReady', () => {
|
2018-09-04 12:28:50 +00:00
|
|
|
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' );
|
2022-04-04 22:53:04 +00:00
|
|
|
target.activatingDeferred.then( async () => {
|
2018-11-16 18:47:54 +00:00
|
|
|
assert.equalDomElement(
|
2023-04-27 13:51:35 +00:00
|
|
|
target.toolbar.tools.notices.noticeItems[ 0 ].$element[ 0 ],
|
2018-11-16 18:47:54 +00:00
|
|
|
$( '<div class="ve-ui-mwNoticesPopupTool-item"><b>HTML string notice</b> message</div>' )[ 0 ],
|
|
|
|
'HTML string notice message is passed through from API'
|
|
|
|
);
|
2023-04-27 13:51:35 +00:00
|
|
|
assert.strictEqual( target.toolbar.tools.notices.noticeItems[ 0 ].type, undefined, 'Plain text notice type is undefined' );
|
2018-11-16 18:47:54 +00:00
|
|
|
assert.equalDomElement(
|
2023-04-27 13:51:35 +00:00
|
|
|
target.toolbar.tools.notices.noticeItems[ 1 ].$element[ 0 ],
|
2018-11-16 18:47:54 +00:00
|
|
|
$( '<div class="ve-ui-mwNoticesPopupTool-item"><b>object notice</b> message</div>' )[ 0 ],
|
|
|
|
'Object notice message is passed through from API'
|
|
|
|
);
|
2023-04-27 13:51:35 +00:00
|
|
|
assert.strictEqual( target.toolbar.tools.notices.noticeItems[ 1 ].type, 'object notice', 'Object notice type is passed through from API' );
|
2022-04-04 22:53:04 +00:00
|
|
|
|
|
|
|
// Open the save dialog and examine it (this bypasses a bunch of stuff, and may fail in funny
|
|
|
|
// ways, but #showSaveDialog has many dependencies that I don't want to simulate here).
|
|
|
|
const dialogs = target.getSurface().getDialogs();
|
|
|
|
const instance = dialogs.openWindow( 'mwSave', target.getSaveDialogOpeningData() );
|
|
|
|
await instance.opened;
|
|
|
|
const dialog = dialogs.getCurrentWindow();
|
|
|
|
assert.equalDomElement(
|
|
|
|
dialog.$element.find( '#editpage-copywarn' )[ 0 ],
|
|
|
|
$( '<div id="editpage-copywarn">Blah blah</div>' )[ 0 ],
|
|
|
|
'Copyright warning message is passed through from API'
|
|
|
|
);
|
|
|
|
dialogs.closeWindow( 'mwSave' );
|
|
|
|
await instance.closed;
|
|
|
|
|
|
|
|
// Store doc state and examine it
|
|
|
|
target.storeDocState();
|
|
|
|
const storedData = JSON.parse( sessionStorage.getItem( 've-docstate' ) );
|
|
|
|
const ignoredKeys = {
|
|
|
|
// Not stored because it's always 'success'
|
|
|
|
result: true,
|
|
|
|
// Not stored because it's stored elsewhere
|
|
|
|
content: true,
|
|
|
|
// Not stored because if you're blocked, the editor opens in read-only mode (or doesn't open
|
|
|
|
// at all, on mobile), so we'll never have to restore from auto-save
|
2023-06-15 00:06:42 +00:00
|
|
|
blockinfo: true
|
2022-04-04 22:53:04 +00:00
|
|
|
};
|
2024-05-01 17:25:33 +00:00
|
|
|
for ( const key in response.visualeditor ) {
|
2022-04-04 22:53:04 +00:00
|
|
|
if ( !ignoredKeys[ key ] ) {
|
|
|
|
assert.deepEqual(
|
|
|
|
storedData.response[ key ],
|
|
|
|
response.visualeditor[ key ],
|
|
|
|
key + ' can be restored from auto-save data'
|
|
|
|
);
|
|
|
|
}
|
2024-05-01 17:25:33 +00:00
|
|
|
}
|
2022-04-04 22:53:04 +00:00
|
|
|
|
|
|
|
await target.destroy();
|
|
|
|
done();
|
2018-11-16 18:47:54 +00:00
|
|
|
} );
|
2018-09-04 12:28:50 +00:00
|
|
|
} );
|
|
|
|
target.activate( dataPromise );
|
|
|
|
} );
|