diff --git a/lib/basket_web/live/overview.ex b/lib/basket_web/live/overview.ex index 79796d7..c82e426 100644 --- a/lib/basket_web/live/overview.ex +++ b/lib/basket_web/live/overview.ex @@ -15,6 +15,7 @@ defmodule BasketWeb.Overview do prop tickers, :list, default: [] def mount(_, _, socket) do + IO.inspect("SOCKET: #{inspect(socket)}") BasketWeb.Endpoint.subscribe(Alpaca.bars_topic()) socket = assign(socket, tickers: []) diff --git a/test/basket_web/live/overview_test.exs b/test/basket_web/live/overview_test.exs index e500c3b..4907d20 100644 --- a/test/basket_web/live/overview_test.exs +++ b/test/basket_web/live/overview_test.exs @@ -1,11 +1,60 @@ defmodule BasketWeb.OverviewTest do use BasketWeb.ConnCase + require Phoenix.LiveViewTest + import Mox - test "mount/3" do - Basket.Websocket.MockAlpaca |> expect(:start_link, fn state -> {:ok, 1} end) + alias BasketWeb.Overview + + @assigns_map %{__changed__: %{__context__: true}} + @socket %{ + assigns: @assigns_map, + __context__: %{}, + flash: %{}, + live_action: nil + } + + describe "mount/3" do + test "assigns empty lists to keys" do + Basket.Websocket.MockAlpaca |> expect(:start_link, fn state -> {:ok, 1} end) + + assert({:ok, socket} = Overview.mount([], %{}, @assigns_map)) + + assert( + socket == %{ + __changed__: %{__context__: true, basket: true, tickers: true}, + __context__: %{}, + basket: [], + tickers: [] + } + ) + end + end + + describe "handle_event/3" do + test "ticker search does nothing without search criteria" do + assert {:noreply, socket} = + Overview.handle_event( + "ticker-search", + %{"selected-ticker" => "ABC"}, + Map.merge(@assigns_map, %{assigns: %{tickers: ["ABC", "XYZ"]}}) + ) + end + + # test "ticker search updates the ticker list" do + # assert {:reply, %{}, socket} = + # Overview.handle_event( + # "ticker-search", + # %{"selected-ticker" => "XYZ"}, + # Map.merge(@assigns_map, %{assigns: %{tickers: ["ABC", "XYZ"]}}) + # ) - Basket.Websocket.Alpaca.start_link("statee") |> IO.inspect(label: "RESULT") + # assert socket == %{ + # __changed__: %{__context__: true, tickers: true}, + # __context__: %{}, + # tickers: ["XYZ"] + # } + # end end end