diff --git a/app/views/solid_stack_web/cable/index.html.erb b/app/views/solid_stack_web/cable/index.html.erb
index 7d06a1a..86e1103 100644
--- a/app/views/solid_stack_web/cable/index.html.erb
+++ b/app/views/solid_stack_web/cable/index.html.erb
@@ -16,12 +16,24 @@
<% if @channels.any? %>
- | Channel |
+
+ | Channel |
+ Messages |
+ Last Message |
+
<% @channels.each do |channel| %>
- | <%= channel %> |
+
+ | <%= channel[:channel] %> |
+ <%= channel[:message_count] %> |
+ <%= channel[:last_message_at]&.strftime("%b %d %H:%M") %> |
+
<% end %>
+<% else %>
+
<% end %>
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index de97119..da5676a 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -16,4 +16,5 @@
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!
+ config.include ActiveSupport::Testing::TimeHelpers
end
diff --git a/spec/requests/solid_stack_web/cable_spec.rb b/spec/requests/solid_stack_web/cable_spec.rb
index a3e94e7..308cc93 100644
--- a/spec/requests/solid_stack_web/cable_spec.rb
+++ b/spec/requests/solid_stack_web/cable_spec.rb
@@ -42,9 +42,36 @@
get "#{engine_root}/cable"
- # 2 distinct channels, stat value should be 2 (not 3 messages)
expect(response.body).to include("Channels")
expect(response.body).to match(/class="sqw-stat__value">\s*2\s*)
end
+
+ it "shows message count and last message time per channel" do
+ SolidCable::Message.broadcast("sports:scores", "goal!")
+ SolidCable::Message.broadcast("sports:scores", "offside")
+
+ get "#{engine_root}/cable"
+
+ expect(response.body).to include("sports:scores")
+ expect(response.body).to include("Messages")
+ expect(response.body).to include("Last Message")
+ end
+
+ it "orders channels by most recent message first" do
+ SolidCable::Message.broadcast("older:channel", "first")
+ travel 1.second do
+ SolidCable::Message.broadcast("newer:channel", "second")
+ end
+
+ get "#{engine_root}/cable"
+
+ expect(response.body.index("newer:channel")).to be < response.body.index("older:channel")
+ end
+
+ it "shows empty state when no messages exist" do
+ SolidCable::Message.delete_all
+ get "#{engine_root}/cable"
+ expect(response.body).to include("No cable messages")
+ end
end
end