2023-05-20 08:30:52 +00:00
const { OptionsDialog } = require ( 'mmv' ) ;
2018-11-12 16:33:24 +00:00
( function ( ) {
2014-10-15 18:06:41 +00:00
function makeDialog ( initialise ) {
2023-10-24 09:53:23 +00:00
const $qf = $ ( '#qunit-fixture' ) ;
const $button = $ ( '<div>' ) . appendTo ( $qf ) ;
const dialog = new OptionsDialog ( $qf , $button , { setMediaViewerEnabledOnClick : function ( ) { } } ) ;
2014-10-15 18:06:41 +00:00
if ( initialise ) {
dialog . initPanel ( ) ;
}
return dialog ;
}
QUnit . module ( 'mmv.ui.viewingOptions' , QUnit . newMwEnvironment ( ) ) ;
2021-12-10 00:43:28 +00:00
QUnit . test ( 'Constructor sense test' , function ( assert ) {
2023-10-24 09:53:23 +00:00
const dialog = makeDialog ( ) ;
2023-05-20 08:30:52 +00:00
assert . true ( dialog instanceof OptionsDialog , 'Dialog is created successfully' ) ;
2014-10-15 18:06:41 +00:00
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Initialisation functions' , function ( assert ) {
2023-10-24 09:53:23 +00:00
const dialog = makeDialog ( true ) ;
2014-10-15 18:06:41 +00:00
2022-05-20 00:18:43 +00:00
assert . strictEqual ( dialog . $disableDiv . length , 1 , 'Disable div is created.' ) ;
assert . strictEqual ( dialog . $enableDiv . length , 1 , 'Enable div is created.' ) ;
assert . strictEqual ( dialog . $disableConfirmation . length , 1 , 'Disable confirmation is created.' ) ;
assert . strictEqual ( dialog . $enableConfirmation . length , 1 , 'Enable confirmation is created.' ) ;
2014-10-15 18:06:41 +00:00
} ) ;
2017-07-25 23:38:21 +00:00
QUnit . test ( 'Disable' , function ( assert ) {
2023-10-24 09:53:23 +00:00
const dialog = makeDialog ( ) ;
const deferred = $ . Deferred ( ) ;
2014-10-15 18:06:41 +00:00
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 ( ) ;
2023-10-24 09:53:23 +00:00
const $header = dialog . $disableDiv . find ( 'h3.mw-mmv-options-dialog-header' ) ;
2014-10-15 18:06:41 +00:00
2023-10-24 09:53:23 +00:00
const $text = dialog . $disableDiv . find ( 'div.mw-mmv-options-text' ) ;
const $textHeader = $text . find ( 'p.mw-mmv-options-text-header' ) ;
const $textBody = $text . find ( 'p.mw-mmv-options-text-body' ) ;
const $aboutLink = $text . find ( 'a.mw-mmv-project-info-link' ) ;
const $submitButton = dialog . $disableDiv . find ( 'button.mw-mmv-options-submit-button' ) ;
const $cancelButton = dialog . $disableDiv . find ( 'button.mw-mmv-options-cancel-button' ) ;
2014-10-15 18:06:41 +00:00
assert . strictEqual ( $header . length , 1 , 'Disable header created successfully.' ) ;
2020-06-12 07:48:11 +00:00
assert . strictEqual ( $header . text ( ) , '(multimediaviewer-options-dialog-header)' , 'Disable header has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-15 18:06:41 +00:00
2022-05-20 00:18:43 +00:00
assert . strictEqual ( $text . length , 1 , 'Text div created successfully.' ) ;
2014-10-15 18:06:41 +00:00
assert . strictEqual ( $textHeader . length , 1 , 'Text header created successfully.' ) ;
2020-06-12 07:48:11 +00:00
assert . strictEqual ( $textHeader . text ( ) , '(multimediaviewer-options-text-header)' , 'Text header has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-15 18:06:41 +00:00
assert . strictEqual ( $textBody . length , 1 , 'Text body created successfully.' ) ;
2020-06-12 07:48:11 +00:00
assert . strictEqual ( $textBody . text ( ) , '(multimediaviewer-options-text-body)' , 'Text body has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-15 18:06:41 +00:00
2014-10-22 16:20:19 +00:00
assert . strictEqual ( $aboutLink . length , 1 , 'About link created successfully.' ) ;
2020-06-12 07:48:11 +00:00
assert . strictEqual ( $aboutLink . text ( ) , '(multimediaviewer-options-learn-more)' , 'About link has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-22 16:20:19 +00:00
2014-10-15 18:06:41 +00:00
assert . strictEqual ( $submitButton . length , 1 , 'Disable button created successfully.' ) ;
2020-06-12 07:48:11 +00:00
assert . strictEqual ( $submitButton . text ( ) , '(multimediaviewer-option-submit-button)' , 'Disable button has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-15 18:06:41 +00:00
assert . strictEqual ( $cancelButton . length , 1 , 'Cancel button created successfully.' ) ;
2020-06-12 07:48:11 +00:00
assert . strictEqual ( $cancelButton . text ( ) , '(multimediaviewer-option-cancel-button)' , 'Cancel button has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-15 18:06:41 +00:00
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 ) {
2023-10-24 09:53:23 +00:00
const dialog = makeDialog ( ) ;
const deferred = $ . Deferred ( ) ;
2014-10-15 18:06:41 +00:00
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 ( ) ;
2023-10-24 09:53:23 +00:00
const $header = dialog . $enableDiv . find ( 'h3.mw-mmv-options-dialog-header' ) ;
2014-10-15 18:06:41 +00:00
2023-10-24 09:53:23 +00:00
const $text = dialog . $enableDiv . find ( 'div.mw-mmv-options-text' ) ;
const $textHeader = $text . find ( 'p.mw-mmv-options-text-header' ) ;
const $aboutLink = $text . find ( 'a.mw-mmv-project-info-link' ) ;
const $submitButton = dialog . $enableDiv . find ( 'button.mw-mmv-options-submit-button' ) ;
const $cancelButton = dialog . $enableDiv . find ( 'button.mw-mmv-options-cancel-button' ) ;
2014-10-15 18:06:41 +00:00
assert . strictEqual ( $header . length , 1 , 'Enable header created successfully.' ) ;
2020-06-12 07:48:11 +00:00
assert . strictEqual ( $header . text ( ) , '(multimediaviewer-enable-dialog-header)' , 'Enable header has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-15 18:06:41 +00:00
2022-05-20 00:18:43 +00:00
assert . strictEqual ( $text . length , 1 , 'Text div created successfully.' ) ;
2014-10-15 18:06:41 +00:00
assert . strictEqual ( $textHeader . length , 1 , 'Text header created successfully.' ) ;
2020-06-12 07:48:11 +00:00
assert . strictEqual ( $textHeader . text ( ) , '(multimediaviewer-enable-text-header)' , 'Text header has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-15 18:06:41 +00:00
2014-10-22 16:20:19 +00:00
assert . strictEqual ( $aboutLink . length , 1 , 'About link created successfully.' ) ;
2020-06-12 07:48:11 +00:00
assert . strictEqual ( $aboutLink . text ( ) , '(multimediaviewer-options-learn-more)' , 'About link has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-22 16:20:19 +00:00
2014-10-15 18:06:41 +00:00
assert . strictEqual ( $submitButton . length , 1 , 'Enable button created successfully.' ) ;
2020-06-12 07:48:11 +00:00
assert . strictEqual ( $submitButton . text ( ) , '(multimediaviewer-enable-submit-button)' , 'Enable button has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-15 18:06:41 +00:00
assert . strictEqual ( $cancelButton . length , 1 , 'Cancel button created successfully.' ) ;
2020-06-12 07:48:11 +00:00
assert . strictEqual ( $cancelButton . text ( ) , '(multimediaviewer-option-cancel-button)' , 'Cancel button has correct text (if this fails, it may be due to i18n differences)' ) ;
2014-10-15 18:06:41 +00:00
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
} ( ) ) ;