r92125 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92124‎ | r92125 | r92126 >
Date:23:31, 13 July 2011
Author:krinkle
Status:resolved (Comments)
Tags:
Comment:
Fix broken test introduced in r92113 for Gecko-browsers.
- Checking text() and attr() separately instead of comparing the resulting HTML (which was problematic due to browsers putting attributes in a different order)
Modified paths:
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.localize.js (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.localize.js
@@ -8,66 +8,58 @@
99 test( 'Handle basic replacements', function() {
1010 expect(4);
1111
12 - var html, $lc, expected;
 12+ var html, $lc;
1313 mw.messages.set( 'basic', 'Basic stuff' );
1414
1515 // Tag: html:msg
16 - html = '<div><span class="foobar"><html:msg key="basic"></span></div>';
 16+ html = '<span><html:msg key="basic"></span>';
1717 $lc = $( html ).localize();
18 - expected = '<span class="foobar">Basic stuff</span>';
1918
20 - strictEqual( $lc.html(), expected, 'Tag: html:msg' );
 19+ strictEqual( $lc.html(), 'Basic stuff', 'Tag: html:msg' );
2120
2221 // Tag: msg (deprecated)
23 - html = '<div><span class="foobar"><msg key="basic"></span></div>';
 22+ html = '<span><msg key="basic"></span>';
2423 $lc = $( html ).localize();
25 - expected = '<span class="foobar">Basic stuff</span>';
2624
27 - strictEqual( $lc.html(), expected, 'Tag: msg' );
 25+ strictEqual( $lc.html(), 'Basic stuff', 'Tag: msg' );
2826
2927 // Attribute: title-msg
30 - html = '<div><span class="foobar" title-msg="basic"></span></div>';
31 - $lc = $( html ).localize();
32 - expected = '<span class="foobar" title="Basic stuff"></span>';
 28+ html = '<div><span title-msg="basic"></span></div>';
 29+ $lc = $( html ).localize().find( 'span' );
3330
34 - strictEqual( $lc.html(), expected, 'Attribute: title-msg' );
 31+ strictEqual( $lc.attr( 'title' ), 'Basic stuff', 'Attribute: title-msg' );
3532
3633 // Attribute: alt-msg
37 - html = '<div><span class="foobar" alt-msg="basic"></span></div>';
38 - $lc = $( html ).localize();
39 - expected = '<span class="foobar" alt="Basic stuff"></span>';
 34+ html = '<div><span alt-msg="basic"></span></div>';
 35+ $lc = $( html ).localize().find( 'span' );
4036
41 - strictEqual( $lc.html(), expected, 'Attribute: alt-msg' );
 37+ strictEqual( $lc.attr( 'alt' ), 'Basic stuff', 'Attribute: alt-msg' );
4238 } );
4339
4440 test( 'Proper escaping', function() {
4541 expect(2);
4642
47 - var html, $lc, expected;
 43+ var html, $lc;
4844 mw.messages.set( 'properfoo', '<proper esc="test">' );
4945
5046 // This is handled by jQuery inside $.fn.localize, just a simple sanity checked
5147 // making sure it is actually using text() and attr() (or something with the same effect)
5248
5349 // Text escaping
54 - html = '<div><span class="foobar"><html:msg key="properfoo"></span></div>';
 50+ html = '<span><html:msg key="properfoo"></span>';
5551 $lc = $( html ).localize();
56 - expected = '<span class="foobar">&lt;proper esc="test"&gt;</span>';
5752
58 - strictEqual( $lc.html(), expected, 'Content is inserted as text, not as html.' );
 53+ strictEqual( $lc.text(), mw.msg( 'properfoo' ), 'Content is inserted as text, not as html.' );
5954
6055 // Attribute escaping
61 - html = '<div><span class="foobar" title-msg="properbar"></span></div>';
62 - $lc = $( html ).localize();
63 - expected = '<span class="foobar" title="&lt;properbar&gt;"></span>';
 56+ html = '<div><span title-msg="properfoo"></span></div>';
 57+ $lc = $( html ).localize().find( 'span' );
6458
65 - strictEqual( $lc.html(), expected, 'Attributes are not inserted raw.' );
66 -
67 -
 59+ strictEqual( $lc.attr( 'title' ), mw.msg( 'properfoo' ), 'Attributes are not inserted raw.' );
6860 } );
6961
7062 test( 'Options', function() {
71 - expect(4);
 63+ expect(7);
7264
7365 mw.messages.set( {
7466 'foo-lorem': 'Lorem',
@@ -78,16 +70,16 @@
7971 'foo-bazz-label': 'The Bazz ($1)',
8072 'foo-welcome': 'Welcome to $1! (last visit: $2)'
8173 } );
82 - var html, $lc, expected, x, sitename = 'Wikipedia';
 74+ var html, $lc, attrs, x, sitename = 'Wikipedia';
8375
8476 // Message key prefix
8577 html = '<div><span title-msg="lorem"><html:msg key="ipsum" /></span></div>';
8678 $lc = $( html ).localize( {
8779 prefix: 'foo-'
88 - } );
89 - expected = '<span title="Lorem">Ipsum</span>';
 80+ } ).find( 'span' );
9081
91 - strictEqual( $lc.html(), expected, 'Message key prefix' );
 82+ strictEqual( $lc.attr( 'title' ), 'Lorem', 'Message key prefix - attr' );
 83+ strictEqual( $lc.text(), 'Ipsum', 'Message key prefix - text' );
9284
9385 // Variable keys mapping
9486 x = 'bar';
@@ -97,21 +89,20 @@
9890 'title': 'foo-' + x + '-title',
9991 'label': 'foo-' + x + '-label'
10092 }
101 - } );
102 - expected = '<span title="Read more about bars">The Bars</span>';
 93+ } ).find( 'span' );
10394
104 - strictEqual( $lc.html(), expected, 'Message prefix' );
 95+ strictEqual( $lc.attr( 'title' ), 'Read more about bars', 'Variable keys mapping - attr' );
 96+ strictEqual( $lc.text(), 'The Bars', 'Variable keys mapping - text' );
10597
10698 // Passing parameteters to mw.msg
107 - html = '<div><span><html:msg key="foo-welcome" /></span></div>';
 99+ html = '<span><html:msg key="foo-welcome" /></span>';
108100 $lc = $( html ).localize( {
109101 params: {
110102 'foo-welcome': [sitename, 'yesterday']
111103 }
112104 } );
113 - expected = '<span>Welcome to Wikipedia! (last visit: yesterday)</span>';
114105
115 - strictEqual( $lc.html(), expected, 'Message prefix' );
 106+ strictEqual( $lc.text(), 'Welcome to Wikipedia! (last visit: yesterday)', 'Passing parameteters to mw.msg' );
116107
117108 // Combination of options prefix, params and keys
118109 x = 'bazz';
@@ -127,8 +118,8 @@
128119 'label': [sitename, '3 minutes ago']
129120
130121 }
131 - } );
132 - expected = '<span title="Read more about bazz at Wikipedia (last modified: 3 minutes ago)">The Bazz (Wikipedia)</span>';
 122+ } ).find( 'span' );
133123
134 - strictEqual( $lc.html(), expected, 'Message prefix' );
 124+ strictEqual( $lc.text(), 'The Bazz (Wikipedia)', 'Combination of options prefix, params and keys - text' );
 125+ strictEqual( $lc.attr( 'title' ), 'Read more about bazz at Wikipedia (last modified: 3 minutes ago)', 'Combination of options prefix, params and keys - attr' );
135126 } );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r92113Unit tests for jquery.localize...krinkle22:37, 13 July 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   17:25, 14 July 2011

tests still broken in ie 6/7/8

#Comment by Krinkle (talk | contribs)   20:23, 14 July 2011

in those browsers it's not returning anything at all (not a wrong response, but none at all) in those browsers. something is going wrong in the unit test. I've tried a dozen different things, I'm missing something...

For example, check the result in IE8, it's getting an empty string....

#Comment by Krinkle (talk | contribs)   20:57, 27 July 2011

The follow up commits by brion and me to jquery.localize and the unit test suite fixed all issues. It's passing 100% as of r92758 (TestSwarm results). Marking resolved.

Status & tagging log