2 QUnit
.module( 'mediawiki.api.watch', QUnit
.newMwEnvironment( {
4 this.server
= this.sandbox
.useFakeServer();
5 this.server
.respondImmediately
= true;
9 QUnit
.test( '.watch( string )', function ( assert
) {
10 this.server
.respond( function ( req
) {
11 // Match POST requestBody
12 if ( /action=watch.*&titles=Foo(&|$)/.test( req
.requestBody
) ) {
13 req
.respond( 200, { 'Content-Type': 'application/json' },
14 '{ "watch": [ { "title": "Foo", "watched": true, "message": "<b>Added</b>" } ] }'
19 return new mw
.Api().watch( 'Foo' ).done( function ( item
) {
20 assert
.strictEqual( item
.title
, 'Foo' );
24 // Ensure we don't mistake a single item array for a single item and vice versa.
25 // The query parameter in request is the same either way (separated by pipe).
26 QUnit
.test( '.watch( Array ) - single', function ( assert
) {
27 this.server
.respond( function ( req
) {
28 // Match POST requestBody
29 if ( /action=watch.*&titles=Foo(&|$)/.test( req
.requestBody
) ) {
30 req
.respond( 200, { 'Content-Type': 'application/json' },
31 '{ "watch": [ { "title": "Foo", "watched": true, "message": "<b>Added</b>" } ] }'
36 return new mw
.Api().watch( [ 'Foo' ] ).done( function ( items
) {
37 assert
.strictEqual( items
[ 0 ].title
, 'Foo' );
41 QUnit
.test( '.watch( Array ) - multi', function ( assert
) {
42 this.server
.respond( function ( req
) {
43 // Match POST requestBody
44 if ( /action=watch.*&titles=Foo%7CBar/.test( req
.requestBody
) ) {
45 req
.respond( 200, { 'Content-Type': 'application/json' },
47 '{ "title": "Foo", "watched": true, "message": "<b>Added</b>" },' +
48 '{ "title": "Bar", "watched": true, "message": "<b>Added</b>" }' +
54 return new mw
.Api().watch( [ 'Foo', 'Bar' ] ).done( function ( items
) {
55 assert
.strictEqual( items
[ 0 ].title
, 'Foo' );
56 assert
.strictEqual( items
[ 1 ].title
, 'Bar' );