Skip to content

Commit

Permalink
initial overview unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daveminer committed Nov 15, 2023
1 parent c569eb3 commit 3e8e9d6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/basket_web/live/overview.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule BasketWeb.Overview do
prop tickers, :list, default: []

def mount(_, _, socket) do
IO.inspect("SOCKET: #{inspect(socket)}")

Check warning on line 18 in lib/basket_web/live/overview.ex

View workflow job for this annotation

GitHub Actions / test

There should be no calls to IO.inspect/1.
BasketWeb.Endpoint.subscribe(Alpaca.bars_topic())

socket = assign(socket, tickers: [])
Expand Down
55 changes: 52 additions & 3 deletions test/basket_web/live/overview_test.exs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3e8e9d6

Please sign in to comment.