mediawiki.api.watch: Don't use deprecated 'title' parameter
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki.api / mediawiki.api.watch.test.js
1 ( function ( mw ) {
2 QUnit.module( 'mediawiki.api.watch', QUnit.newMwEnvironment( {
3 setup: function () {
4 this.clock = this.sandbox.useFakeTimers();
5 this.server = this.sandbox.useFakeServer();
6 },
7 teardown: function () {
8 this.clock.tick( 1 );
9 }
10 } ) );
11
12 QUnit.test( '.watch()', function ( assert ) {
13 QUnit.expect( 4 );
14
15 var api = new mw.Api();
16
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' );
21 } );
22
23 api.watch( [ 'Foo' ] ).done( function ( items ) {
24 assert.equal( items[0].title, 'Foo' );
25 } );
26
27 api.watch( [ 'Foo', 'Bar' ] ).done( function ( items ) {
28 assert.equal( items[0].title, 'Foo' );
29 assert.equal( items[1].title, 'Bar' );
30 } );
31
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>" } ] }'
37 );
38 }
39
40 if ( /action=watch.*&titles=Foo%7CBar/.test( req.requestBody ) ) {
41 req.respond( 200, { 'Content-Type': 'application/json' },
42 '{ "watch": [ ' +
43 '{ "title": "Foo", "watched": true, "message": "<b>Added</b>" },' +
44 '{ "title": "Bar", "watched": true, "message": "<b>Added</b>" }' +
45 '] }'
46 );
47 }
48 } );
49 } );
50 }( mediaWiki ) );