Debian Codegraph @

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

raw symbols SCIP
1 QUnit.module( 'mediawiki.api.edit', ( hooks ) => {
2 let server;
3 hooks.beforeEach( function () {
4 server = this.sandbox.useFakeServer();
5 server.respondImmediately = true;
6 } );
7
8 QUnit.test( '.parse( string )', async ( assert ) => {
9 server.respondWith( 'POST', /api.php/, [ 200,
10 { 'Content-Type': 'application/json' },
11 '{ "parse": { "text": "<p><b>Hello world</b></p>" } }'
12 ] );
13
14 const html = await new mw.Api().parse( '\'\'\'Hello world\'\'\'' );
15 assert.strictEqual( html, '<p><b>Hello world</b></p>', 'Parse wikitext by string' );
16 } );
17
18 QUnit.test( '.parse( Object.toString )', async ( assert ) => {
19 server.respondWith( 'POST', /api.php/, [ 200,
20 { 'Content-Type': 'application/json' },
21 '{ "parse": { "text": "<p><b>Hello world</b></p>" } }'
22 ] );
23
24 const input = {
25 toString: function () {
26 return '\'\'\'Hello world\'\'\'';
27 }
28 };
29 const html = await new mw.Api().parse( input );
30 assert.strictEqual( html, '<p><b>Hello world</b></p>', 'Parse wikitext by toString object' );
31 } );
32
33 QUnit.test( '.parse( mw.Title )', async ( assert ) => {
34 server.respondWith( 'GET', /action=parse.*&page=Earth/, [ 200,
35 { 'Content-Type': 'application/json' },
36 '{ "parse": { "text": "<p><b>Earth</b> is a planet.</p>" } }'
37 ] );
38
39 const html = await new mw.Api().parse( new mw.Title( 'Earth' ) );
40 assert.strictEqual( html, '<p><b>Earth</b> is a planet.</p>', 'Parse page by Title object' );
41 } );
42 } );