774cbc31f3b0e86db565527647e83950703680b4
1 module( 'jquery.localize.js' );
3 test( '-- Initial check', function() {
5 ok( $.fn
.localize
, 'jQuery.fn.localize defined' );
8 test( 'Handle basic replacements', function() {
12 mw
.messages
.set( 'basic', 'Basic stuff' );
15 html
= '<div><span><html:msg key="basic"/></span></div>';
16 $lc
= $( html
).localize().find( 'span' );
17 console
.log($lc
.length
);
19 strictEqual( $lc
.text(), 'Basic stuff', 'Tag: html:msg' );
21 // Tag: msg (deprecated)
22 html
= '<div><span><msg key="basic"/></span></div>';
23 $lc
= $( html
).localize().find( 'span' );
24 $('body').append($lc
);
26 strictEqual( $lc
.text(), 'Basic stuff', 'Tag: msg' );
28 // Attribute: title-msg
29 html
= '<div><span title-msg="basic"></span></div>';
30 $lc
= $( html
).localize().find( 'span' );
32 strictEqual( $lc
.attr( 'title' ), 'Basic stuff', 'Attribute: title-msg' );
35 html
= '<div><span alt-msg="basic"></span></div>';
36 $lc
= $( html
).localize().find( 'span' );
38 strictEqual( $lc
.attr( 'alt' ), 'Basic stuff', 'Attribute: alt-msg' );
41 test( 'Proper escaping', function() {
45 mw
.messages
.set( 'properfoo', '<proper esc="test">' );
47 // This is handled by jQuery inside $.fn.localize, just a simple sanity checked
48 // making sure it is actually using text() and attr() (or something with the same effect)
51 html
= '<div><span><html:msg key="properfoo"/></span></div>';
52 $lc
= $( html
).localize().find( 'span' );
54 strictEqual( $lc
.text(), mw
.msg( 'properfoo' ), 'Content is inserted as text, not as html.' );
57 html
= '<div><span title-msg="properfoo"></span></div>';
58 $lc
= $( html
).localize().find( 'span' );
60 strictEqual( $lc
.attr( 'title' ), mw
.msg( 'properfoo' ), 'Attributes are not inserted raw.' );
63 test( 'Options', function() {
69 'foo-bar-title': 'Read more about bars',
70 'foo-bar-label': 'The Bars',
71 'foo-bazz-title': 'Read more about bazz at $1 (last modified: $2)',
72 'foo-bazz-label': 'The Bazz ($1)',
73 'foo-welcome': 'Welcome to $1! (last visit: $2)'
75 var html
, $lc
, attrs
, x
, sitename
= 'Wikipedia';
78 html
= '<div><span title-msg="lorem"><html:msg key="ipsum" /></span></div>';
79 $lc
= $( html
).localize( {
83 strictEqual( $lc
.attr( 'title' ), 'Lorem', 'Message key prefix - attr' );
84 strictEqual( $lc
.text(), 'Ipsum', 'Message key prefix - text' );
86 // Variable keys mapping
88 html
= '<div><span title-msg="title"><html:msg key="label" /></span></div>';
89 $lc
= $( html
).localize( {
91 'title': 'foo-' + x
+ '-title',
92 'label': 'foo-' + x
+ '-label'
96 strictEqual( $lc
.attr( 'title' ), 'Read more about bars', 'Variable keys mapping - attr' );
97 strictEqual( $lc
.text(), 'The Bars', 'Variable keys mapping - text' );
99 // Passing parameteters to mw.msg
100 html
= '<div><span><html:msg key="foo-welcome" /></span></div>';
101 $lc
= $( html
).localize( {
103 'foo-welcome': [sitename
, 'yesterday']
107 strictEqual( $lc
.text(), 'Welcome to Wikipedia! (last visit: yesterday)', 'Passing parameteters to mw.msg' );
109 // Combination of options prefix, params and keys
111 html
= '<div><span title-msg="title"><html:msg key="label" /></span></div>';
112 $lc
= $( html
).localize( {
115 'title': x
+ '-title',
116 'label': x
+ '-label'
119 'title': [sitename
, '3 minutes ago'],
120 'label': [sitename
, '3 minutes ago']
125 strictEqual( $lc
.text(), 'The Bazz (Wikipedia)', 'Combination of options prefix, params and keys - text' );
126 strictEqual( $lc
.attr( 'title' ), 'Read more about bazz at Wikipedia (last modified: 3 minutes ago)', 'Combination of options prefix, params and keys - attr' );