mirror of
https://github.com/discourse/discourse.git
synced 2026-03-03 23:54:20 +08:00
Enable theme cards to show dark and light mode screenshots. ### Context Prior to this change, a single screenshot was displayed only. ### Changes * introduce separate fields: `screenshot_light_url` and `screenshot_dark_url` * displays both screenshots (horizontally scrollable) * limits display of screenshots to the files named `light` and `dark` only ### Result https://github.com/user-attachments/assets/4d845f32-9120-49b8-8f05-ba7790ce1629 --------- Co-authored-by: Yuriy Kurant <yuriy@discourse.org>
52 lines
1.6 KiB
Ruby
52 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe ThemeIndexSerializer do
|
|
fab!(:theme) { Fabricate(:theme, user_selectable: true) }
|
|
fab!(:screenshot_upload) do
|
|
UploadCreator.new(file_from_fixtures("logo.png"), "logo.png").create_for(-1)
|
|
end
|
|
fab!(:screenshot_field) do
|
|
Fabricate(
|
|
:theme_field,
|
|
theme:,
|
|
target_id: Theme.targets[:common],
|
|
name: "screenshot_light",
|
|
upload_id: screenshot_upload.id,
|
|
type_id: ThemeField.types[:theme_screenshot_upload_var],
|
|
)
|
|
end
|
|
|
|
let(:serializer) { ThemeIndexSerializer.new(theme, root: false) }
|
|
let(:json) { serializer.as_json }
|
|
|
|
it "includes basic theme attributes" do
|
|
expect(json[:id]).to eq(theme.id)
|
|
expect(json[:name]).to eq(theme.name)
|
|
expect(json[:enabled]).to eq(theme.enabled)
|
|
expect(json[:user_selectable]).to eq(true)
|
|
end
|
|
|
|
it "includes screenshot_light_url attribute" do
|
|
expect(json[:screenshot_light_url]).to eq(screenshot_upload.url)
|
|
end
|
|
|
|
it "includes color_scheme relationship when present" do
|
|
expect(json[:color_scheme]).to eq(nil)
|
|
|
|
theme.color_scheme = Fabricate(:color_scheme)
|
|
theme.save!
|
|
|
|
new_json = ThemeIndexSerializer.new(theme, root: false).as_json
|
|
expect(new_json[:color_scheme][:id]).to eq(theme.color_scheme.id)
|
|
end
|
|
|
|
it "includes remote_theme relationship when present" do
|
|
expect(json[:remote_theme]).to eq(nil)
|
|
|
|
remote_theme = RemoteTheme.create!(remote_url: "https://github.com/discourse/sample-theme")
|
|
theme.update!(remote_theme_id: remote_theme.id)
|
|
|
|
new_json = ThemeIndexSerializer.new(theme, root: false).as_json
|
|
expect(new_json[:remote_theme][:id]).to eq(remote_theme.id)
|
|
end
|
|
end
|