2 QUnit
.module( 'mediawiki.api.watch', QUnit
.newMwEnvironment( {
4 this.clock
= this.sandbox
.useFakeTimers();
5 this.server
= this.sandbox
.useFakeServer();
7 teardown: function () {
12 QUnit
.test( '.watch()', function ( assert
) {
15 var api
= new mw
.Api();
17 // Ensure we don't mistake a single item array for a single item and vice versa.
18 // The query parameter in request is the same either way (separated by pipe).
19 api
.watch( 'Foo' ).done( function ( item
) {
20 assert
.equal( item
.title
, 'Foo' );
23 api
.watch( [ 'Foo' ] ).done( function ( items
) {
24 assert
.equal( items
[0].title
, 'Foo' );
27 api
.watch( [ 'Foo', 'Bar' ] ).done( function ( items
) {
28 assert
.equal( items
[0].title
, 'Foo' );
29 assert
.equal( items
[1].title
, 'Bar' );
32 // Requests are POST, match requestBody instead of url
33 this.server
.respond( function ( req
) {
34 if ( /action=watch.*&titles=Foo(&|$)/.test( req
.requestBody
) ) {
35 req
.respond( 200, { 'Content-Type': 'application/json' },
36 '{ "watch": [ { "title": "Foo", "watched": true, "message": "<b>Added</b>" } ] }'
40 if ( /action=watch.*&titles=Foo%7CBar/.test( req
.requestBody
) ) {
41 req
.respond( 200, { 'Content-Type': 'application/json' },
43 '{ "title": "Foo", "watched": true, "message": "<b>Added</b>" },' +
44 '{ "title": "Bar", "watched": true, "message": "<b>Added</b>" }' +