Tests: Migrate changeListeners/syncUserSettings.test.js to node-qunit

Change-Id: I3bf86e0452557e938fe7066978e553d583d974f7
This commit is contained in:
joakin 2017-02-21 13:11:37 +01:00
parent 715389443c
commit 4e0c054a19
2 changed files with 104 additions and 106 deletions

View 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 ) );
} );

View file

@ -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 ) );