QUnit.test('The interface is emptied properly when necessary',thingsShouldBeEmptied.length+thingsShouldHaveEmptyClass.length,function(assert){
vari,
lightbox=newmw.LightboxInterface();
lightbox.empty();
for(i=0;i<thingsShouldBeEmptied.length;i++){
assert.strictEqual(lightbox[thingsShouldBeEmptied[i]].text(),'','We successfully emptied the '+thingsShouldBeEmptied[i]+' element');
}
for(i=0;i<thingsShouldHaveEmptyClass.length;i++){
assert.strictEqual(lightbox[thingsShouldHaveEmptyClass[i]].hasClass('empty'),true,'We successfully applied the empty class to the '+thingsShouldHaveEmptyClass[i]+' element');
}
});
QUnit.test('Handler registration and clearance work OK',2,function(assert){
varlightbox=newmw.LightboxInterface(),
handlerCalls=0;
functionhandleEvent(){
handlerCalls++;
}
lightbox.handleEvent('test',handleEvent);
$(document).trigger('test');
assert.strictEqual(handlerCalls,1,'The handler was called when we triggered the event.');
lightbox.clearEvents();
$(document).trigger('test');
assert.strictEqual(handlerCalls,1,'The handler was not called after calling lightbox.clearEvents().');
QUnit.test('Setting repository information in the UI works as expected',5,function(assert){
varlightbox=newmw.LightboxInterface(),
localRepoInfo={
local:true
},
remoteDBRepoInfo={
descBaseUrl:'http://example.com/wiki/File:'
},
remoteAPIRepoInfo={
server:'http://commons.example.org',
articlepath:'/wiki/$1'
};
lightbox.setRepoDisplayName('Example Wiki');
assert.strictEqual(lightbox.$repo.text(),'Learn more on Example Wiki','Text set to something useful for remote wiki - if this fails it might be because of localisation');
lightbox.setRepoDisplayName();
assert.strictEqual(lightbox.$repo.text(),'Learn more on '+mw.config.get('wgSiteName'),'Text set to something useful for local wiki - if this fails it might be because of localisation');
assert.strictEqual(lightbox.$repo.prop('href'),mw.config.get('wgServer')+mw.config.get('wgArticlePath').replace('$1','File:Foobar.jpg'),'The file link was set to a local page successfully.');
assert.strictEqual(lightbox.$repo.prop('href'),'http://example.com/wiki/File:Foobar.jpg','The file link was set to a remote shared DB page successfully.');
assert.strictEqual(lightbox.$repo.prop('href'),'http://commons.example.org/wiki/File:Foobar.jpg','The file link was set to a remote API page successfully.');