diff options
Diffstat (limited to 'tests/qunit/suites/resources/mediawiki.api')
-rw-r--r-- | tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js | 26 | ||||
-rw-r--r-- | tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js | 59 |
2 files changed, 85 insertions, 0 deletions
diff --git a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js new file mode 100644 index 00000000..3d3f630f --- /dev/null +++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js @@ -0,0 +1,26 @@ +QUnit.module( 'mediawiki.api.parse', QUnit.newMwEnvironment() ); + +QUnit.asyncTest( 'Hello world', function ( assert ) { + var api; + QUnit.expect( 6 ); + + api = new mw.Api(); + + api.parse( "'''Hello world'''" ) + .done( function ( html ) { + // Parse into a document fragment instead of comparing HTML, due to + // presence of Tidy influencing whitespace. + // Html also contains "NewPP report" comment. + var $res = $( '<div>' ).html( html ).children(), + res = $res.get( 0 ); + assert.equal( $res.length, 1, 'Response contains 1 element' ); + assert.equal( res.nodeName.toLowerCase(), 'p', 'Response is a paragraph' ); + assert.equal( $res.children().length, 1, 'Response has 1 child element' ); + assert.equal( $res.children().get( 0 ).nodeName.toLowerCase(), 'b', 'Child element is a bold tag' ); + // Trim since Tidy may or may not mess with the spacing here + assert.equal( $.trim( $res.text() ), 'Hello world', 'Response contains given text' ); + assert.equal( $res.find( 'b' ).text(), 'Hello world', 'Bold tag wraps the entire, same, text' ); + + QUnit.start(); + }); +}); diff --git a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js new file mode 100644 index 00000000..79bd7306 --- /dev/null +++ b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js @@ -0,0 +1,59 @@ +QUnit.module( 'mediawiki.api', QUnit.newMwEnvironment() ); + +QUnit.asyncTest( 'Basic functionality', function ( assert ) { + var api, d1, d2, d3; + QUnit.expect( 3 ); + + api = new mw.Api(); + + d1 = api.get( {} ) + .done( function ( data ) { + assert.deepEqual( data, [], 'If request succeeds without errors, resolve deferred' ); + }); + + d2 = api.get({ + action: 'doesntexist' + }) + .fail( function ( errorCode, details ) { + assert.equal( errorCode, 'unknown_action', 'API error (e.g. "unknown_action") should reject the deferred' ); + }); + + d3 = api.post( {} ) + .done( function ( data ) { + assert.deepEqual( data, [], 'Simple POST request' ); + }); + + // After all are completed, continue the test suite. + QUnit.whenPromisesComplete( d1, d2, d3 ).always( function () { + QUnit.start(); + }); +}); + +QUnit.asyncTest( 'Deprecated callback methods', function ( assert ) { + var api, d1, d2, d3; + QUnit.expect( 3 ); + + api = new mw.Api(); + + d1 = api.get( {}, function () { + assert.ok( true, 'Function argument treated as success callback.' ); + }); + + d2 = api.get( {}, { + ok: function ( data ) { + assert.ok( true, '"ok" property treated as success callback.' ); + } + }); + + d3 = api.get({ + action: 'doesntexist' + }, { + err: function ( data ) { + assert.ok( true, '"err" property treated as error callback.' ); + } + }); + + QUnit.whenPromisesComplete( d1, d2, d3 ).always( function () { + QUnit.start(); + }); +}); |