forked from your-land-mirror/minetest-flow
Add (indirect) unit test for change_ctx
This commit is contained in:
parent
1528e87864
commit
8f0d86a53a
@ -65,16 +65,11 @@ local function embed_add_prefix(node, name, prefix)
|
||||
end
|
||||
end
|
||||
|
||||
-- TODO: Unit test this
|
||||
local change_ctx = ...
|
||||
|
||||
return function(self, fields)
|
||||
local player = fields.player
|
||||
local name = fields.name
|
||||
-- TODO: It might be cool to somehow pass elements down (number-indexes
|
||||
-- of fields) into the child form, but I'm not sure how that would look
|
||||
-- on the form definition side.
|
||||
-- Perhaps passing it in via the context, or an extra arg to _build?
|
||||
local parent_ctx = flow.get_context()
|
||||
if name == nil then
|
||||
-- Don't prefix anything if name is unspecified
|
||||
|
19
test.lua
19
test.lua
@ -929,14 +929,14 @@ describe("Flow", function()
|
||||
}
|
||||
end)
|
||||
it("raises an error if called outside of a form context", function()
|
||||
assert.has_error(function()
|
||||
assert.has_error(function()
|
||||
embedded_form:embed{
|
||||
-- It's fully possible that the API user would have access
|
||||
-- to a player reference
|
||||
player = stub_player"test_player",
|
||||
name = "theprefix"
|
||||
}
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
it("returns a flow widget", function ()
|
||||
test_render(function(p, _)
|
||||
@ -1132,5 +1132,20 @@ describe("Flow", function()
|
||||
gui.Field{name = "\2asdf\2field"}
|
||||
})
|
||||
end)
|
||||
it("updates flow.get_context", function()
|
||||
local form = flow.make_gui(function()
|
||||
assert.equals(flow.get_context().value, "inner")
|
||||
return gui.Label{label = "Hello"}
|
||||
end)
|
||||
test_render(function(p, ctx)
|
||||
ctx.value = "outer"
|
||||
ctx.inner = {value = "inner"}
|
||||
|
||||
assert.equals(flow.get_context().value, "outer")
|
||||
local embedded = form:embed{player = p, name = "test"}
|
||||
assert.equals(flow.get_context().value, "outer")
|
||||
return embedded
|
||||
end, gui.Label{label = "Hello"})
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user