Merge "Added release notes for 'ContentHandler::runLegacyHooks' removal"
[mediawiki.git] / tests / qunit / suites / resources / mediawiki.api / mediawiki.api.watch.test.js
blob86414691d8b7a5e4569aeab3ed0c55cfc759bf98
1 ( function ( mw ) {
2         QUnit.module( 'mediawiki.api.watch', QUnit.newMwEnvironment( {
3                 setup: function () {
4                         this.server = this.sandbox.useFakeServer();
5                         this.server.respondImmediately = true;
6                 }
7         } ) );
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>" } ] }'
15                                 );
16                         }
17                 } );
19                 return new mw.Api().watch( 'Foo' ).done( function ( item ) {
20                         assert.equal( item.title, 'Foo' );
21                 } );
22         } );
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>" } ] }'
32                                 );
33                         }
34                 } );
36                 return new mw.Api().watch( [ 'Foo' ] ).done( function ( items ) {
37                         assert.equal( items[ 0 ].title, 'Foo' );
38                 } );
39         } );
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' },
46                                         '{ "watch": [ ' +
47                                                 '{ "title": "Foo", "watched": true, "message": "<b>Added</b>" },' +
48                                                 '{ "title": "Bar", "watched": true, "message": "<b>Added</b>" }' +
49                                                 '] }'
50                                 );
51                         }
52                 } );
54                 return new mw.Api().watch( [ 'Foo', 'Bar' ] ).done( function ( items ) {
55                         assert.equal( items[ 0 ].title, 'Foo' );
56                         assert.equal( items[ 1 ].title, 'Bar' );
57                 } );
58         } );
60 }( mediaWiki ) );