Update tests

This commit is contained in:
Insality
2025-04-17 19:18:40 +03:00
parent d1d54896fb
commit 0d0581b108
25 changed files with 1672 additions and 320 deletions

View File

@@ -1,49 +1,53 @@
return function()
local mock_gui = nil
local mock_time = nil
local mock_input = nil
local test_helper = nil
local druid_system = nil
local druid = nil
local context = nil
describe("Back Handler component", function()
local mock_time
local mock_input
local druid_system
local druid
local context
before(function()
mock_gui = require("deftest.mock.gui")
mock_time = require("deftest.mock.time")
mock_input = require("test.helper.mock_input")
test_helper = require("test.helper.test_helper")
druid_system = require("druid.druid")
mock_gui.mock()
mock_time.mock()
mock_time.set(60)
mock_time.set(0)
context = test_helper.get_context()
context = vmath.vector3()
druid = druid_system.new(context)
end)
after(function()
mock_gui.unmock()
mock_time.unmock()
druid:final(context)
druid:final()
druid = nil
end)
it("Should react on back action id with custom args", function()
local on_back_handler, on_back_handler_mock = test_helper.get_function()
druid:new_back_handler(on_back_handler, { args = "custom" })
local is_back_handler_called = false
local context_arg = nil
local back_handler_args = nil
druid:new_back_handler(function(self, args)
context_arg = self
is_back_handler_called = true
back_handler_args = args
end, "custom")
druid:on_input(mock_input.key_pressed("key_back"))
druid:on_input(mock_input.key_released("key_back"))
assert(on_back_handler_mock.calls == 1)
assert(on_back_handler_mock.params[1] == context)
assert(on_back_handler_mock.params[2].args == "custom")
assert(is_back_handler_called)
assert(back_handler_args == "custom")
assert(context_arg == context)
is_back_handler_called = false
druid:on_input(mock_input.key_pressed("key_a"))
druid:on_input(mock_input.key_released("key_a"))
assert(on_back_handler_mock.calls == 1)
assert(is_back_handler_called == false)
end)
end)
end