Module:Int/testcases

From Linux Web Expert

< Module:Int

Revision as of 17:01, 25 August 2021 by imported>ExE Boss (Add remaining test case for parameter `missing`)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

File:OOjs UI icon close-ltr-destructive.svgN1 test failed.

Name Expected Actual
File:OOjs UI icon close-ltr-destructive.svgN testRenderIntMessage View $1 notices ⧼notification-link-text-expand-notice-count⧽
File:OOjs UI icon check-constructive.svg testRenderIntMessageWithLang
File:OOjs UI icon check-constructive.svg testRenderIntMessageWithMissingFallback

local p = require('Module:ScribuntoUnit'):new()
local m = require('Module:Int')

local function callWithArgs(msg, lang, args, missing)
	local templateArgs = { msg }
	if args then
		for n, v in ipairs(args) do
			templateArgs[n+1] = v
		end
	end
	local frame = (mw.getCurrentFrame()
		:newChild{ args = templateArgs }
		:newChild{ args = { [1] = msg, lang = lang, missing = missing } })
	return m.renderIntMessage(frame)
end

function p:testRenderIntMessage()
	self:assertEquals('View history', callWithArgs('vector-view-history'))
	self:assertEquals('View history', callWithArgs('vector-view-history', nil, {'unused', 'data', 2.71}))
	self:assertEquals('View $1 notices', callWithArgs('notification-link-text-expand-notice-count'))
	self:assertEquals('View 1 notice', callWithArgs('notification-link-text-expand-notice-count', nil, {'1'}))
	self:assertEquals('View 1 notice', callWithArgs('notification-link-text-expand-notice-count', nil, {1}))
end

function p:testRenderIntMessageWithLang()
	self:assertEquals('View history', callWithArgs('vector-view-history', ''))
	self:assertEquals('View history', callWithArgs('vector-view-history', 'en'))
	-- Apostrophes are invalid in language codes; they should be ignored rather than throwing an error
	self:assertEquals('View history', callWithArgs('vector-view-history', '"de"'))
	self:assertEquals('Versionsgeschichte', callWithArgs('vector-view-history', 'de'))
end

function p:testRenderIntMessageWithMissingFallback()
	self:assertEquals(
		'⧼Module:Int/test-missing⧽',
		callWithArgs('Module:Int/test-missing'),
		"parameter <code>|missing=</code> unset"
	)
	self:assertEquals(
		'⧼Module:Int/test-missing⧽',
		callWithArgs('Module:Int/test-missing', nil, nil, ''),
		"parameter <code>|missing=</code> set to the empty string"
	)
	self:assertEquals(
		'test-missing',
		callWithArgs('Module:Int/test-missing', nil, nil, 'test-missing'),
		"parameter <code>|missing=...</code> set"
	)
end

return p