Dokumentaci tohoto modulu lze vytvořit na stránce Nápověda:Modul:Wikidata-WP/testcases

-- Testy pro [[Modul:Wikidata-WP]]. Spouští se v diskusi.

local p = require 'Modul:UnitTests'

local function test_wd_class(left, right, expected)
	p:preprocess_equals(left .. '|addclass=true' .. right, mw.ustring.format('<span class="wd">%s</span>', expected))
end

function p:test_get_badges()
	self:preprocess_equals_many('{{#invoke:Wikidata-WP|getBadges|id=', '}}', {
		{'Q45909|site=cswiki', mw.wikibase.label('Q17437796')},
		{'Q189080|site=cswiki', mw.wikibase.label('Q17437798')},
		{'Q1085|site=foowiki', ''},
	})
end

function p:test_get_description()
	self:preprocess_equals('{{#invoke:Wikidata-WP|getDescription|id=Q1085}}', mw.wikibase.description('Q1085'))
	test_wd_class('{{#invoke:Wikidata-WP|getDescription|id=Q1085', '}}', mw.wikibase.description('Q1085'))
end

function p:test_get_id()
	self:preprocess_equals('{{#invoke:Wikidata-WP|getId|Spolková republika Německo}}', 'Q183')
end

function p:test_get_label()
	self:preprocess_equals_many('{{#invoke:Wikidata-WP|getLabel|id=Q1085', '}}', {
		{'', 'Praha'},
		{'|lang=cs', 'Praha'},
		{'|lang=ru', 'Прага'},
		{'|lang=xyz', ''},
	})
	test_wd_class('{{#invoke:Wikidata-WP|getLabel|id=Q1085', '}}', 'Praha')
end

function p:test_get_sitelink()
	self:preprocess_equals_many('{{#invoke:Wikidata-WP|getSitelink|id=Q1085', '}}', {
		{'', 'Praha'},
		{'', mw.wikibase.sitelink('Q1085')},
		{'|cswiki', 'Praha'},
		{'|site=cswiki', 'Praha'},
		{'|site=ruwiki|pattern=[[:ru:$1]]', '[[:ru:Прага]]'},
	})
	test_wd_class('{{#invoke:Wikidata-WP|getSitelink|id=Q1085|cswiki', '}}', 'Praha')
end

return p