mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-28 09:20:31 +00:00
Merge "Test: Migrate eventLoggingChangeListener.test.js to node-qunit"
This commit is contained in:
commit
68cd0a330d
79
tests/node-qunit/changeListeners/eventLogging.test.js
Normal file
79
tests/node-qunit/changeListeners/eventLogging.test.js
Normal 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 );
|
||||
}
|
||||
);
|
|
@ -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 ) );
|
Loading…
Reference in a new issue