mediawiki.api.upload: Fix test assumption about <iframe>
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 24 Mar 2018 04:17:42 +0000 (21:17 -0700)
committerTimo Tijhof <krinklemail@gmail.com>
Sat, 24 Mar 2018 04:17:42 +0000 (21:17 -0700)
This test failed when another iframe exists before the one added
during the test, because it uses $('iframe').prop() to access the
property, which, if matching multiple iframes, will use the first
one on the page.

Make it slightly less bad, by specifying that it should use the
last one instead, given we know that mediawiki/api/upload.js appends
to document.body.

Really, though, it should have a more reliable method of obtaining
the references to these nodes.

Change-Id: I0f0723668fa3366fb8228a7a3e8a4cb03ff87d27

tests/qunit/suites/resources/mediawiki.api/mediawiki.api.upload.test.js

index bfaf7f2..788a427 100644 (file)
 
                api.uploadWithIframe( $( '<input>' )[ 0 ], { filename: 'Testing API upload.jpg' } );
 
-               $iframe = $( 'iframe' );
+               $iframe = $( 'iframe:last-child' );
                $form = $( 'form.mw-api-upload-form' );
                $input = $form.find( 'input[name=filename]' );
 
-               assert.ok( $form.length > 0 );
-               assert.ok( $input.length > 0 );
-               assert.ok( $iframe.length > 0 );
-               assert.strictEqual( $form.prop( 'target' ), $iframe.prop( 'id' ) );
-               assert.strictEqual( $input.val(), 'Testing API upload.jpg' );
+               assert.ok( $form.length > 0, 'form' );
+               assert.ok( $input.length > 0, 'input' );
+               assert.ok( $iframe.length > 0, 'frame' );
+               assert.strictEqual( $form.prop( 'target' ), $iframe.prop( 'id' ), 'form.target and frame.id ' );
+               assert.strictEqual( $input.val(), 'Testing API upload.jpg', 'input value' );
        } );
 
 }( mediaWiki, jQuery ) );