diff --git a/app/views/beacons/_summary.html.erb b/app/views/beacons/_summary.html.erb new file mode 100644 index 00000000..f48634e3 --- /dev/null +++ b/app/views/beacons/_summary.html.erb @@ -0,0 +1,43 @@ +
+
+
+
+

Total Beacons

+

<%= @beacons.count %>

+
+
+ + + +
+
+
+ +
+
+
+

Online Now

+

<%= @beacons.count { |b| b[:online] } %>

+
+
+ + + +
+
+
+ +
+
+
+

Offline

+

<%= @beacons.count { |b| !b[:online] } %>

+
+
+ + + +
+
+
+
diff --git a/app/views/beacons/_table.html.erb b/app/views/beacons/_table.html.erb new file mode 100644 index 00000000..e815878a --- /dev/null +++ b/app/views/beacons/_table.html.erb @@ -0,0 +1,85 @@ +
+
+ + + + + + + + + + + + + + <% if @beacons.any? %> + <% @beacons.each do |beacon| %> + + + + + + + + + + <% end %> + <% else %> + + + + <% end %> + +
StatusBeacon NameCurrent Manifest VersionLatest Manifest VersionUp to Date?Last Seen atLast Sync at
+
+ + + <%= beacon.revoked? ? 'Revoked' : 'Active' %> + +
+
+ <%= link_to beacon_path(beacon), class: "no-underline" do %> +
+
+ + + +
+
+
<%= beacon.name %>
+
<%= beacon.api_key_prefix %>***
+
+
+ <% end %> +
+ + current manifest + + + + latest manifest + + + + is up to date? + + + + last seen at + + + + last sync at + +
+
+ + + +

No beacons provisioned yet

+

Get started by provisioning your first beacon.

+
+
+
+
diff --git a/app/views/beacons/index.html.erb b/app/views/beacons/index.html.erb index a63ee2e0..793fed29 100644 --- a/app/views/beacons/index.html.erb +++ b/app/views/beacons/index.html.erb @@ -21,7 +21,7 @@
- Active: <%= @beacons.count { |b| !b.revoked? } %> / + Active: <%= @beacons.count { |b| !b.revoked? } %> / Revoked: <%= @beacons.count { |b| b.revoked? } %>
@@ -36,136 +36,9 @@
- -
-
- - - - - - - - - - - - - - <% if @beacons.any? %> - <% @beacons.each do |beacon| %> - - - - - - - - - - <% end %> - <% else %> - - - - <% end %> - -
StatusBeacon NameCurrent Manifest VersionLatest Manifest VersionUp to Date?Last Seen atLast Sync at
-
- - - <%= beacon.revoked? ? 'Revoked' : 'Active' %> - -
-
- <%= link_to beacon_path(beacon), class: "no-underline" do %> -
-
- - - -
-
-
<%= beacon.name %>
-
<%= beacon.api_key_prefix %>***
-
-
- <% end %> -
- - current manifest - - - - latest manifest - - - - is up to date? - - - - last seen at - - - - last sync at - -
-
- - - -

No beacons provisioned yet

-

Get started by provisioning your first beacon.

-
-
-
-
+ <%= render "summary" %> - -
-
-
-
-

Total Beacons

-

<%= @beacons.count %>

-
-
- - - -
-
-
+ <%= render "table" %> -
-
-
-

Online Now

-

<%= @beacons.count { |b| b[:online] } %>

-
-
- - - -
-
-
- -
-
-
-

Offline

-

<%= @beacons.count { |b| !b[:online] } %>

-
-
- - - -
-
-
-
diff --git a/db/seeds.rb b/db/seeds.rb index 6b9540bc..fb42ee02 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -15,6 +15,14 @@ User.destroy_all Tag.destroy_all +puts "Creating regions..." + +[ "Northeast", "Southeast", "Midwest", "Southwest", "West" ].each do |name| + Region.find_or_create_by!(name: name) +end + +puts "Regions created!" + puts "Creating languages..." [ diff --git a/spec/views/beacons/index.html.erb_spec.rb b/spec/views/beacons/index.html.erb_spec.rb new file mode 100644 index 00000000..2a5e7b43 --- /dev/null +++ b/spec/views/beacons/index.html.erb_spec.rb @@ -0,0 +1,69 @@ +require "rails_helper" + +RSpec.describe "beacons/index", type: :view do + context "when there are no beacons" do + before do + assign(:beacons, []) + end + + it "renders an empty state message" do + render + assert_select "td", text: /No beacons provisioned yet/ + end + + it "renders the provision new beacon link" do + render + assert_select "a", text: /Provision New Beacon/ + end + end + + context "when there are beacons" do + let(:active_beacon) { create(:beacon) } + let(:revoked_beacon) { create(:beacon, :revoked) } + + before do + assign(:beacons, [active_beacon, revoked_beacon]) + end + + it "renders a row for each beacon" do + render + assert_select "table tbody tr", count: 2 + end + + it "shows Active status for active beacons" do + render + assert_select "td span", text: "Active" + end + + it "shows Revoked status for revoked beacons" do + render + assert_select "td span", text: "Revoked" + end + + it "renders each beacon name" do + render + assert_select "td", text: /#{active_beacon.name}/ + assert_select "td", text: /#{revoked_beacon.name}/ + end + + it "shows the active count in the header" do + render + assert_select "span.text-green-600", text: "1" + end + + it "shows the revoked count in the header" do + render + assert_select "span.text-red-600", text: "1" + end + + it "shows the total beacon count in the summary" do + render + assert_select "p.text-3xl", text: "2" + end + + it "renders the Status column header without text wrapping" do + render + assert_select "th.whitespace-nowrap", text: /Status/ + end + end +end