Indicate when a (car) software update is available

This commit is contained in:
Adrian Kumpf
2019-10-17 00:50:56 +02:00
parent dca44e141f
commit 5dff59a7bf
10 changed files with 90 additions and 12 deletions
@@ -42,7 +42,8 @@ defmodule TeslaMate.Mqtt.PubSub.VehicleSubscriberTest do
locked: true,
sentry_mode: false,
plugged_in: false,
version: "2019.42"
version: "2019.42",
update_available: false
}
send(pid, summary)
@@ -5,6 +5,7 @@ defmodule TeslaMate.Vehicles.Vehicle.UpdatingTest do
test "logs an update cycle", %{test: name} do
events = [
{:ok, online_event()},
{:ok, update_event("available", nil)},
{:ok, update_event("installing", "2019.8.4 530d1d3")},
{:ok, update_event("installing", "2019.8.4 530d1d3")},
{:ok, update_event("installing", "2019.8.4 530d1d3")},
@@ -19,7 +20,10 @@ defmodule TeslaMate.Vehicles.Vehicle.UpdatingTest do
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _server, _topic, %Summary{state: :online, since: s0}}}
assert_receive {:pubsub,
{:broadcast, _server, _topic,
%Summary{state: :online, since: s0, update_available: true}}}
assert_receive {:start_update, ^car_id}
@@ -46,6 +50,7 @@ defmodule TeslaMate.Vehicles.Vehicle.UpdatingTest do
test "logs an update if the status is not empty", %{test: name} do
events = [
{:ok, online_event()},
{:ok, update_event("available", nil)},
{:ok, update_event("installing", "2019.8.4 530d1d3")},
{:ok, update_event("foo", "2019.8.5 3aaa23d")}
]
@@ -54,7 +59,10 @@ defmodule TeslaMate.Vehicles.Vehicle.UpdatingTest do
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _server, _topic, %Summary{state: :online, since: s0}}}
assert_receive {:pubsub,
{:broadcast, _server, _topic,
%Summary{state: :online, since: s0, update_available: true}}}
assert_receive {:start_update, ^car_id}
assert_receive {:pubsub, {:broadcast, _server, _topic, %Summary{state: :updating, since: s1}}}
@@ -163,6 +163,28 @@ defmodule TeslaMateWeb.CarLive.SummaryTest do
end
end
describe "tags" do
@tag :signed_in
@tag :capture_log
test "shows tag if update is available ", %{conn: conn} do
events = [
{:ok, online_event()},
{:ok, update_event("available", nil)},
{:error, :unknown}
]
:ok = start_vehicles(events)
Process.sleep(300)
assert {:ok, _parent_view, html} =
live(conn, "/", connect_params: %{"baseUrl" => "http://localhost"})
assert [{"span", _, [{"span", _, _}, " Software Update available"]}] =
html |> Floki.find(".update-available")
end
end
def start_vehicles(events \\ []) do
{:ok, _pid} = start_supervised({ApiMock, name: :api_vehicle, events: events, pid: self()})