Implement extension registration from an extension.json file
[mediawiki.git] / tests / qunit / suites / resources / mediawiki.api / mediawiki.api.watch.test.js
blob5965ab7b4f66862f4889b69f6ab1d1ae71ee118f
1 ( function ( mw ) {
2         QUnit.module( 'mediawiki.api.watch', QUnit.newMwEnvironment( {
3                 setup: function () {
4                         this.server = this.sandbox.useFakeServer();
5                 }
6         } ) );
8         QUnit.test( '.watch()', function ( assert ) {
9                 QUnit.expect( 4 );
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' );
17                 } );
19                 api.watch( [ 'Foo' ] ).done( function ( items ) {
20                         assert.equal( items[0].title, 'Foo' );
21                 } );
23                 api.watch( [ 'Foo', 'Bar' ] ).done( function ( items ) {
24                         assert.equal( items[0].title, 'Foo' );
25                         assert.equal( items[1].title, 'Bar' );
26                 } );
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>" } ] }'
33                                 );
34                         }
36                         if ( /action=watch.*&titles=Foo%7CBar/.test( req.requestBody ) ) {
37                                 req.respond( 200, { 'Content-Type': 'application/json' },
38                                         '{ "watch": [ ' +
39                                                 '{ "title": "Foo", "watched": true, "message": "<b>Added</b>" },' +
40                                                 '{ "title": "Bar", "watched": true, "message": "<b>Added</b>" }' +
41                                                 '] }'
42                                 );
43                         }
44                 } );
45         } );
46 }( mediaWiki ) );