1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-02-03 13:11:21 +02:00
RedMew/utils/gui_tests.lua

52 lines
2.0 KiB
Lua
Raw Normal View History

2020-09-28 21:03:31 +01:00
local Declare = require 'utils.test.declare'
local Gui = require 'utils.gui'
local Assert = require 'utils.test.assert'
local Helper = require 'utils.test.helper'
2020-09-28 21:03:31 +01:00
2020-11-24 20:20:45 +00:00
Declare.module({'utils', 'Gui'}, function()
Declare.module('can toggle top buttons', function()
local function count_gui_elements(player)
-- local gui = player.gui
-- return #gui.top.children + #gui.left.children + #gui.center.children + #gui.screen.children
return #Gui.get_top_flow(player).children + #Gui.get_left_flow(player).children + #player.gui.center.children + #player.gui.screen.children
end
local function is_ignored_element(element)
local tooltip = element.tooltip
if type(tooltip) == 'table' and tooltip[1] == 'evolution_progress.tooltip' then
return true
end
return false
2020-11-24 20:20:45 +00:00
end
for _, name in pairs(Gui._top_elements) do
April fools maps (#1404) * Upload pinguin scenario * Fix relative path * Pinguin scenario modularization * Update enemy_turrets.lua Added energy interface controls to limit power available to enemy laser turrets, with laser_shots_per_level constant for balancing. * Update floor_is_lava.lua Now spawns fire under players when level is half of max. * Explosion Scare Module Added explosion_scare module. Chooses players to randomly explode (non-damaging) a number of times before switching to new targets. Explosion intensity increases as module increases. * Update pinguin.lua Removed comment block over modules. * Added New Module: permanent_factory Has a very small chance to make an entity unminable and undestructible when placed. * MeteOres Added new module: MeteOres. Spawns a random meteor that damages entities, creates ore, and spawns biters. * Update meteOres.lua Added explosion to meteor * Added Auto Build Added auto_build module. Selects random players, and automatically builds the item in their cursor nearby for a while, before changing targets. * New module: Unorganized Recipes Added a new module to hide recipe groups and subgroups for random players. This leads to "unorganized" crafting menus. * Update auto_build.lua Fixed typo. I must have changed base targets to 0 instead of the global level when preparing this file for commit. * Add Biter Ores Module Add new module. Spawns ores on death of biters, worms, and spawners, based on difficulty of biter and level. looks for ores on the tile the biter dies on to add to, otherwise looks nearby for an ore type and uses that, otherwise decides on a new ore type to spawn. This should allow players to set up "farms" for their ores, creating reasonable ore patches. Contains a RANDOM_ORES constant that will make the search radius small and ensure random ores are placed instead. * Update biter_ores.lua Found typo. radius should be .1 not 1 for tile directly beneath biter. * Updated Existing Modules Got luacheck setup in my IDE so we don't have to wait for RedMew to run it. Fixed white-space and other linting errors. * Split AF scenarios * Add alien biomes module * Draft april-fools scenarios * Fix draft issues --------- Co-authored-by: R. Nukem <Reoisasa@gmail.com>
2024-03-29 00:27:27 +01:00
Declare.test(Gui.names and Gui.names[name] or name, function(context)
2020-11-24 20:20:45 +00:00
local player = context.player
local element = Gui.get_top_flow(player)[name]
2020-11-24 20:20:45 +00:00
if not element.enabled or is_ignored_element(element) then
2020-11-24 20:20:45 +00:00
return
2020-09-28 21:03:31 +01:00
end
2020-11-24 20:20:45 +00:00
local click_action = function()
Helper.click(element)
2020-09-28 21:03:31 +01:00
end
2020-11-24 20:20:45 +00:00
local before_count = count_gui_elements(player)
2020-11-24 20:20:45 +00:00
-- Open
click_action()
local after_open_count = count_gui_elements(player)
2020-11-24 20:20:45 +00:00
Assert.is_true(after_open_count > before_count, 'after open count should be greater than before count.')
-- Close
context:next(click_action):next(function()
local after_close_count = count_gui_elements(player)
2020-11-24 20:20:45 +00:00
Assert.equal(before_count, after_close_count, 'after close count should be equal to before count.')
end)
end)
end
end)
end)