2018-11-13 21:02:18 +00:00
|
|
|
QUnit.module( 'Thanks thank', QUnit.newMwEnvironment( {
|
2022-05-04 08:43:32 +00:00
|
|
|
beforeEach: function () {
|
2018-11-13 21:02:18 +00:00
|
|
|
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' ) );
|
2022-05-04 08:43:32 +00:00
|
|
|
assert.deepEqual( mw.thanks.thanked.load(), [ '17', '11' ], 'cookie with two values' );
|
2018-11-13 21:02:18 +00:00
|
|
|
|
2022-05-04 08:43:32 +00:00
|
|
|
// Add a 0 the 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' ) );
|
2022-05-04 08:43:32 +00:00
|
|
|
assert.strictEqual( mw.thanks.thanked.load()[ mw.thanks.thanked.maxHistory - 1 ], '0', 'load ids from a cookie' );
|
2018-11-13 21:02:18 +00:00
|
|
|
|
2022-01-10 12:54:51 +00:00
|
|
|
mw.thanks.thanked.push( thankId );
|
2022-05-04 08:43:32 +00:00
|
|
|
assert.strictEqual( mw.thanks.thanked.load().length, mw.thanks.thanked.maxHistory, 'cut to maxHistory' );
|
|
|
|
assert.strictEqual( mw.thanks.thanked.load()[ mw.thanks.thanked.maxHistory - 1 ], thankId, 'add to the end' );
|
2018-11-13 21:02:18 +00:00
|
|
|
|
2022-05-04 08:43:32 +00:00
|
|
|
assert.strictEqual( mw.thanks.thanked.contains( thankId ), true, 'cookie contains id' );
|
|
|
|
assert.strictEqual( mw.thanks.thanked.contains( thankIdNonExisting ), false, 'cookie does not contain id' );
|
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":""}]}}'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
2022-05-04 08:43:32 +00:00
|
|
|
var maleUser = mw.thanks.getUserGender( 'user1' );
|
|
|
|
var unknownGenderUser = mw.thanks.getUserGender( 'user2' );
|
|
|
|
var nonExistingUser = mw.thanks.getUserGender( 'user3' );
|
|
|
|
var done = assert.async( 3 );
|
2018-11-13 21:02:18 +00:00
|
|
|
|
|
|
|
maleUser.then( function ( recipientGender ) {
|
2022-05-04 08:43:32 +00:00
|
|
|
assert.strictEqual( recipientGender, 'male', 'gender for male user' );
|
|
|
|
done();
|
2018-11-13 21:02:18 +00:00
|
|
|
} );
|
|
|
|
unknownGenderUser.then( function ( recipientGender ) {
|
2022-05-04 08:43:32 +00:00
|
|
|
assert.strictEqual( recipientGender, 'unknown', 'gender for unknown-gender user' );
|
|
|
|
done();
|
2018-11-13 21:02:18 +00:00
|
|
|
} );
|
|
|
|
nonExistingUser.then( function ( recipientGender ) {
|
2022-05-04 08:43:32 +00:00
|
|
|
assert.strictEqual( recipientGender, 'unknown', 'gender for non-existing user' );
|
|
|
|
done();
|
2018-11-13 21:02:18 +00:00
|
|
|
} );
|
|
|
|
} );
|