Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lua/spec/hidden_data_box_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ describe('hidden data box', function()
local Variables = require('Module:Variables')
local WarningBox = require('Module:Widget/WarningBox')

local AddCategorySpy

before_each(function()
AddCategorySpy = spy.on(mw.ext.TeamLiquidIntegration, 'add_category')
end)

after_each(function()
AddCategorySpy:revert()
end)

describe('tier parseing', function()
it('empty tier return nil', function()
assert.is_nil(Hdb.validateTier())
Expand All @@ -19,12 +29,14 @@ describe('hidden data box', function()

it('unknown tier', function()
local _, _, warnings = Hdb.validateTier('Qualifier')
assert.are_same({'Qualifier is not a known Liquipedia Tier[[Category:Pages with invalid Tier]]'}, warnings)
assert.are_same({'Qualifier is not a known Liquipedia Tier'}, warnings)
assert.stub(AddCategorySpy).was.called_with('Pages with invalid Tier')
end)

it('unknown tiertype', function()
local _, _, warnings = Hdb.validateTier(nil, 'Abc')
assert.are_same({'Abc is not a known Liquipedia Tiertype[[Category:Pages with invalid Tiertype]]'}, warnings)
assert.are_same({'Abc is not a known Liquipedia Tiertype'}, warnings)
assert.stub(AddCategorySpy).was.called_with('Pages with invalid Tiertype')
end)
end)

Expand All @@ -40,9 +52,10 @@ describe('hidden data box', function()

it('has correct warning', function()
assert.are_same(
tostring(WarningBox{text = 'DummyPage is not a Liquipedia Tournament[[Category:Pages with invalid parent]]'}),
tostring(WarningBox{text = 'DummyPage is not a Liquipedia Tournament'}),
tostring(Hdb.run({parent = 'DummyPage'}))
)
assert.stub(AddCategorySpy).was.called_with('Pages with invalid parent')
end)
end)

Expand Down
19 changes: 13 additions & 6 deletions lua/wikis/commons/HiddenDataBox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local Array = Lua.import('Module:Array')
local Class = Lua.import('Module:Class')
local Logic = Lua.import('Module:Logic')
local Game = Lua.import('Module:Game')
local I18n = Lua.import('Module:I18n')
local Info = Lua.import('Module:Info', {loadData = true})
local MatchTicker = Lua.import('Module:MatchTicker')
local MatchTickerEntityDisplay = Lua.import('Module:MatchTicker/DisplayComponents/Entity')
Expand All @@ -28,9 +29,6 @@ local WarningBoxGroup = Lua.import('Module:Widget/WarningBox/Group')
local WidgetUtil = Lua.import('Module:Widget/Util')

local HiddenDataBox = {}
local INVALID_TIER_WARNING = '${tierString} is not a known Liquipedia '
.. '${tierMode}[[Category:Pages with invalid ${tierMode}]]'
local INVALID_PARENT = '${parent} is not a Liquipedia Tournament[[Category:Pages with invalid parent]]'
local DEFAULT_TIER_TYPE = 'general'

local Language = mw.getContentLanguage()
Expand Down Expand Up @@ -59,7 +57,8 @@ function HiddenDataBox.run(args)
})[1] or {}

if Table.isEmpty(queryResult) and Namespace.isMain() then
table.insert(warnings, String.interpolate(INVALID_PARENT, {parent = parent}))
mw.ext.TeamLiquidIntegration.add_category('Pages with invalid parent')
table.insert(warnings, I18n.translate('hiddendatabox-invalid-parent-warning', {parent = parent}))
else
local date = HiddenDataBox.cleanDate(args.date, args.sdate) or queryResult.startdate or
Variables.varDefault('tournament_startdate') or HiddenDataBox.cleanDate(args.edate) or
Expand Down Expand Up @@ -214,11 +213,19 @@ function HiddenDataBox.validateTier(tier, tierType)
local tierValue, tierTypeValue = Tier.toValue(tier, tierType)

if tier and not tierValue then
table.insert(warnings, String.interpolate(INVALID_TIER_WARNING, {tierString = tier, tierMode = 'Tier'}))
mw.ext.TeamLiquidIntegration.add_category('Pages with invalid Tier')
table.insert(
warnings,
I18n.translate('hiddendatabox-invalid-tier-warning', {tierString = tier, tierMode = 'Tier'})
)
end

if tierType and tierType:lower() ~= DEFAULT_TIER_TYPE and not tierTypeValue then
table.insert(warnings, String.interpolate(INVALID_TIER_WARNING, {tierString = tierType, tierMode = 'Tiertype'}))
mw.ext.TeamLiquidIntegration.add_category('Pages with invalid Tiertype')
table.insert(
warnings,
I18n.translate('hiddendatabox-invalid-tier-warning', {tierString = tierType, tierMode = 'Tiertype'})
)
end

return tierValue, tierTypeValue, warnings
Expand Down
4 changes: 4 additions & 0 deletions lua/wikis/commons/I18n/Data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ return {
['date-range-month-day--month-unknown_day'] = '${startMonth} ${startDate} – ${endMonth} TBA',
['date-range-month-day--month-day'] = '${startMonth} ${startDate} – ${endMonth} ${endDate}',

-- HiddenDataBox warnings
['hiddendatabox-invalid-parent-warning'] = '${parent} is not a Liquipedia Tournament',
['hiddendatabox-invalid-tier-warning'] = '${tierString} is not a known Liquipedia ${tierMode}',

-- Bracket Headers
['brkts-header-r1'] = 'Grand Final,Final,GF',
['brkts-header-r2'] = 'Semifinals,Semis,SF',
Expand Down
Loading