mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-11 07:16:08 +00:00
b7effdc000
Action changes: * Include the user's preview count in the user property of the action. Reducer changes: * Make the eventLogging reducer add the bucketed user's preview count to the state tree. Changes: * Extract mw.popups.UserSettings#getPreviewCount and #setPreviewCount and associated tests from the ext.popups.core module. Bug: T152225 Change-Id: I6b7afef31311be8fede685deb536f577845cb9cf
67 lines
1.5 KiB
JavaScript
67 lines
1.5 KiB
JavaScript
( function ( mw ) {
|
|
|
|
QUnit.module( 'ext.popups/counts' );
|
|
|
|
QUnit.test( '#getEditCountBucket', function ( assert ) {
|
|
var i, bucket, count,
|
|
cases = [
|
|
[ 0, '0 edits' ],
|
|
[ 1, '1-4 edits' ],
|
|
[ 2, '1-4 edits' ],
|
|
[ 4, '1-4 edits' ],
|
|
[ 5, '5-99 edits' ],
|
|
[ 25, '5-99 edits' ],
|
|
[ 50, '5-99 edits' ],
|
|
[ 99, '5-99 edits' ],
|
|
[ 100, '100-999 edits' ],
|
|
[ 101, '100-999 edits' ],
|
|
[ 500, '100-999 edits' ],
|
|
[ 999, '100-999 edits' ],
|
|
[ 1000, '1000+ edits' ],
|
|
[ 1500, '1000+ edits' ]
|
|
];
|
|
|
|
assert.expect( cases.length );
|
|
|
|
for ( i = 0; i < cases.length; i++ ) {
|
|
count = cases[ i ][ 0 ];
|
|
bucket = mw.popups.counts.getEditCountBucket( count );
|
|
assert.equal(
|
|
bucket,
|
|
cases[ i ][ 1 ],
|
|
'Edit count bucket is "' + bucket + '" when edit count is ' + count + '.'
|
|
);
|
|
}
|
|
} );
|
|
|
|
QUnit.test( '#getPreviewCountBucket', function ( assert ) {
|
|
var i, count, bucket,
|
|
cases = [
|
|
[ -1, 'unknown' ],
|
|
[ 0, '0 previews' ],
|
|
[ 1, '1-4 previews' ],
|
|
[ 2, '1-4 previews' ],
|
|
[ 4, '1-4 previews' ],
|
|
[ 5, '5-20 previews' ],
|
|
[ 10, '5-20 previews' ],
|
|
[ 20, '5-20 previews' ],
|
|
[ 21, '21+ previews' ],
|
|
[ 100, '21+ previews' ],
|
|
[ 1000, '21+ previews' ]
|
|
];
|
|
|
|
QUnit.expect( cases.length );
|
|
|
|
for ( i = 0; i < cases.length; i++ ) {
|
|
count = cases[ i ][ 0 ];
|
|
bucket = mw.popups.counts.getPreviewCountBucket( count );
|
|
assert.equal(
|
|
bucket,
|
|
cases[ i ][ 1 ],
|
|
'Preview count bucket is "' + bucket + '" when preview count is ' + count + '.'
|
|
);
|
|
}
|
|
} );
|
|
|
|
}( mediaWiki ) );
|