mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-24 07:34:11 +00:00
Tests: Migrate changeListeners/syncUserSettings.test.js to node-qunit
Change-Id: I3bf86e0452557e938fe7066978e553d583d974f7
This commit is contained in:
parent
715389443c
commit
4e0c054a19
104
tests/node-qunit/changeListeners/syncUserSettings.test.js
Normal file
104
tests/node-qunit/changeListeners/syncUserSettings.test.js
Normal file
|
@ -0,0 +1,104 @@
|
|||
var syncUserSettings = require( '../../../src/changeListeners/syncUserSettings' );
|
||||
|
||||
QUnit.module( 'ext.popups/changeListeners/syncUserSettings', {
|
||||
setup: function () {
|
||||
this.userSettings = {
|
||||
setPreviewCount: this.sandbox.spy(),
|
||||
setIsEnabled: this.sandbox.spy()
|
||||
};
|
||||
|
||||
this.changeListener = syncUserSettings( this.userSettings );
|
||||
}
|
||||
} );
|
||||
|
||||
QUnit.test(
|
||||
'it shouldn\'t update the storage if the preview count hasn\'t changed',
|
||||
function ( assert ) {
|
||||
var state,
|
||||
prevState;
|
||||
|
||||
assert.expect( 1 );
|
||||
|
||||
state = {
|
||||
eventLogging: {
|
||||
previewCount: 222
|
||||
}
|
||||
};
|
||||
|
||||
this.changeListener( undefined, state );
|
||||
|
||||
// ---
|
||||
|
||||
prevState = $.extend( true, {}, state );
|
||||
|
||||
this.changeListener( prevState, state );
|
||||
|
||||
assert.notOk( this.userSettings.setPreviewCount.called );
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test( 'it should update the storage if the previewCount has changed', function ( assert ) {
|
||||
var prevState,
|
||||
state;
|
||||
|
||||
assert.expect( 1 );
|
||||
|
||||
prevState = {
|
||||
eventLogging: {
|
||||
previewCount: 222
|
||||
}
|
||||
};
|
||||
|
||||
state = $.extend( true, {}, prevState );
|
||||
++state.eventLogging.previewCount;
|
||||
|
||||
this.changeListener( prevState, state );
|
||||
|
||||
assert.ok( this.userSettings.setPreviewCount.calledWith( 223 ) );
|
||||
} );
|
||||
|
||||
QUnit.test(
|
||||
'it shouldn\'t update the storage if the enabled state hasn\'t changed',
|
||||
function ( assert ) {
|
||||
var state,
|
||||
prevState;
|
||||
|
||||
assert.expect( 1 );
|
||||
|
||||
state = {
|
||||
preview: {
|
||||
enabled: true
|
||||
}
|
||||
};
|
||||
|
||||
this.changeListener( undefined, state );
|
||||
|
||||
// ---
|
||||
|
||||
prevState = $.extend( true, {}, state );
|
||||
|
||||
this.changeListener( prevState, state );
|
||||
|
||||
assert.notOk( this.userSettings.setIsEnabled.called );
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test( 'it should update the storage if the enabled flag has changed', function ( assert ) {
|
||||
var prevState,
|
||||
state;
|
||||
|
||||
assert.expect( 1 );
|
||||
|
||||
prevState = {
|
||||
preview: {
|
||||
enabled: true
|
||||
}
|
||||
};
|
||||
|
||||
state = $.extend( true, {}, prevState );
|
||||
state.preview.enabled = false;
|
||||
|
||||
this.changeListener( prevState, state );
|
||||
|
||||
assert.ok( this.userSettings.setIsEnabled.calledWith( false ) );
|
||||
} );
|
|
@ -1,106 +0,0 @@
|
|||
( function ( mw, $ ) {
|
||||
|
||||
QUnit.module( 'ext.popups/changeListeners/syncUserSettings', {
|
||||
setup: function () {
|
||||
this.userSettings = {
|
||||
setPreviewCount: this.sandbox.spy(),
|
||||
setIsEnabled: this.sandbox.spy()
|
||||
};
|
||||
|
||||
this.changeListener = mw.popups.changeListeners.syncUserSettings( this.userSettings );
|
||||
}
|
||||
} );
|
||||
|
||||
QUnit.test(
|
||||
'it shouldn\'t update the storage if the preview count hasn\'t changed',
|
||||
function ( assert ) {
|
||||
var state,
|
||||
prevState;
|
||||
|
||||
assert.expect( 1 );
|
||||
|
||||
state = {
|
||||
eventLogging: {
|
||||
previewCount: 222
|
||||
}
|
||||
};
|
||||
|
||||
this.changeListener( undefined, state );
|
||||
|
||||
// ---
|
||||
|
||||
prevState = $.extend( true, {}, state );
|
||||
|
||||
this.changeListener( prevState, state );
|
||||
|
||||
assert.notOk( this.userSettings.setPreviewCount.called );
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test( 'it should update the storage if the previewCount has changed', function ( assert ) {
|
||||
var prevState,
|
||||
state;
|
||||
|
||||
assert.expect( 1 );
|
||||
|
||||
prevState = {
|
||||
eventLogging: {
|
||||
previewCount: 222
|
||||
}
|
||||
};
|
||||
|
||||
state = $.extend( true, {}, prevState );
|
||||
++state.eventLogging.previewCount;
|
||||
|
||||
this.changeListener( prevState, state );
|
||||
|
||||
assert.ok( this.userSettings.setPreviewCount.calledWith( 223 ) );
|
||||
} );
|
||||
|
||||
QUnit.test(
|
||||
'it shouldn\'t update the storage if the enabled state hasn\'t changed',
|
||||
function ( assert ) {
|
||||
var state,
|
||||
prevState;
|
||||
|
||||
assert.expect( 1 );
|
||||
|
||||
state = {
|
||||
preview: {
|
||||
enabled: true
|
||||
}
|
||||
};
|
||||
|
||||
this.changeListener( undefined, state );
|
||||
|
||||
// ---
|
||||
|
||||
prevState = $.extend( true, {}, state );
|
||||
|
||||
this.changeListener( prevState, state );
|
||||
|
||||
assert.notOk( this.userSettings.setIsEnabled.called );
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test( 'it should update the storage if the enabled flag has changed', function ( assert ) {
|
||||
var prevState,
|
||||
state;
|
||||
|
||||
assert.expect( 1 );
|
||||
|
||||
prevState = {
|
||||
preview: {
|
||||
enabled: true
|
||||
}
|
||||
};
|
||||
|
||||
state = $.extend( true, {}, prevState );
|
||||
state.preview.enabled = false;
|
||||
|
||||
this.changeListener( prevState, state );
|
||||
|
||||
assert.ok( this.userSettings.setIsEnabled.calledWith( false ) );
|
||||
} );
|
||||
|
||||
}( mediaWiki, jQuery ) );
|
Loading…
Reference in a new issue