Files
discourse/spec/serializers/component_index_serializer_spec.rb
Osama Sayegh ad0966afa9 FEATURE: Introduce new components listing page (#32164)
Follow-up to https://github.com/discourse/discourse/pull/31887

This commit introduces a new design for the components listing page, which
is not linked from anywhere in the UI at the moment, but it can be
accessed by heading to the `/admin/config/customize/components` path
directly. We'll make this new design available from the sidebar and
remove the old page once we've tested and validated the new design
internally.

Internal topic: t/146007.

---------

Co-authored-by: Ella <ella.estigoy@gmail.com>
2025-04-08 17:58:29 +03:00

57 lines
1.5 KiB
Ruby

# frozen_string_literal: true
RSpec.describe ComponentIndexSerializer do
fab!(:theme_1) { Fabricate(:theme) }
fab!(:theme_2) { Fabricate(:theme) }
fab!(:component) do
Fabricate(
:theme,
component: true,
parent_themes: [theme_1, theme_2],
remote_theme:
RemoteTheme.create!(
remote_url: "https://github.com/discourse/discourse.git",
commits_behind: 3,
authors: "CDCK Inc.",
),
theme_fields: [
ThemeField.new(
name: "en",
type_id: ThemeField.types[:yaml],
target_id: Theme.targets[:translations],
value: <<~YAML,
en:
theme_metadata:
description: "Description of my component"
YAML
),
],
)
end
let(:json) { described_class.new(component, root: false).as_json }
it "includes remote_theme object" do
expect(json[:remote_theme][:id]).to eq(component.remote_theme.id)
expect(json[:remote_theme][:commits_behind]).to eq(3)
expect(json[:remote_theme][:authors]).to eq("CDCK Inc.")
end
it "includes parent themes objects" do
expect(json[:parent_themes].map { |o| o[:name] }).to contain_exactly(theme_1.name, theme_2.name)
end
it "includes the component name" do
expect(json[:name]).to eq(component.name)
end
it "includes the component id" do
expect(json[:id]).to eq(component.id)
end
it "includes the component description" do
expect(json[:description]).to eq("Description of my component")
end
end