Fix nested frame updates (#1251)

This commit is contained in:
Jonatan Kłosko 2022-06-29 21:04:27 +01:00 committed by GitHub
parent cb0a208274
commit 5c0ad7ba1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -722,7 +722,7 @@ defmodule Livebook.Notebook do
end
defp do_find_frame_outputs({_idx, {:frame, outputs, _info}}, ref) do
Enum.flat_map(outputs, &find_frame_outputs(&1, ref))
Enum.flat_map(outputs, &do_find_frame_outputs(&1, ref))
end
defp do_find_frame_outputs(_output, _ref) do

View file

@ -403,4 +403,29 @@ defmodule Livebook.NotebookTest do
)
end
end
describe "find_frame_outputs/2" do
test "returns frame outputs with matching ref" do
frame_output = {0, {:frame, [], %{ref: "1", type: :default}}}
notebook = %{
Notebook.new()
| sections: [%{Section.new() | cells: [%{Cell.new(:code) | outputs: [frame_output]}]}]
}
assert [^frame_output] = Notebook.find_frame_outputs(notebook, "1")
end
test "finds a nested frame" do
nested_frame_output = {0, {:frame, [], %{ref: "2", type: :default}}}
frame_output = {0, {:frame, [nested_frame_output], %{ref: "1", type: :default}}}
notebook = %{
Notebook.new()
| sections: [%{Section.new() | cells: [%{Cell.new(:code) | outputs: [frame_output]}]}]
}
assert [^nested_frame_output] = Notebook.find_frame_outputs(notebook, "2")
end
end
end