-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add some test cases for dashboard map * Make sure invalid locations doesn't render marker.
- Loading branch information
Showing
3 changed files
with
114 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
defmodule NervesHubWeb.Live.Product.DashboardTest do | ||
use NervesHubWeb.ConnCase.Browser, async: true | ||
|
||
alias NervesHub.Devices | ||
alias NervesHub.Devices.Device | ||
alias NervesHubWeb.Endpoint | ||
|
||
alias Phoenix.Socket.Broadcast | ||
|
||
@valid_location %{ | ||
"latitude" => 60.6204, | ||
"longitude" => 16.7697, | ||
"source" => "geoip" | ||
} | ||
|
||
@invalid_location %{ | ||
"latitude" => 60.6204, | ||
"source" => "geoip" | ||
} | ||
|
||
setup %{fixture: %{device: device}} do | ||
Endpoint.subscribe("device:#{device.id}") | ||
end | ||
|
||
describe "dashboard map" do | ||
test "assert devices with location data renders map and marker info", %{ | ||
conn: conn, | ||
org: org, | ||
product: product, | ||
device: device | ||
} do | ||
assert {:ok, %Device{}} = | ||
Devices.update_device(device, %{ | ||
connection_metadata: %{"location" => @valid_location} | ||
}) | ||
|
||
conn | ||
|> visit("/org/#{org.name}/#{product.name}/dashboard") | ||
|> assert_has("#map") | ||
|> assert_has("#map-markers") | ||
end | ||
|
||
test "assert page render without locations ", %{ | ||
conn: conn, | ||
org: org, | ||
product: product, | ||
device: device | ||
} do | ||
assert device.connection_metadata["location"] == nil | ||
|
||
conn | ||
|> visit("/org/#{org.name}/#{product.name}/dashboard") | ||
|> assert_has("h3", text: "#{product.name} doesn’t have any devices with location data.") | ||
end | ||
|
||
test "assert page render without devices", %{ | ||
conn: conn, | ||
org: org, | ||
product: product, | ||
device: device | ||
} do | ||
assert {:ok, _} = Devices.delete_device(device) | ||
|
||
conn | ||
|> visit("/org/#{org.name}/#{product.name}/dashboard") | ||
|> assert_has("h3", text: "#{product.name} doesn’t have any devices yet.") | ||
end | ||
|
||
test "assert page still render with invalid location data", %{ | ||
conn: conn, | ||
org: org, | ||
product: product, | ||
device: device | ||
} do | ||
assert {:ok, %Device{}} = | ||
Devices.update_device(device, %{ | ||
connection_metadata: %{"location" => @invalid_location} | ||
}) | ||
|
||
conn | ||
|> visit("/org/#{org.name}/#{product.name}/dashboard") | ||
|> assert_has("h3", text: "#{product.name} doesn’t have any devices with location data.") | ||
end | ||
|
||
test "handle_info - location:update", %{ | ||
conn: conn, | ||
org: org, | ||
product: product, | ||
device: device | ||
} do | ||
conn | ||
|> visit("/org/#{org.name}/#{product.name}/dashboard") | ||
|> assert_has("#map") | ||
|> assert_has("h3", text: "#{product.name} doesn’t have any devices with location data.") | ||
|> unwrap(fn view -> | ||
{:ok, _} = | ||
Devices.update_device(device, %{connection_metadata: %{"location" => @valid_location}}) | ||
|
||
send(view.pid, %Broadcast{event: "location:updated", payload: @valid_location}) | ||
render(view) | ||
end) | ||
|> refute_has("h3", text: "#{product.name} doesn’t have any devices with location data.") | ||
|> assert_has("#map-markers") | ||
end | ||
end | ||
end |