Skip to content

Commit

Permalink
test(infobox): simple quick golden test for infobox league (#4813)
Browse files Browse the repository at this point in the history
* tests(Infobox): simple quick golden test for infobox league

* goldens + tweaks to make it run
  • Loading branch information
Rathoz authored Oct 9, 2024
1 parent 1d1da9e commit 068a4e3
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 5 deletions.
10 changes: 8 additions & 2 deletions components/infobox/wikis/apexlegends/infobox_league_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ local Logic = require('Module:Logic')
local Page = require('Module:Page')
local String = require('Module:StringUtils')
local Table = require('Module:Table')
local Tier = require('Module:Tier')
local Variables = require('Module:Variables')

local Injector = Lua.import('Module:Widget/Injector')
Expand All @@ -29,6 +28,13 @@ local GAME_MODE = mw.loadData('Module:GameMode')
local EA_ICON = ' [[File:EA icon.png|x15px|middle|link=Electronic Arts|'
.. 'Tournament sponsored by Electronirc Arts & Respawn.]]'

local EA_TIERS = {
major = '[[Major]]',
premier = '[[Premier]]',
challenger = '[[Challenger]]',
online = '[[Online]]',
}

---@class ApexlegendsLeagueInfobox: InfoboxLeague
local CustomLeague = Class.new(League)
local CustomInjector = Class.new(Injector)
Expand Down Expand Up @@ -71,7 +77,7 @@ function CustomInjector:parse(id, widgets)
end
table.insert(widgets, Cell{
name = 'EA tier',
content = {Tier['ea'][string.lower(args.eatier or '')]},
content = {EA_TIERS[string.lower(args.eatier or '')]},
classes = {'tournament-highlighted-bg'}
})
elseif id == 'customcontent' then
Expand Down
87 changes: 85 additions & 2 deletions components/infobox/wikis/rocketleague/infobox_league_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ local Class = require('Module:Class')
local Game = require('Module:Game')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Math = require('Module:MathUtil')
local String = require('Module:StringUtils')
local Tier = require('Module:Tier/Custom')
local TournamentNotability = require('Module:TournamentNotability')
local Variables = require('Module:Variables')

local Injector = Lua.import('Module:Widget/Injector')
Expand All @@ -28,6 +28,7 @@ local Center = Widgets.Center
---@class RocketleagueLeagueInfobox: InfoboxLeague
local CustomLeague = Class.new(League)
local CustomInjector = Class.new(Injector)
local NotabilityCalculator = {}

local SERIES_RLCS = 'Rocket League Championship Series'
local MODE_2v2 = '2v2'
Expand Down Expand Up @@ -166,7 +167,7 @@ function CustomLeague:addToLpdb(lpdbData, args)
lpdbData.extradata.mode = args.mode
lpdbData.extradata.notabilitymod = args.notabilitymod
lpdbData.extradata.liquipediatiertype2 = args.liquipediatiertype2
lpdbData.extradata.notabilitypercentage = args.edate ~= 'tba' and TournamentNotability.run() or ''
lpdbData.extradata.notabilitypercentage = args.edate ~= 'tba' and NotabilityCalculator.run() or ''

return lpdbData
end
Expand Down Expand Up @@ -206,4 +207,86 @@ function CustomLeague:_makeInternalLink(content)
return '[[' .. content .. ']]'
end

---@return number
function NotabilityCalculator.run()
local pagename = mw.title.getCurrentTitle().text:gsub(' ', '_')
local placements = NotabilityCalculator._getPlacements(pagename)
local allTeams = NotabilityCalculator._getAllTeams()

local teamsWithAPage = 0

-- We need this because sometimes we get a placement like "tbd"
local numberOfPlacements = 0

for _, placement in ipairs(placements) do
if placement.participant:lower() ~= '' and placement.participant:lower() ~= 'tbd' then
local doesTeamExist = NotabilityCalculator._findTeam(allTeams, placement.participant)
numberOfPlacements = numberOfPlacements + 1

if doesTeamExist == true then
teamsWithAPage = teamsWithAPage + 1
end
end
end

if numberOfPlacements == 0 then
return 0
end

return Math.round((teamsWithAPage / numberOfPlacements) * 100, 2)
end

---@param allTeams table
---@param teamToFind string
---@return boolean
function NotabilityCalculator._findTeam(allTeams, teamToFind)
local firstLetter = string.sub(teamToFind, 1, 1):lower()

if not allTeams[firstLetter] then
return false
end

for _, team in ipairs(allTeams[firstLetter]) do
if team:lower() == teamToFind:lower() then
return true
end
end

return false
end

---@return table
function NotabilityCalculator._getAllTeams()
local teams = mw.ext.LiquipediaDB.lpdb('team', {
query = 'name',
limit = 5000,
})

-- Make a table of letters, with each letter mapping to an
-- array of names, to aid in faster lookup
local indexedTeams = {}

for _, team in pairs(teams) do
local firstLetter = string.sub(team.name, 1, 1):lower()

if indexedTeams[firstLetter] == nil then
indexedTeams[firstLetter] = {}
end

table.insert(indexedTeams[firstLetter], team.name)
end

return indexedTeams
end

---@param pagename string
---@return {participant: string, participantflag: string, mode: string}[]
function NotabilityCalculator._getPlacements(pagename)
return mw.ext.LiquipediaDB.lpdb('placement', {
conditions = '[[pagename::' .. pagename .. ']] AND [[mode::3v3]]',
query = 'participant, participantflag, mode'
})
end


return CustomLeague
4 changes: 3 additions & 1 deletion definitions/mw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ function mw.frame:callParserFunction(name, args) end
---This is transclusion. As in transclusion, if the passed title does not contain a namespace prefix it will be assumed to be in the Template: namespace.
---@param params {title: string, args: table?}
---@return string
function mw.frame:expandTemplate(params) end
function mw.frame:expandTemplate(params)
error('Cannot expand template in fake')
end

---This is equivalent to a call to frame:callParserFunction() with function name '#tag:' .. name and with content prepended to args.
---@param name string
Expand Down
1 change: 1 addition & 0 deletions spec/golden_masters/infobox_league_apexlegends.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="fo-nttax-infobox-wrapper infobox-apexlegends"><div class="fo-nttax-infobox"><div><div class="infobox-header wiki-backgroundcolor-light"><span class="infobox-buttons navigation-not-searchable">&#91;[https://liquipedia.net/wiki/ e]&#93;&#91;[[lpcommons:|h]]&#93;</span>FakePage</div></div><div><div class="infobox-header wiki-backgroundcolor-light infobox-header-2">League Information</div></div><div><div class="infobox-cell-2 infobox-description">Platform:</div><div style="width:50%">[[PC Competitions|PC]][[Category:PC Competitions]]</div></div><div><div class="infobox-cell-2 infobox-description">Location:</div><div style="width:50%">[[Template:Abbr/TBD]]</div></div></div><div class="fo-nttax-infobox-adbox"></div><div></div></div>
1 change: 1 addition & 0 deletions spec/golden_masters/infobox_league_counterstrike.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="fo-nttax-infobox-wrapper infobox-counterstrike"><div class="fo-nttax-infobox"><div><div class="infobox-header wiki-backgroundcolor-light"><span class="infobox-buttons navigation-not-searchable">&#91;[https://liquipedia.net/wiki/ e]&#93;&#91;[[lpcommons:|h]]&#93;</span>FakePage</div></div><div><div class="infobox-header wiki-backgroundcolor-light infobox-header-2">League Information</div></div><div><div class="infobox-cell-2 infobox-description">Location:</div><div style="width:50%">[[Template:Abbr/TBD]]</div></div></div><div class="fo-nttax-infobox-adbox"></div><div></div></div>
1 change: 1 addition & 0 deletions spec/golden_masters/infobox_league_dota2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="fo-nttax-infobox-wrapper infobox-dota2"><div class="fo-nttax-infobox"><div><div class="infobox-header wiki-backgroundcolor-light"><span class="infobox-buttons navigation-not-searchable">&#91;[https://liquipedia.net/wiki/ e]&#93;&#91;[[lpcommons:|h]]&#93;</span>FakePage</div></div><div><div class="infobox-header wiki-backgroundcolor-light infobox-header-2">League Information</div></div><div><div class="infobox-cell-2 infobox-description">Location:</div><div style="width:50%">[[Template:Abbr/TBD]]</div></div><div><div class="infobox-cell-2 infobox-description">Game:</div><div style="width:50%">[[Dota 2|Dota 2]]</div></div></div><div class="fo-nttax-infobox-adbox"></div><div></div></div>
1 change: 1 addition & 0 deletions spec/golden_masters/infobox_league_leagueoflegends.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="fo-nttax-infobox-wrapper infobox-leagueoflegends"><div class="fo-nttax-infobox"><div><div class="infobox-header wiki-backgroundcolor-light"><span class="infobox-buttons navigation-not-searchable">&#91;[https://liquipedia.net/wiki/ e]&#93;&#91;[[lpcommons:|h]]&#93;</span>FakePage</div></div><div><div class="infobox-header wiki-backgroundcolor-light infobox-header-2">League Information</div></div><div><div class="infobox-cell-2 infobox-description">Location:</div><div style="width:50%">[[Template:Abbr/TBD]]</div></div></div><div class="fo-nttax-infobox-adbox"></div><div></div></div>
1 change: 1 addition & 0 deletions spec/golden_masters/infobox_league_mobilelegends.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="fo-nttax-infobox-wrapper infobox-mobilelegends"><div class="fo-nttax-infobox"><div><div class="infobox-header wiki-backgroundcolor-light"><span class="infobox-buttons navigation-not-searchable">&#91;[https://liquipedia.net/wiki/ e]&#93;&#91;[[lpcommons:|h]]&#93;</span>FakePage</div></div><div><div class="infobox-header wiki-backgroundcolor-light infobox-header-2">League Information</div></div><div><div class="infobox-cell-2 infobox-description">Location:</div><div style="width:50%">[[Template:Abbr/TBD]]</div></div></div><div class="fo-nttax-infobox-adbox"></div><div></div></div>
1 change: 1 addition & 0 deletions spec/golden_masters/infobox_league_overwatch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="fo-nttax-infobox-wrapper infobox-overwatch"><div class="fo-nttax-infobox"><div><div class="infobox-header wiki-backgroundcolor-light"><span class="infobox-buttons navigation-not-searchable">&#91;[https://liquipedia.net/wiki/ e]&#93;&#91;[[lpcommons:|h]]&#93;</span>FakePage</div></div><div><div class="infobox-header wiki-backgroundcolor-light infobox-header-2">League Information</div></div><div><div class="infobox-cell-2 infobox-description">Location:</div><div style="width:50%">[[Template:Abbr/TBD]]</div></div><div><div class="infobox-cell-2 infobox-description">Game:</div><div style="width:50%">[[Overwatch 2|Overwatch 2]]</div></div></div><div class="fo-nttax-infobox-adbox"></div><div></div></div>
1 change: 1 addition & 0 deletions spec/golden_masters/infobox_league_rainbowsix.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="fo-nttax-infobox-wrapper infobox-rainbowsix"><div class="fo-nttax-infobox"><div><div class="infobox-header wiki-backgroundcolor-light"><span class="infobox-buttons navigation-not-searchable">&#91;[https://liquipedia.net/wiki/ e]&#93;&#91;[[lpcommons:|h]]&#93;</span>FakePage</div></div><div><div class="infobox-header wiki-backgroundcolor-light infobox-header-2">League Information</div></div><div><div class="infobox-cell-2 infobox-description">Location:</div><div style="width:50%">[[Template:Abbr/TBD]]</div></div><div><div class="infobox-cell-2 infobox-description">Game:</div><div style="width:50%">Tom Clancy's Rainbow Six Siege</div></div><div><div class="infobox-cell-2 infobox-description">Platform:</div><div style="width:50%">[[:Category:PC|PC]]</div></div></div><div class="fo-nttax-infobox-adbox"></div><div></div></div>
1 change: 1 addition & 0 deletions spec/golden_masters/infobox_league_rocketleague.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="fo-nttax-infobox-wrapper infobox-rocketleague"><div class="fo-nttax-infobox"><div><div class="infobox-header wiki-backgroundcolor-light"><span class="infobox-buttons navigation-not-searchable">&#91;[https://liquipedia.net/wiki/ e]&#93;&#91;[[lpcommons:|h]]&#93;</span>FakePage</div></div><div><div class="infobox-header wiki-backgroundcolor-light infobox-header-2">League Information</div></div><div><div class="infobox-cell-2 infobox-description">Location:</div><div style="width:50%">[[Template:Abbr/TBD]]</div></div></div><div class="fo-nttax-infobox-adbox"></div><div></div></div>
1 change: 1 addition & 0 deletions spec/golden_masters/infobox_league_starcraft2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="fo-nttax-infobox-wrapper infobox-starcraft2"><div class="fo-nttax-infobox"><div><div class="infobox-header wiki-backgroundcolor-light"><span class="infobox-buttons navigation-not-searchable">&#91;[https://liquipedia.net/wiki/ e]&#93;&#91;[[lpcommons:|h]]&#93;</span>FakePage</div></div><div><div class="infobox-header wiki-backgroundcolor-light infobox-header-2">League Information</div></div><div><div class="infobox-cell-2 infobox-description">Game Version:</div><div style="width:50%">[[Wings of Liberty|Wings of Liberty]]<br></div></div><div><div class="infobox-cell-2 infobox-description">Location:</div><div style="width:50%">[[Template:Abbr/TBD]]</div></div></div><div class="fo-nttax-infobox-adbox"></div><div></div></div>
1 change: 1 addition & 0 deletions spec/golden_masters/infobox_league_valorant.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="fo-nttax-infobox-wrapper infobox-valorant"><div class="fo-nttax-infobox"><div><div class="infobox-header wiki-backgroundcolor-light"><span class="infobox-buttons navigation-not-searchable">&#91;[https://liquipedia.net/wiki/ e]&#93;&#91;[[lpcommons:|h]]&#93;</span>FakePage</div></div><div><div class="infobox-header wiki-backgroundcolor-light infobox-header-2">League Information</div></div><div><div class="infobox-cell-2 infobox-description">Location:</div><div style="width:50%">[[Template:Abbr/TBD]]</div></div></div><div class="fo-nttax-infobox-adbox"></div><div></div></div>
19 changes: 19 additions & 0 deletions spec/infobox_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--- Triple Comment to Enable our LLS Plugin
insulate('Infobox', function()
insulate('League', function ()
allwikis('smoke', function (args, wikiName)
local LpdbSquadStub = stub(mw.ext.LiquipediaDB, 'lpdb_tournament')
local LpdbQueryStub = stub(mw.ext.LiquipediaDB, 'lpdb', {})
local InfoboxLeagueCustom = require('Module:Infobox/League/Custom')

GoldenTest('infobox_league_' .. wikiName, tostring(InfoboxLeagueCustom.run(args.input)))

LpdbSquadStub:revert()
LpdbQueryStub:revert()
end, {default = {
input = {
require('test_assets.tournaments').dummy
},
}})
end)
end)

0 comments on commit 068a4e3

Please sign in to comment.