Debian Codegraph @

tests/qunit/resources/mediawiki.api/mediawiki.api.messages.test.js

raw symbols SCIP
1 QUnit.module( 'mediawiki.api.messages', ( hooks ) => {
2 let server;
3 hooks.beforeEach( function () {
4 server = this.sandbox.useFakeServer();
5 server.respondImmediately = true;
6 } );
7
8 QUnit.test( '.getMessages()', async ( assert ) => {
9 server.respondWith( /ammessages=foo%7Cbaz/, [
10 200,
11 { 'Content-Type': 'application/json' },
12 '{ "query": { "allmessages": [' +
13 '{ "name": "foo", "content": "Foo bar" },' +
14 '{ "name": "baz", "content": "Baz Quux" }' +
15 '] } }'
16 ] );
17
18 assert.deepEqual(
19 await new mw.Api().getMessages( [ 'foo', 'baz' ] ),
20 {
21 foo: 'Foo bar',
22 baz: 'Baz Quux'
23 }
24 );
25 } );
26
27 // Make sure we properly handle a string and don't try to slice it in the handling for
28 // multiple messages. The alphabet has 26 letters, so twice that is 52, if we don't
29 // switch the string to an array of one the slice() call would remove the last two letters
30 const LONG_KEY = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz';
31
32 QUnit.test( '.getMessages() with a long string', async ( assert ) => {
33 server.respondWith( new RegExp( 'ammessages=' + LONG_KEY ), [
34 200,
35 { 'Content-Type': 'application/json' },
36 '{ "query": { "allmessages": [' +
37 '{ "name": "' + LONG_KEY + '", "content": "SomeRandomValue" }' +
38 '] } }'
39 ] );
40
41 assert.deepEqual(
42 await new mw.Api().getMessages( LONG_KEY ),
43 {
44 [ LONG_KEY ]: 'SomeRandomValue'
45 }
46 );
47 } );
48 } );