discourse/spec/system/user_api_key_show_spec.rb
Penar Musaraj ef406fc8c0
DEV: Add theme screenshots system spec and skill (#39426)
Previously, there was no systematic way to visually review changes
across multiple screens in a theme. Or to compare how Foundation and
Horizon render key UI screens

This adds a `screenshot_marker(label:)` helper in system specs (globally
included via ThemeScreenshotMarker) that captures a PNG at that point in
a test. A matrix runner spec at `theme_screenshots_spec.rb`
auto-discovers any system spec containing screenshot markers and runs
those blocks against each theme × color mode × device combination. At
the end it generates a `compare.html` viewer for side-by-side
comparison.

<img width="3399" height="1400" alt="image"
src="https://github.com/user-attachments/assets/4ddd650a-6133-4da5-901e-5ec2f2d0906a"
/>


This can be run via CLI or via the attached skill. Directly:

### All themes × light/dark × desktop/mobile (default)
TAKE_SCREENSHOTS=1 bin/rspec spec/system/theme_screenshots_spec.rb


#### Foundation only, dark mode, desktop only
TAKE_SCREENSHOTS=1 SCREENSHOTS_THEMES=foundation SCREENSHOTS_MODES=dark
SCREENSHOTS_DEVICES=desktop bin/rspec
spec/system/theme_screenshots_spec.rb

#### Third-party theme in addition to core themes
TAKE_SCREENSHOTS=1
SCREENSHOTS_THEME_URL=https://github.com/discourse/discourse-air
bin/rspec spec/system/theme_screenshots_spec.rb



You can also run this via the agent skill, which builds the command from
natural language: `/discourse-screenshots` for the full default matrix,
or `/discourse-screenshots foundation only, dark only, desktop` and
similar limited runs.

### Use cases

- review broad changes in core against key UI screens across the app
- compare layouts/screens between core themes and/or a custom theme
- preview a new theme's look and feel across different areas of the app

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-05 09:36:29 -04:00

45 lines
1.6 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe "User API Key Show Page" do
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
let(:cdp) { PageObjects::CDP.new }
let(:public_key) { OpenSSL::PKey::RSA.new(2048).public_key.to_pem }
before { SiteSetting.user_api_key_allowed_groups = Group::AUTO_GROUPS[:trust_level_0] }
it "displays the copy button and copies the payload without whitespace" do
sign_in(user)
# Visit the authorization page (no auth_redirect means show page after submit)
visit "/user-api-key/new?#{URI.encode_www_form(scopes: "read", client_id: "x" * 32, application_name: "Test Application", public_key: public_key, nonce: SecureRandom.hex)}"
screenshot_marker(label: "user-api-key-auth")
# Submit the authorization form
click_button I18n.t("user_api_key.authorize")
# Now we should be on the show page
expect(page).to have_css("#user-api-key-payload")
expect(page).to have_css("#copy-api-key-btn")
cdp.allow_clipboard
displayed_payload = find("#user-api-key-payload").text
# The displayed payload should have whitespace (rendered from newlines in Base64.encode64)
expect(displayed_payload).to match(/\s/)
find("#copy-api-key-btn").click
# Verify button text changes to "Copied"
expect(page).to have_button(I18n.t("user_api_key.copied"))
# Verify clipboard contains payload without whitespace
clipboard_content = cdp.read_clipboard
expect(clipboard_content).not_to match(/\s/)
# Verify the copied content can be base64 decoded
expect { Base64.decode64(clipboard_content) }.not_to raise_error
end
end