Skip to content

Commit

Permalink
test: assert_push_event for other liveviews
Browse files Browse the repository at this point in the history
  • Loading branch information
sorax committed Mar 18, 2024
1 parent 2c82baa commit 331c0e1
Showing 1 changed file with 43 additions and 14 deletions.
57 changes: 43 additions & 14 deletions test/radiator_web/live/episode_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,41 @@ defmodule RadiatorWeb.EpisodeLiveTest do
setup %{conn: conn} do
user = user_fixture()
show = show_fixture()
episode = episode_fixture(%{show_id: show.id})
node = node_fixture(%{episode_id: episode.id})

%{conn: log_in_user(conn, user), show: show, node: node}
%{conn: log_in_user(conn, user), show: show}
end

test "has the title of the episode", %{conn: conn, show: show} do
{:ok, live, _html} = live(conn, ~p"/admin/podcast/#{show.id}")

assert page_title(live) =~ show.title
end
end

describe "Episode outline nodes" do
setup %{conn: conn} do
user = user_fixture()
show = show_fixture()
episode = episode_fixture(%{show_id: show.id})

node_1 = node_fixture(%{episode_id: episode.id})
node_2 = node_fixture(%{episode_id: episode.id, prev_id: node_1.uuid})
_node_21 = node_fixture(%{episode_id: episode.id, parent_id: node_2.uuid})

%{conn: log_in_user(conn, user), show: show, episode: episode}
end

test "lists all nodes", %{conn: conn, show: show, node: node} do
test "lists all nodes", %{conn: conn, show: show} do
{:ok, live, _html} = live(conn, ~p"/admin/podcast/#{show.id}")

assert_push_event(live, "list", %{nodes: [^node]})
nodes = Outline.list_nodes()

assert_push_event(live, "list", %{nodes: ^nodes})
end

test "create a new node", %{conn: conn, show: show} do
test "insert a new node", %{conn: conn, show: show} do
{:ok, live, _html} = live(conn, ~p"/admin/podcast/#{show.id}")
{:ok, other_live, _html} = live(conn, ~p"/admin/podcast/#{show.id}")

temp_id = "f894d2ed-9447-4eef-8c31-fc52372b3bbe"
params = %{"temp_id" => temp_id, "content" => "new node temp content"}
Expand All @@ -62,13 +77,19 @@ defmodule RadiatorWeb.EpisodeLiveTest do
node =
Outline.list_nodes()
|> Enum.find(&(&1.content == "new node temp content"))
|> Map.put(:temp_id, temp_id)

assert_reply(live, ^node)
node_with_temp_id = Map.put(node, :temp_id, temp_id)

assert_reply(live, ^node_with_temp_id)

assert_push_event(other_live, "insert", ^node)
end

test "update node", %{conn: conn, show: show, node: node} do
test "update node", %{conn: conn, show: show, episode: episode} do
{:ok, live, _html} = live(conn, ~p"/admin/podcast/#{show.id}")
{:ok, other_live, _html} = live(conn, ~p"/admin/podcast/#{show.id}")

node = node_fixture(%{episode_id: episode.id})

params =
node
Expand All @@ -83,14 +104,22 @@ defmodule RadiatorWeb.EpisodeLiveTest do

assert updated_node.uuid == params.uuid
assert updated_node.content == params.content

assert_push_event(other_live, "update", ^updated_node)
end

# {:ok, pid} = MyGenServer.start_link()
test "delete node", %{conn: conn, show: show, episode: episode} do
{:ok, live, _html} = live(conn, ~p"/admin/podcast/#{show.id}")
{:ok, other_live, _html} = live(conn, ~p"/admin/podcast/#{show.id}")

node = node_fixture(%{episode_id: episode.id})
params = Map.from_struct(node)

# send(self(), :hello)
# send(pid, {:some_message, self()})
assert live |> render_hook(:delete_node, params)

# assert_received {:handle_info, {:some_message, self()}, _state}
# assert_push_event(live, "insert", %{nodes: [%{content: "new node content"}]})
assert_push_event(other_live, "delete", %{uuid: deleted_uuid})

assert deleted_uuid == node.uuid
end
end
end

0 comments on commit 331c0e1

Please sign in to comment.