r109164 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109163‎ | r109164 | r109165 >
Date:17:10, 17 January 2012
Author:amire80
Status:ok
Tags:
Comment:
Clearer test descriptions and constant font names.
Modified paths:
  • /trunk/extensions/WebFonts/tests/qunit/ext.webfonts.tests.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WebFonts/tests/qunit/ext.webfonts.tests.js
@@ -3,22 +3,23 @@
44 test( '-- Initial check', function() {
55 expect(1);
66
7 - ok( mw.webfonts, 'mw.webfonts defined' );
 7+ ok( mw.webfonts, 'mw.webfonts is defined' );
88 } );
99
1010 test( '-- Dynamic font loading', function() {
1111 expect( 7 );
12 -
 12+
 13+ var validFontName = 'Lohit Devanagari';
1314 mw.webfonts.fonts = [];
1415 var cssRulesLength = document.styleSheets.length;
15 - assertTrue( mw.webfonts.addFont( 'Lohit Devanagari' ) , 'Add the Lohit Devanagari font' );
16 - assertTrue( $.inArray( 'Lohit Devanagari', mw.webfonts.fonts ) >= 0 , 'Font loaded' );
 16+ assertTrue( mw.webfonts.addFont( validFontName ) , 'Add the ' + validFontName + ' font' );
 17+ assertTrue( $.inArray( validFontName, mw.webfonts.fonts ) >= 0 , validFontName + ' font loaded' );
1718 assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'New css rule added to the document' );
1819 var loadedFontsSize = mw.webfonts.fonts.length;
19 - assertTrue( mw.webfonts.addFont( 'Lohit Devanagari' ) , 'Add the Lohit Devanagari font again' );
20 - assertTrue( loadedFontsSize === mw.webfonts.fonts.length , 'Already loaded fonts not loaded again.' );
21 - assertFalse( mw.webfonts.addFont( 'Some Non existing font' ), 'addFont should return false if font not found' );
22 - assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'No new css rules added at this stage' );
 20+ assertTrue( mw.webfonts.addFont( validFontName ) , 'Add the ' + validFontName + ' font again' );
 21+ assertTrue( loadedFontsSize === mw.webfonts.fonts.length , 'A font that is already loaded is not loaded again' );
 22+ assertFalse( mw.webfonts.addFont( 'Some non-existing font' ), 'addFont returns false if the font was not found' );
 23+ assertTrue( cssRulesLength + 1 === document.styleSheets.length, 'Loading the font does not add new css rules' );
2324 } );
2425
2526 test( '-- Dynamic font loading based on lang attribute', function() {
@@ -32,27 +33,28 @@
3334 wgPageContentLanguage: "en",
3435 } );
3536
36 - ok( $( 'body' ).append( "<p class='webfonts-testing-lang-attr'>Some Content</p>") );
 37+ ok( $( 'body' ).append( "<p class='webfonts-testing-lang-attr'>Some content</p>"), ' A testing element was appended to <body>' );
3738 $testElement = $( 'p.webfonts-testing-lang-attr' )
38 - assertTrue( $testElement !== [], 'Test element added' ) ;
 39+ assertTrue( $testElement !== [], 'The test element is defined' );
3940
40 - ok( mw.webfonts.loadFontsForLangAttr() );
41 - assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr class since there is no lang attribute' ) ;
 41+ ok( mw.webfonts.loadFontsForLangAttr(), 'Attempted to load fonts for the lang attribute' );
 42+ assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr class since there is no lang attribute' );
4243
43 - ok( $testElement.attr( 'lang' , 'en' ) , 'Set lang attribute as english' );
44 - ok( mw.webfonts.loadFontsForLangAttr() );
45 - assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr class since en lang has no fonts available' ) ;
 44+ ok( $testElement.attr( 'lang' , 'en' ) , 'The lang attribute of the test element was set to en (English)' );
 45+ ok( mw.webfonts.loadFontsForLangAttr(), 'Attempted to load fonts for the lang attribute en' );
 46+ assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The test element has no webfonts-lang-attr class since en lang has no fonts available' );
4647
47 - ok( $testElement.attr( 'lang' , 'ta' ) , 'Set lang attribute as Tamil' );
48 - ok( mw.webfonts.loadFontsForLangAttr() );
49 - assertTrue( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has webfonts-lang-attr class' ) ;
50 - assertTrue( $.inArray( 'Lohit Tamil', mw.webfonts.fonts ) >= 0 , 'Font loaded' );
51 - assertTrue( isFontFaceLoaded( 'Lohit Tamil' ), 'New css rule added to the document for font Lohit Tamil' );
 48+ var tamilFont = 'Lohit Tamil';
 49+ ok( $testElement.attr( 'lang' , 'ta' ) , 'Set lang attribute to ta (Tamil)' );
 50+ ok( mw.webfonts.loadFontsForLangAttr(), 'Attempted to load fonts for the lang attribute ta' );
 51+ assertTrue( $testElement.hasClass( 'webfonts-lang-attr' ), 'The test element has webfonts-lang-attr class' );
 52+ assertTrue( $.inArray( tamilFont, mw.webfonts.fonts ) >= 0 , tamilFont + ' font loaded' );
 53+ assertTrue( isFontFaceLoaded( tamilFont ), 'New css rule font-face was added to the document for font ' + tamilFont );
5254
53 - ok( mw.webfonts.reset() );
54 - assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr since we reset it' ) ;
 55+ ok( mw.webfonts.reset(), 'Reset webfonts' );
 56+ assertFalse( $testElement.hasClass( 'webfonts-lang-attr' ), 'The element has no webfonts-lang-attr since we reset it' );
5557
56 - ok( $testElement.remove() );
 58+ ok( $testElement.remove(), 'The test element was removed from <body>' );
5759 } );
5860
5961 test( '-- Dynamic font loading based on font-family style attribute', function() {
@@ -61,7 +63,7 @@
6264 mw.webfonts.fonts = [];
6365 ok( $( 'body' ).append( "<p class='webfonts-testing-font-family-style'>Some Content</p>" ) );
6466 var $testElement = $( 'p.webfonts-testing-font-family-style' );
65 - assertTrue( $testElement !== [], 'Test element added' ) ;
 67+ assertTrue( $testElement !== [], 'Test element added' );
6668
6769 $testElement.attr( 'style','font-family: RufScript, Arial, Helvetica, sans' );
6870 assertTrue( $.inArray( 'RufScript', mw.webfonts.fonts ) === -1 , 'RufScript Font not loaded yet' );
@@ -86,10 +88,10 @@
8789 isFontFaceLoaded = function(fontFamilyName){
8890 var lastStyleIndex = document.styleSheets.length-1;
8991 // Iterate from last.
90 - for( var styleIndex = lastStyleIndex; styleIndex > 0 ; styleIndex-- ){
 92+ for( var styleIndex = lastStyleIndex; styleIndex > 0; styleIndex-- ){
9193 var lastStyleSheet = document.styleSheets[styleIndex];
92 - if ( !lastStyleSheet ) continue ;
93 - if ( !lastStyleSheet.cssRules[0] ) continue ;
 94+ if ( !lastStyleSheet ) continue;
 95+ if ( !lastStyleSheet.cssRules[0] ) continue;
9496 var cssText = lastStyleSheet.cssRules[0].cssText;
9597 if ( cssText.indexOf( '@font-face' ) >= 0 && cssText.indexOf( fontFamilyName ) >= 0 ){
9698 return true;

Follow-up revisions

RevisionCommit summaryAuthorDate
r109170Follow up to r109164 - more cleanup and restored test descriptions to be whol...amire8018:13, 17 January 2012

Status & tagging log