Module:Icon/testcases: Difference between revisions

Content deleted Content added
remove template testing functionality, as it wasn't being used and we probably don't need it
use descriptive sentences for test cases, and generate the test data table every time, just in case the main module does something funny with it
 
(3 intermediate revisions by the same user not shown)
Line 1:
local mIcon = require('Module:Icon/sandbox')
local ScribuntoUnit = require('Module:ScribuntoUnit')
local suite = ScribuntoUnit:new()
 
-- Use a shortcut function to call mIcon._main using custom icon data.
local function icon(args)
local data = {
fa = {
image = "Featured article star.svg",
tooltip = "Featured article",
link = true,
},
ga = {
image = "Symbol support vote.svg",
tooltip = "Good article",
link = false,
},
wikipedia = {
image = "Wikipedia-logo.svg",
tooltip = "Wikipedia page",
},
_DEFAULT = {
image = "Symbol question.svg",
link = false,
}
}
return mIcon._main(args, data)
end
 
function suite:assertIsFileLink(s)
self:assertStringContains('^%[%[File:[^%]]+%]%]$', s)
self:assertStringContains('Good article|class=noviewer', mIcon._main{'ga'}s, true)
end
 
local linkPattern = '|link=[|%]]'
function suite:testIsFileLink()
 
self:assertIsFileLink(mIcon._main{})
function suite:testIsFileLinkassertLinkIsSuppressed(s)
self:assertIsFileLink(mIcon._main{'fa'})
self:assertStringContains('16x16px'linkPattern, mIcon._main{}s)
self:assertIsFileLink(mIcon._main{'qwertyuiop'})
end
 
function suite:testGAassertLinkIsNotSuppressed(s)
self:assertNotStringContains('Featured article'linkPattern, mIcon._main{'fa', class = ''}s)
self:assertStringContains('Symbol support vote.svg', mIcon._main{'ga'}, true)
self:assertStringContains('Good article', mIcon._main{'ga'}, true)
end
 
suite["test _main: when no icon code is specified, a file link is output"] = function(self)
function suite:testDefaultSize()
self:assertIsFileLink(mIcon._mainicon{})
self:assertStringContains('16x16px', mIcon._main{})
end
 
suite["test _main: when an existing icon code is specified, a file link is output"] = function(self)
function suite:testCustomSize()
self:assertIsFileLink(mIcon._mainicon{'fa'})
self:assertStringContains('320px', mIcon._main{size = '320px'})
end
 
suite["test _main: when an nonexistent icon code is specified, a file link is output"] = function(self)
function suite:testAlias()
self:assertIsFileLink(mIcon._mainicon{'qwertyuiopnonexistentcode'})
self:assertStringContains('Former featured article', mIcon._main{'dfa'})
end
 
suite["test _main: when an existing code is specified, the relevant image is displayed"] = function(self)
function suite:testCodeWhitespace()
self:assertStringContains('FeaturedSymbol articlesupport vote.svg', mIcon._mainicon{' fa ga'}, true)
end
 
suite["test _main: when an existing code is specified, the relevant tooltip is displayed"] = function(self)
function suite:testCodeCapitalization()
self:assertStringContains('FeaturedGood article', mIcon._mainicon{'FAga'}, true)
end
 
suite["test _main: when no dimensions are specified, the image is output as 16x16 pixels"] = function(self)
function suite:testClassParameter()
self:assertStringContains('Featured article16x16px', mIcon._mainicon{class = 'fa'})
end
 
suite["test _main: when custom dimensions are specified, the image is output with those dimensions"] = function(self)
function suite:testClassParameterOverride()
self:assertNotStringContainsassertStringContains('Featured article320px', mIcon._mainicon{'fa', classsize = 'ga320px'})
end
self:assertNotStringContains('Featured article', mIcon._main{'fa', class = ''})
 
suite["test _main: codes can have surrounding whitespace"] = function(self)
self:assertStringContains('Featured article', icon{' fa '})
end
 
suite["test _main: codes can be upper case"] = function(self)
self:assertStringContains('Former featuredFeatured article', mIcon._mainicon{'dfaFA'})
end
 
suite["test _main: codes can be specified with the 'class' parameter"] = function(self)
self:assertStringContains('320pxFeatured article', mIcon._mainicon{sizeclass = '320pxfa'})
end
 
suite["test _main: the class parameter has precedence over the first positional parameter"] = function(self)
self:assertNotStringContains('Featured article', icon{'fa', class = 'ga'})
end
 
suite["test _main: the class parameter has precedence over the first positional parameter, even if the class parameter is the empty string"] = function(self)
self:assertNotStringContains('Featured article', icon{'fa', class = ''})
end
 
suite["test _main: links are suppressed when the entry in the data table has 'link' set to false"] = function(self)
self:assertLinkIsSuppressed(icon{'ga'})
end
 
suite["test _main: links are not suppressed when the entry in the data table has 'link' set to true"] = function(self)
self:assertNotStringContains(linkPattern, icon{'fa'})
end
 
suite["test _main: links are not suppressed when the entry in the data table has no value for 'link'"] = function(self)
self:assertNotStringContains(linkPattern, icon{'wikipedia'})
end
 
suite["test Module:Icon/data: codes can be specified as aliases"] = function(self)
self:assertStringContains('SymbolFormer supportfeatured vote.svgarticle', mIcon._main{'gadfa'}, true)
end