r109328 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109327‎ | r109328 | r109329 >
Date:07:01, 18 January 2012
Author:santhosh
Status:ok
Tags:
Comment:
qunit tests for webfonts -- build menu
Fixes in extension javascript
- Before creating the menu check if one exists or not. if exists, remove it
- Correct return values of the method.
Modified paths:
  • /trunk/extensions/WebFonts/resources/ext.webfonts.js (modified) (history)
  • /trunk/extensions/WebFonts/tests/qunit/ext.webfonts.tests.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WebFonts/tests/qunit/ext.webfonts.tests.js
@@ -82,7 +82,7 @@
8383 } );
8484
8585 test( '-- Dynamic font loading based on font-family style attribute', function() {
86 - expect( 14 )
 86+ expect( 14 );
8787
8888 mw.webfonts.fonts = [];
8989 ok( $( 'body' ).append( "<p class='webfonts-testing-font-family-style'>Some content</p>" ), 'An element for testing font-family loading was appended to body' );
@@ -113,6 +113,25 @@
114114 ok( $testElement.remove() );
115115 } );
116116
 117+test( '-- Build the menu', function() {
 118+ expect( 8 );
 119+ var oldFonts = mw.webfonts.fonts;
 120+ var fonts = [];
 121+ assertFalse( mw.webfonts.buildMenu( fonts ) , 'Build the menu with empty fonts list' );
 122+ fonts = mw.webfonts.config.languages.hi;
 123+ ok( mw.webfonts.buildMenu( fonts ) , 'Build the menu with hindi fonts list' );
 124+ equals( $( 'li#pt-webfont' ).length , 1, 'There should be one and only one menu at any time' );
 125+ ok( mw.webfonts.buildMenu( fonts ) , 'Build the menu with hindi fonts list again' );
 126+ equals( $( 'li#pt-webfont' ).length , 1, 'There should be one and only one menu at any time' );
 127+ equals( $( 'ul#webfonts-fontsmenu li' ).length , fonts.length + 2 , 'Number of menu items is number of availables fonts, a help link and reset item' );
 128+ equals ( $( 'li.webfont-help-item').length , 1, 'Help link exists' );
 129+ if (oldFonts.length)
 130+ assertTrue( mw.webfonts.buildMenu( oldFonts ) , 'Restore the menu' );
 131+ else {
 132+ assertFalse( mw.webfonts.buildMenu( oldFonts ) , 'Restore the menu' );
 133+ }
 134+} );
 135+
117136 isFontFaceLoaded = function( fontFamilyName ) {
118137 var lastStyleIndex = document.styleSheets.length - 1;
119138
Index: trunk/extensions/WebFonts/resources/ext.webfonts.js
@@ -363,8 +363,14 @@
364364 buildMenu: function( fonts ) {
365365 var $menuItemsDiv = mw.webfonts.buildMenuItems( fonts );
366366 if( $menuItemsDiv === null ) {
367 - return;
 367+ return false;
368368 }
 369+
 370+ if( $( 'li#pt-webfont' ).length > 0 ) {
 371+ $( 'li#pt-webfont' ).remove();
 372+ $( 'div#webfonts-menu' ).remove();
 373+ }
 374+
369375 var $menu = $( '<div>' )
370376 .attr( 'id', 'webfonts-menu' )
371377 .addClass( 'webfontMenu' )
@@ -435,6 +441,7 @@
436442 $( '#searchform' ).css( { visibility: 'visible' } );
437443 } );
438444 }
 445+ return true;
439446 }
440447 };
441448

Status & tagging log