Merge "Test: Migrate eventLoggingChangeListener.test.js to node-qunit"

This commit is contained in:
jenkins-bot 2017-02-21 20:41:22 +00:00 committed by Gerrit Code Review
commit 68cd0a330d
2 changed files with 79 additions and 81 deletions

View file

@ -0,0 +1,79 @@
var eventLogging = require( '../../../src/changeListeners/eventLogging' );
QUnit.module( 'ext.popups/eventLogging', {
setup: function () {
this.boundActions = {
eventLogged: this.sandbox.spy()
};
this.schema = {
log: this.sandbox.spy()
};
this.changeListener = eventLogging(
this.boundActions,
this.schema
);
}
} );
QUnit.test( 'it should log the queued event', function ( assert ) {
var baseData,
state;
assert.expect( 1 );
baseData = {
foo: 'bar',
baz: 'qux'
};
state = {
eventLogging: {
baseData: baseData,
event: {
action: 'pageLoaded'
}
}
};
this.changeListener( undefined, state );
assert.ok(
this.schema.log.calledWith( {
foo: 'bar',
baz: 'qux',
action: 'pageLoaded'
} ),
'It should merge the event data and the accumulated base data.'
);
} );
QUnit.test(
'it should call the eventLogged bound action creator',
function ( assert ) {
var state = {
eventLogging: {
baseData: {},
event: undefined
}
};
this.changeListener( undefined, state );
assert.notOk(
this.boundActions.eventLogged.called,
'It shouldn\'t call the eventLogged bound action creator if there\'s no queued event.'
);
// ---
state.eventLogging.event = {
action: 'pageLoaded'
};
this.changeListener( undefined, state );
assert.ok( this.boundActions.eventLogged.called );
}
);

View file

@ -1,81 +0,0 @@
( function ( mw ) {
QUnit.module( 'ext.popups/eventLogging', {
setup: function () {
this.boundActions = {
eventLogged: this.sandbox.spy()
};
this.schema = {
log: this.sandbox.spy()
};
this.changeListener = mw.popups.changeListeners.eventLogging(
this.boundActions,
this.schema
);
}
} );
QUnit.test( 'it should log the queued event', function ( assert ) {
var baseData,
state;
assert.expect( 1 );
baseData = {
foo: 'bar',
baz: 'qux'
};
state = {
eventLogging: {
baseData: baseData,
event: {
action: 'pageLoaded'
}
}
};
this.changeListener( undefined, state );
assert.ok(
this.schema.log.calledWith( {
foo: 'bar',
baz: 'qux',
action: 'pageLoaded'
} ),
'It should merge the event data and the accumulated base data.'
);
} );
QUnit.test(
'it should call the eventLogged bound action creator',
function ( assert ) {
var state = {
eventLogging: {
baseData: {},
event: undefined
}
};
this.changeListener( undefined, state );
assert.notOk(
this.boundActions.eventLogged.called,
'It shouldn\'t call the eventLogged bound action creator if there\'s no queued event.'
);
// ---
state.eventLogging.event = {
action: 'pageLoaded'
};
this.changeListener( undefined, state );
assert.ok( this.boundActions.eventLogged.called );
}
);
}( mediaWiki ) );