2014-03-17 08:07:53 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the MediaWiki extension MultimediaViewer.
|
|
|
|
*
|
|
|
|
* MultimediaViewer is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MultimediaViewer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-11-12 16:33:24 +00:00
|
|
|
( function () {
|
2014-03-17 08:07:53 +00:00
|
|
|
function makeShare() {
|
|
|
|
return new mw.mmv.ui.reuse.Share( $( '#qunit-fixture' ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
QUnit.module( 'mmv.ui.reuse.share', QUnit.newMwEnvironment() );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'Sanity test, object creation and UI construction', function ( assert ) {
|
2014-03-17 08:07:53 +00:00
|
|
|
var share = makeShare();
|
|
|
|
|
|
|
|
assert.ok( share, 'Share UI element is created.' );
|
|
|
|
assert.strictEqual( share.$pane.length, 1, 'Pane div created.' );
|
|
|
|
assert.ok( share.pageInput, 'Text field created.' );
|
|
|
|
assert.ok( share.$pageLink, 'Link created.' );
|
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'set()/empty():', function ( assert ) {
|
2014-03-17 08:07:53 +00:00
|
|
|
var share = makeShare(),
|
|
|
|
image = { // fake mw.mmv.model.Image
|
|
|
|
title: new mw.Title( 'File:Foobar.jpg' ),
|
|
|
|
url: 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
2014-04-14 23:22:28 +00:00
|
|
|
descriptionUrl: '//commons.wikimedia.org/wiki/File:Foobar.jpg'
|
2014-03-17 08:07:53 +00:00
|
|
|
};
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
assert.notStrictEqual( !share.pageInput.getValue(), '', 'pageInput is empty.' );
|
2014-03-17 08:07:53 +00:00
|
|
|
|
2014-03-19 22:35:55 +00:00
|
|
|
share.select = function () {
|
|
|
|
assert.ok( true, 'Text has been selected after data is set.' );
|
|
|
|
};
|
|
|
|
|
2014-03-17 08:07:53 +00:00
|
|
|
share.set( image );
|
|
|
|
|
|
|
|
assert.notStrictEqual( share.pageInput.getValue(), '', 'pageInput is not empty.' );
|
|
|
|
|
|
|
|
share.empty();
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
assert.notStrictEqual( !share.pageInput.getValue(), '', 'pageInput is empty.' );
|
2014-03-17 08:07:53 +00:00
|
|
|
} );
|
|
|
|
|
2017-07-25 23:38:21 +00:00
|
|
|
QUnit.test( 'attach()/unattach():', function ( assert ) {
|
2014-03-17 08:07:53 +00:00
|
|
|
var share = makeShare(),
|
|
|
|
image = {
|
|
|
|
title: new mw.Title( 'File:Foobar.jpg' ),
|
|
|
|
url: 'https://upload.wikimedia.org/wikipedia/commons/3/3a/Foobar.jpg',
|
2014-04-14 23:22:28 +00:00
|
|
|
descriptionUrl: '//commons.wikimedia.org/wiki/File:Foobar.jpg'
|
2014-03-17 08:07:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
share.set( image );
|
|
|
|
|
2015-01-23 12:48:27 +00:00
|
|
|
share.selectAllOnEvent = function () {
|
2014-03-17 08:07:53 +00:00
|
|
|
assert.ok( false, 'selectAllOnEvent should not have been called.' );
|
|
|
|
};
|
|
|
|
|
|
|
|
// Triggering action events before attaching should do nothing
|
2014-05-15 19:16:22 +00:00
|
|
|
// use of focus() would run into jQuery bug #14740 and similar issues
|
2014-05-21 21:41:39 +00:00
|
|
|
share.pageInput.$element.find( 'input' ).triggerHandler( 'focus' );
|
2014-03-17 08:07:53 +00:00
|
|
|
|
|
|
|
share.selectAllOnEvent = function () {
|
|
|
|
assert.ok( true, 'selectAllOnEvent was called.' );
|
|
|
|
};
|
|
|
|
|
|
|
|
share.attach();
|
|
|
|
|
|
|
|
// Action events should be handled now
|
2014-05-21 21:41:39 +00:00
|
|
|
share.pageInput.$element.find( 'input' ).triggerHandler( 'focus' );
|
2014-03-17 08:07:53 +00:00
|
|
|
|
|
|
|
// Test the unattach part
|
2015-01-23 12:48:27 +00:00
|
|
|
share.selectAllOnEvent = function () {
|
2014-03-17 08:07:53 +00:00
|
|
|
assert.ok( false, 'selectAllOnEvent should not have been called.' );
|
|
|
|
};
|
|
|
|
|
|
|
|
share.unattach();
|
|
|
|
|
|
|
|
// Triggering action events now that we are unattached should do nothing
|
2014-05-21 21:41:39 +00:00
|
|
|
share.pageInput.$element.find( 'input' ).triggerHandler( 'focus' );
|
2014-03-17 08:07:53 +00:00
|
|
|
} );
|
|
|
|
|
2018-11-12 16:33:24 +00:00
|
|
|
}() );
|