2018-11-12 16:33:24 +00:00
( function ( ) {
2014-10-15 18:06:41 +00:00
function makeDialog ( initialise ) {
var $qf = $ ( '#qunit-fixture' ) ,
$button = $ ( '<div>' ) . appendTo ( $qf ) ,
2015-01-23 12:48:27 +00:00
dialog = new mw . mmv . ui . OptionsDialog ( $qf , $button , { setMediaViewerEnabledOnClick : $ . noop } ) ;
2014-10-15 18:06:41 +00:00
if ( initialise ) {
dialog . initPanel ( ) ;
}
return dialog ;
}
QUnit . module ( 'mmv.ui.viewingOptions' , QUnit . newMwEnvironment ( ) ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Constructor sanity test' , function ( assert ) {
2014-10-15 18:06:41 +00:00
var dialog = makeDialog ( ) ;
assert . ok ( dialog , 'Dialog is created successfully' ) ;
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Initialisation functions' , function ( assert ) {
2014-10-15 18:06:41 +00:00
var dialog = makeDialog ( true ) ;
assert . ok ( dialog . $disableDiv , 'Disable div is created.' ) ;
assert . ok ( dialog . $enableDiv , 'Enable div is created.' ) ;
assert . ok ( dialog . $disableConfirmation , 'Disable confirmation is created.' ) ;
assert . ok ( dialog . $enableConfirmation , 'Enable confirmation is created.' ) ;
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Disable' , function ( assert ) {
2014-10-15 18:06:41 +00:00
var $header , $icon , $text , $textHeader , $textBody ,
2014-10-22 16:20:19 +00:00
$submitButton , $cancelButton , $aboutLink ,
2014-10-15 18:06:41 +00:00
dialog = makeDialog ( ) ,
deferred = $ . Deferred ( ) ;
2015-01-23 12:48:27 +00:00
this . sandbox . stub ( dialog . config , 'setMediaViewerEnabledOnClick' , function ( ) {
2014-10-15 18:06:41 +00:00
return deferred ;
} ) ;
dialog . initDisableDiv ( ) ;
$header = dialog . $disableDiv . find ( 'h3.mw-mmv-options-dialog-header' ) ;
$icon = dialog . $disableDiv . find ( 'div.mw-mmv-options-icon' ) ;
$text = dialog . $disableDiv . find ( 'div.mw-mmv-options-text' ) ;
$textHeader = $text . find ( 'p.mw-mmv-options-text-header' ) ;
$textBody = $text . find ( 'p.mw-mmv-options-text-body' ) ;
2014-10-22 16:20:19 +00:00
$aboutLink = $text . find ( 'a.mw-mmv-project-info-link' ) ;
2014-10-15 18:06:41 +00:00
$submitButton = dialog . $disableDiv . find ( 'button.mw-mmv-options-submit-button' ) ;
$cancelButton = dialog . $disableDiv . find ( 'button.mw-mmv-options-cancel-button' ) ;
assert . strictEqual ( $header . length , 1 , 'Disable header created successfully.' ) ;
assert . strictEqual ( $header . text ( ) , 'Disable Media Viewer?' , 'Disable header has correct text (if this fails, it may be due to i18n differences)' ) ;
assert . strictEqual ( $icon . length , 1 , 'Icon created successfully.' ) ;
assert . strictEqual ( $icon . html ( ) , ' ' , 'Icon has a blank space in it.' ) ;
assert . ok ( $text , 'Text div created successfully.' ) ;
assert . strictEqual ( $textHeader . length , 1 , 'Text header created successfully.' ) ;
assert . strictEqual ( $textHeader . text ( ) , 'Skip this viewing feature for all files.' , 'Text header has correct text (if this fails, it may be due to i18n differences)' ) ;
assert . strictEqual ( $textBody . length , 1 , 'Text body created successfully.' ) ;
assert . strictEqual ( $textBody . text ( ) , 'You can enable it later through the file details page.' , 'Text body has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-22 16:20:19 +00:00
assert . strictEqual ( $aboutLink . length , 1 , 'About link created successfully.' ) ;
assert . strictEqual ( $aboutLink . text ( ) , 'Learn more' , 'About link has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-15 18:06:41 +00:00
assert . strictEqual ( $submitButton . length , 1 , 'Disable button created successfully.' ) ;
assert . strictEqual ( $submitButton . text ( ) , 'Disable Media Viewer' , 'Disable button has correct text (if this fails, it may be due to i18n differences)' ) ;
assert . strictEqual ( $cancelButton . length , 1 , 'Cancel button created successfully.' ) ;
assert . strictEqual ( $cancelButton . text ( ) , 'Cancel' , 'Cancel button has correct text (if this fails, it may be due to i18n differences)' ) ;
2018-04-24 14:47:41 +00:00
$submitButton . trigger ( 'click' ) ;
2014-10-15 18:06:41 +00:00
2018-06-06 18:23:25 +00:00
assert . strictEqual ( dialog . $disableConfirmation . hasClass ( 'mw-mmv-shown' ) , false , 'Disable confirmation not shown yet' ) ;
assert . strictEqual ( dialog . $dialog . hasClass ( 'mw-mmv-disable-confirmation-shown' ) , false , 'Disable confirmation not shown yet' ) ;
2014-10-15 18:06:41 +00:00
// Pretend that the async call in mmv.js succeeded
deferred . resolve ( ) ;
// The confirmation should appear
2018-06-06 18:23:25 +00:00
assert . strictEqual ( dialog . $disableConfirmation . hasClass ( 'mw-mmv-shown' ) , true , 'Disable confirmation shown' ) ;
assert . strictEqual ( dialog . $dialog . hasClass ( 'mw-mmv-disable-confirmation-shown' ) , true , 'Disable confirmation shown' ) ;
2014-10-15 18:06:41 +00:00
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Enable' , function ( assert ) {
2014-10-22 16:20:19 +00:00
var $header , $icon , $text , $textHeader , $aboutLink ,
2014-10-15 18:06:41 +00:00
$submitButton , $cancelButton ,
dialog = makeDialog ( ) ,
deferred = $ . Deferred ( ) ;
2015-01-23 12:48:27 +00:00
this . sandbox . stub ( dialog . config , 'setMediaViewerEnabledOnClick' , function ( ) {
2014-10-15 18:06:41 +00:00
return deferred ;
} ) ;
dialog . initEnableDiv ( ) ;
$header = dialog . $enableDiv . find ( 'h3.mw-mmv-options-dialog-header' ) ;
$icon = dialog . $enableDiv . find ( 'div.mw-mmv-options-icon' ) ;
$text = dialog . $enableDiv . find ( 'div.mw-mmv-options-text' ) ;
$textHeader = $text . find ( 'p.mw-mmv-options-text-header' ) ;
2014-10-22 16:20:19 +00:00
$aboutLink = $text . find ( 'a.mw-mmv-project-info-link' ) ;
2014-10-15 18:06:41 +00:00
$submitButton = dialog . $enableDiv . find ( 'button.mw-mmv-options-submit-button' ) ;
$cancelButton = dialog . $enableDiv . find ( 'button.mw-mmv-options-cancel-button' ) ;
assert . strictEqual ( $header . length , 1 , 'Enable header created successfully.' ) ;
assert . strictEqual ( $header . text ( ) , 'Enable Media Viewer?' , 'Enable header has correct text (if this fails, it may be due to i18n differences)' ) ;
assert . strictEqual ( $icon . length , 1 , 'Icon created successfully.' ) ;
assert . strictEqual ( $icon . html ( ) , ' ' , 'Icon has a blank space in it.' ) ;
assert . ok ( $text , 'Text div created successfully.' ) ;
assert . strictEqual ( $textHeader . length , 1 , 'Text header created successfully.' ) ;
assert . strictEqual ( $textHeader . text ( ) , 'Enable this media viewing feature for all files by default.' , 'Text header has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-22 16:20:19 +00:00
assert . strictEqual ( $aboutLink . length , 1 , 'About link created successfully.' ) ;
assert . strictEqual ( $aboutLink . text ( ) , 'Learn more' , 'About link has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-15 18:06:41 +00:00
assert . strictEqual ( $submitButton . length , 1 , 'Enable button created successfully.' ) ;
assert . strictEqual ( $submitButton . text ( ) , 'Enable Media Viewer' , 'Enable button has correct text (if this fails, it may be due to i18n differences)' ) ;
assert . strictEqual ( $cancelButton . length , 1 , 'Cancel button created successfully.' ) ;
assert . strictEqual ( $cancelButton . text ( ) , 'Cancel' , 'Cancel button has correct text (if this fails, it may be due to i18n differences)' ) ;
2018-04-24 14:47:41 +00:00
$submitButton . trigger ( 'click' ) ;
2014-10-15 18:06:41 +00:00
2018-06-06 18:23:25 +00:00
assert . strictEqual ( dialog . $enableConfirmation . hasClass ( 'mw-mmv-shown' ) , false , 'Enable confirmation not shown yet' ) ;
assert . strictEqual ( dialog . $dialog . hasClass ( 'mw-mmv-enable-confirmation-shown' ) , false , 'Enable confirmation not shown yet' ) ;
2014-10-15 18:06:41 +00:00
// Pretend that the async call in mmv.js succeeded
deferred . resolve ( ) ;
// The confirmation should appear
2018-06-06 18:23:25 +00:00
assert . strictEqual ( dialog . $enableConfirmation . hasClass ( 'mw-mmv-shown' ) , true , 'Enable confirmation shown' ) ;
assert . strictEqual ( dialog . $dialog . hasClass ( 'mw-mmv-enable-confirmation-shown' ) , true , 'Enable confirmation shown' ) ;
2014-10-15 18:06:41 +00:00
} ) ;
2018-11-12 16:33:24 +00:00
} ( ) ) ;