Followup r94609: fix jquery.highlightText test cases on IE, simplify test case setup...
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 16 Aug 2011 19:34:47 +0000 (19:34 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 16 Aug 2011 19:34:47 +0000 (19:34 +0000)
These tests were failing on IE 6, 7, and 8 because the innerHTML rendering of the highlighted text came out in caps and without quotes, such that the string didn't match the provided one. By re-normalizing the expected HTML form this check now works on those browsers. Switching common code to a loop and an array makes it easier to add new test cases: less duplication of code, and no need to manually update the number of test cases.

Note that the third test case was previously commented out, but looks like a serious regression. No longer commented out, so this will fail!

tests/qunit/suites/resources/jquery/jquery.highlightText.test.js

index ba8b763..6eacad0 100644 (file)
@@ -6,32 +6,34 @@ test( '-- Initial check', function() {
 } );
 
 test( 'Check', function() {
-       expect(2);
+       var cases = [
+               {
+                       text: 'Blue Öyster Cult',
+                       highlight: 'Blue',
+                       expected: '<span class="highlight">Blue</span> Öyster Cult'
+               },
+               {
+                       text: 'Österreich',
+                       highlight: 'Österreich',
+                       expected: '<span class="highlight">Österreich</span>'
+               },
+               {
+                       desc: 'Highlighter broken on punctuation mark',
+                       text: 'So good. To be there',
+                       highlight: 'good',
+                       expected: 'So <span class="highlight">good</span>. To be there'
+               }
+       ];
+       expect(cases.length);
        var $fixture;
 
-       $fixture = $( '<p>Blue Öyster Cult</p>' );
-       $fixture.highlightText( 'Blue' );
-       equal(
-               '<span class="highlight">Blue</span> Öyster Cult',
-               $fixture.html()
-               );
-
-       $fixture = $( '<p>Österreich</p>' );
-       $fixture.highlightText( 'Österreich' );
-       equal(
-               '<span class="highlight">Österreich</span>',
-               $fixture.html()
-               );
-
-       /**
-        * Highlighter broken on punctuation mark.
-        */
-       /**  dont forget to update the value in expect() at the top!
-       $fixture = $( '<p>So good. To be there</p>' );
-       $fixture.highlightText( 'good' );
-       equal(
-               'So <span class="highlight">good</span>. To be there',
-               $fixture.html()
-               );
-       */
+       $.each(cases, function( i, item ) {
+               $fixture = $( '<p></p>' ).text( item.text );
+               $fixture.highlightText( item.highlight );
+               equals(
+                       $fixture.html(),
+                       $('<p>' + item.expected + '</p>').html(), // re-parse to normalize!
+                       item.desc || undefined
+                       );
+       } );
 } );