Skip to content

Commit 09b113e

Browse files
ihabadhamclaude
andcommitted
Add request + system specs for the RSC demo
Request spec mirrors the dummy's `requests/rsc_payload_spec.rb` pattern (NDJSON parsing, html-chunk presence). Covers: - GET /server-components returns the demo page shell - /rsc_payload/ServerComponentsPage streams a valid NDJSON payload - /rsc_payload/LiveActivity streams a valid NDJSON payload System spec covers the user-facing behaviors of the new sections: - Page renders the four demo section headings - ServerInfo labels appear (Platform, Architecture, Node.js, CPU Cores) - Live Activity shows the live stats labels + initial Refresh count - Refresh button increments the counter (RSCRoute fetch happens) - Simulate Error → ErrorBoundary fallback → Retry recovers Tests behaviors only — no internal state assertions, no specific values (server time, RAM number) that would be flaky. Uses existing rails_helper infrastructure (headless Chrome via DriverRegistration, Capybara defaults). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0b626bc commit 09b113e

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
describe "Server Components" do
6+
it "GET /server-components returns the demo page shell" do
7+
get "/server-components"
8+
expect(response).to have_http_status(:ok)
9+
expect(response.body).to include("React Server Components Demo")
10+
end
11+
12+
describe "RSC payload endpoint" do
13+
def parsed_chunks
14+
response.body.each_line.filter_map do |line|
15+
stripped = line.strip
16+
next if stripped.empty?
17+
18+
JSON.parse(stripped)
19+
end
20+
end
21+
22+
def expect_valid_rsc_payload
23+
expect(response).to have_http_status(:ok)
24+
expect(response.media_type).to eq("application/x-ndjson")
25+
chunks = parsed_chunks
26+
expect(chunks).not_to be_empty
27+
expect(chunks.any? { |chunk| chunk.key?("html") }).to be(true)
28+
end
29+
30+
it "streams a valid RSC payload for ServerComponentsPage" do
31+
get "/rsc_payload/ServerComponentsPage", params: { props: "{}" }
32+
expect_valid_rsc_payload
33+
end
34+
35+
it "streams a valid RSC payload for LiveActivity" do
36+
get "/rsc_payload/LiveActivity", params: { props: "{}" }
37+
expect_valid_rsc_payload
38+
end
39+
end
40+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
describe "Server Components demo" do
6+
before { visit "/server-components" }
7+
8+
it "renders the four demo sections" do
9+
expect(page).to have_selector("h2", text: "Server Environment")
10+
expect(page).to have_selector("h2", text: "Interactive Client Component")
11+
expect(page).to have_selector("h2", text: "Live Server Activity")
12+
expect(page).to have_selector("h2", text: "Streamed Comments")
13+
end
14+
15+
it "shows server-side data in ServerInfo" do
16+
expect(page).to have_content("Platform")
17+
expect(page).to have_content("Architecture")
18+
expect(page).to have_content("Node.js")
19+
expect(page).to have_content("CPU Cores")
20+
end
21+
22+
describe "Live Server Activity (RSCRoute)" do
23+
it "shows the initial activity card with the live stats labels" do
24+
expect(page).to have_content("SERVER TIME")
25+
expect(page).to have_content("FREE RAM")
26+
expect(page).to have_content("UPTIME (HRS)")
27+
expect(page).to have_content("Refresh count: 0")
28+
end
29+
30+
it "updates content when Refresh is clicked" do
31+
click_button "Refresh"
32+
expect(page).to have_content("Refresh count: 1")
33+
end
34+
35+
it "shows the ErrorBoundary fallback when Simulate Error is clicked, then recovers on Retry" do
36+
click_button "Simulate Error"
37+
expect(page).to have_content("Server component fetch failed")
38+
39+
click_button "Retry"
40+
expect(page).to have_content("SERVER TIME")
41+
expect(page).to have_no_content("Server component fetch failed")
42+
end
43+
end
44+
end

0 commit comments

Comments
 (0)