mediawiki-extensions-Popups/tests/node-qunit/integrations/mwpopups.test.js
Piotr Miazga 8510b4b942 Allow 3rd party to check Popups enabled state by accessing mw.popups object
Changes:
 - introduced js module defining mw.popups object
 - introduced isEnabled() method which checks the redux store to retrieve
 isEnabled status

Bug: T171287
Change-Id: I523369831e2aa8a915ed1cb001b35d13b770f9da
2017-08-08 15:38:01 +02:00

52 lines
1 KiB
JavaScript

import registerMwPopups from '../../../src/integrations/mwpopups';
var mw = mediaWiki,
mockStore = function ( state ) {
return {
getState: function () {
return state;
}
};
};
QUnit.module( 'ext.popups/integrations', {
beforeEach: function () {
delete mw.popups;
},
afterEach: function () {
delete mw.popups;
}
} );
QUnit.test( '#isEnabled returns correct value when disabled', function ( assert ) {
var state, store;
state = {
preview: {
enabled: false
}
};
store = mockStore( state );
this.sandbox.spy( store, 'getState' );
registerMwPopups( store );
assert.equal( mw.popups.isEnabled(), false );
assert.ok( store.getState.calledOnce );
} );
QUnit.test( '#isEnabled returns correct value when enabled', function ( assert ) {
var state, store;
state = {
preview: {
enabled: true
}
};
store = mockStore( state );
this.sandbox.spy( store, 'getState' );
registerMwPopups( store );
assert.equal( mw.popups.isEnabled(), true );
assert.ok( store.getState.calledOnce );
} );