Daniel Werner has uploaded a new change for review. https://gerrit.wikimedia.org/r/67290
Change subject: Refactor Sites related wikibase tests in frontend ...................................................................... Refactor Sites related wikibase tests in frontend * Control configuration data rather than assuming some. * Also test certain sites to be set instead of just checking for unknown sites. Change-Id: Ia727a722e4afd53c196433daa76784d1f6134ff1 --- M lib/tests/qunit/wikibase.tests.js 1 file changed, 68 insertions(+), 16 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/90/67290/1 diff --git a/lib/tests/qunit/wikibase.tests.js b/lib/tests/qunit/wikibase.tests.js index a4dd702..6871011 100644 --- a/lib/tests/qunit/wikibase.tests.js +++ b/lib/tests/qunit/wikibase.tests.js @@ -7,10 +7,10 @@ * @ingroup WikibaseLib * * @licence GNU GPL v2+ - * @author H. Snater + * @author Daniel Werner < [email protected] > */ -( function( mw, wb, $, QUnit, undefined ) { +( function( mw, wb, Site, $, QUnit ) { 'use strict'; /** @@ -19,39 +19,93 @@ */ wb.tests = {}; - QUnit.module( 'wikibase', QUnit.newWbEnvironment() ); + var sitesDefinition = { + nn: { + apiUrl: '//nn.wikipedia.org/w/api.php', + globalSiteId: 'nnwiki', + group: 'wikipedia', + id: 'nn', + languageCode: 'nn', + name: null, + pageUrl: '//nn.wikipedia.org/wiki/$1', + shortName: 'norsk nynorsk' + } + }; - QUnit.test( 'basic', function( assert ) { + QUnit.module( 'wikibase', QUnit.newWbEnvironment( { + config: { + wbSiteDetails: sitesDefinition + } + } ) ); - QUnit.expect( 7 ); - + QUnit.test( 'basic', 1, function( assert ) { assert.ok( wb instanceof Object, 'initiated wikibase object' ); + } ); + + QUnit.test( 'wikibase.getSites()', 3, function( assert ) { + var sites = wb.getSites(); assert.ok( - wb.getSites() instanceof Object, - 'gettings sites resturns object' + $.isPlainObject( sites ), + 'getSites() returns a plain object' ); assert.strictEqual( - wb.getSite( 'xy' ), + sites.length, + sitesDefinition.length, + 'getSites() returns expected number of sites' + ); + + var allSiteInstances = true; + $.each( sites, function( i, site ) { + allSiteInstances = allSiteInstances && ( site instanceof Site ); + } ); + + assert.ok( + allSiteInstances, + 'getSites() returned object fields only hold site objects' + ); + } ); + + QUnit.test( 'wikibase.getSite()', 2, function( assert ) { + assert.ok( + wb.getSite( 'nn' ) instanceof Site, + 'trying to get a known site by its ID returns a site object' + ); + + assert.strictEqual( + wb.getSite( 'unknown-site' ), null, - 'trying to get invalid site returns null' + 'trying to get an unknown site returns null' + ); + } ); + + QUnit.test( 'wikibase.hasSite()', 2, function( assert ) { + assert.strictEqual( + wb.hasSite( 'nn' ), + true, + 'trying to check for known site returns true' ); assert.strictEqual( - wb.hasSite( 'xy' ), + wb.hasSite( 'unknown-site' ), false, - 'trying to check for invalid site returns false' + 'trying to check for unknown site returns false' ); + } ); + QUnit.test( 'wikibase.getLanguages()', 1, function( assert ) { assert.ok( $.isPlainObject( wb.getLanguages() ), - 'getLanguages() returns object' + 'getLanguages() returns a plain object' ); + } ); + QUnit.test( 'wikibase.getLanguageNameByCode()', 2, function( assert ) { + // TODO: Don't assume global state, control what languages are available for this test! if( $.uls !== undefined ) { assert.strictEqual( wb.getLanguageNameByCode( 'de' ), @@ -71,8 +125,6 @@ '', 'getLanguageNameByCode returns empty string if unknown code' ); - - } ); -}( mediaWiki, wikibase, jQuery, QUnit ) ); +}( mediaWiki, wikibase, wikibase.Site, jQuery, QUnit ) ); -- To view, visit https://gerrit.wikimedia.org/r/67290 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia727a722e4afd53c196433daa76784d1f6134ff1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Daniel Werner <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
