mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-11 15:27:04 +00:00
bbeb618e1d
Action changes: * Add the PREVIEW_SHOW action. Reducer changes: * Increment the user's preview count in the eventLogging reducer. Changes: * Dispatch the PREVIEW_SHOW action when the preview has been shown. * Add the previewCount change listener, which is responsible for persisting the user's preview count to storage when it changes. * Call the change listener factories individually in #registerChangeListeners as their signatures aren't consistent. Bug: T152225 Change-Id: Ifb493c5bff66712a25614ebb905251e43375420a
111 lines
2.3 KiB
JavaScript
111 lines
2.3 KiB
JavaScript
( function ( mw ) {
|
|
|
|
var counts = mw.popups.counts;
|
|
|
|
QUnit.module( 'ext.popups/reducers#eventLogging', {
|
|
setup: function () {
|
|
this.initialState = mw.popups.reducers.eventLogging( undefined, {
|
|
type: '@@INIT'
|
|
} );
|
|
}
|
|
} );
|
|
|
|
QUnit.test( 'BOOT', function ( assert ) {
|
|
var action = {
|
|
type: 'BOOT',
|
|
sessionToken: '0123456789',
|
|
pageToken: '9876543210',
|
|
page: {
|
|
title: 'Foo',
|
|
namespaceID: 1,
|
|
id: 2
|
|
},
|
|
user: {
|
|
isInCondition: true,
|
|
isAnon: false,
|
|
editCount: 11,
|
|
previewCount: 22
|
|
}
|
|
},
|
|
expectedEditCountBucket,
|
|
expectedPreviewCountBucket;
|
|
|
|
expectedEditCountBucket = counts.getEditCountBucket( action.user.editCount );
|
|
expectedPreviewCountBucket = counts.getPreviewCountBucket( action.user.previewCount );
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.eventLogging( this.initialState, action ),
|
|
{
|
|
previewCount: action.user.previewCount,
|
|
baseData: {
|
|
pageTitleSource: action.page.title,
|
|
namespaceIdSource: action.page.namespaceID,
|
|
pageIdSource: action.page.id,
|
|
isAnon: action.user.isAnon,
|
|
popupEnabled: action.user.isInCondition,
|
|
pageToken: action.pageToken,
|
|
sessionToken: action.sessionToken,
|
|
editCountBucket: expectedEditCountBucket,
|
|
previewCountBucket: expectedPreviewCountBucket
|
|
},
|
|
event: {
|
|
action: 'pageLoaded'
|
|
}
|
|
}
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'EVENT_LOGGED', function ( assert ) {
|
|
var state,
|
|
action;
|
|
|
|
state = {
|
|
event: {}
|
|
};
|
|
|
|
action = {
|
|
type: 'EVENT_LOGGED'
|
|
};
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.eventLogging( state, action ),
|
|
{
|
|
event: undefined
|
|
},
|
|
'It dequeues any event queued for logging.'
|
|
);
|
|
} );
|
|
|
|
QUnit.test( 'PREVIEW_SHOW', function ( assert ) {
|
|
var state,
|
|
count = 22,
|
|
action,
|
|
expectedCount = count + 1;
|
|
|
|
state = {
|
|
previewCount: count,
|
|
baseData: {
|
|
previewCountBucket: counts.getPreviewCountBucket( count )
|
|
},
|
|
event: undefined
|
|
};
|
|
|
|
action = {
|
|
type: 'PREVIEW_SHOW'
|
|
};
|
|
|
|
assert.deepEqual(
|
|
mw.popups.reducers.eventLogging( state, action ),
|
|
{
|
|
previewCount: expectedCount,
|
|
baseData: {
|
|
previewCountBucket: counts.getPreviewCountBucket( expectedCount )
|
|
},
|
|
event: undefined
|
|
},
|
|
'It increments the user\'s preview count and re-buckets that count.'
|
|
);
|
|
} );
|
|
|
|
}( mediaWiki ) );
|