2018-11-13 21:02:18 +00:00
|
|
|
QUnit.module( 'Thanks thank', QUnit.newMwEnvironment( {
|
|
|
|
setup: function () {
|
|
|
|
this.server = this.sandbox.useFakeServer();
|
|
|
|
this.server.respondImmediately = true;
|
|
|
|
}
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
QUnit.test( 'thanked cookie', function ( assert ) {
|
2022-01-10 12:54:51 +00:00
|
|
|
var thankId = '8';
|
|
|
|
var thankIdNonExisting = '13';
|
|
|
|
|
2020-05-29 19:43:31 +00:00
|
|
|
mw.cookie.set( mw.thanks.thanked.cookieName, escape( '17,11' ) );
|
2018-11-13 21:02:18 +00:00
|
|
|
|
|
|
|
assert.deepEqual( mw.thanks.thanked.load(), [ '17', '11' ], 'gets cookie with two values' );
|
|
|
|
|
|
|
|
// Makes the 0 100th element
|
2019-12-12 11:36:24 +00:00
|
|
|
// eslint-disable-next-line no-restricted-properties
|
2020-05-29 19:43:31 +00:00
|
|
|
mw.cookie.set( mw.thanks.thanked.cookieName, escape( '9,'.repeat( mw.thanks.thanked.maxHistory - 1 ) + '0' ) );
|
2018-11-13 21:02:18 +00:00
|
|
|
|
|
|
|
assert.strictEqual( mw.thanks.thanked.load()[ mw.thanks.thanked.maxHistory - 1 ], '0', 'loads ' + mw.thanks.thanked.maxHistory + ' ids from a cookie' );
|
2022-01-10 12:54:51 +00:00
|
|
|
mw.thanks.thanked.push( thankId );
|
2018-11-13 21:02:18 +00:00
|
|
|
assert.strictEqual( mw.thanks.thanked.load().length, mw.thanks.thanked.maxHistory, 'cuts a cookie to ' + mw.thanks.thanked.maxHistory + ' values' );
|
2022-01-10 12:54:51 +00:00
|
|
|
assert.strictEqual( mw.thanks.thanked.load()[ mw.thanks.thanked.maxHistory - 1 ], thankId, 'adds a new value to cookie to the end' );
|
2018-11-13 21:02:18 +00:00
|
|
|
|
2022-01-10 12:54:51 +00:00
|
|
|
assert.strictEqual( mw.thanks.thanked.contains( thankId ), true, 'cookie contains id and returns true' );
|
|
|
|
assert.strictEqual( mw.thanks.thanked.contains( thankIdNonExisting ), false, 'cookie does not contains id and returns false' );
|
2018-11-13 21:02:18 +00:00
|
|
|
} );
|
2022-01-10 12:54:51 +00:00
|
|
|
|
2018-11-13 21:02:18 +00:00
|
|
|
QUnit.test( 'gets user gender', function ( assert ) {
|
|
|
|
this.server.respond( /user1/, function ( request ) {
|
|
|
|
request.respond( 200, { 'Content-Type': 'application/json' },
|
|
|
|
'{"batchcomplete":"","query":{"users":[{"userid":1,"name":"user1","gender":"male"}]}}'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
this.server.respond( /user2/, function ( request ) {
|
|
|
|
request.respond( 200, { 'Content-Type': 'application/json' },
|
|
|
|
'{"batchcomplete":"","query":{"users":[{"userid":2,"name":"user2","gender":"unknown"}]}}'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
this.server.respond( /user3/, function ( request ) {
|
|
|
|
request.respond( 200, { 'Content-Type': 'application/json' },
|
|
|
|
'{"batchcomplete":"","query":{"users":[{"name":"user3","missing":""}]}}'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
var maleUser = mw.thanks.getUserGender( 'user1' ),
|
|
|
|
unknownGenderUser = mw.thanks.getUserGender( 'user2' ),
|
|
|
|
nonExistingUser = mw.thanks.getUserGender( 'user3' ),
|
|
|
|
callbackDone = assert.async( 3 );
|
|
|
|
|
|
|
|
maleUser.then( function ( recipientGender ) {
|
|
|
|
assert.strictEqual( recipientGender, 'male', 'gets a proper gender for existing male user' );
|
|
|
|
callbackDone();
|
|
|
|
} );
|
|
|
|
unknownGenderUser.then( function ( recipientGender ) {
|
|
|
|
assert.strictEqual( recipientGender, 'unknown', 'gets a unknown gender for a existing unknown gender user' );
|
|
|
|
callbackDone();
|
|
|
|
} );
|
|
|
|
nonExistingUser.then( function ( recipientGender ) {
|
|
|
|
assert.strictEqual( recipientGender, 'unknown', 'gets a unknown gender for non-existing user' );
|
|
|
|
callbackDone();
|
|
|
|
} );
|
|
|
|
} );
|