diff --git a/embed.lua b/embed.lua index 374573e..05076ca 100644 --- a/embed.lua +++ b/embed.lua @@ -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 diff --git a/test.lua b/test.lua index e34f273..e6f9050 100644 --- a/test.lua +++ b/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)