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