Skip to content

A platform for community discussion. Free, open, simple.

DEV: Add system tests for category calendar color mapping (#37094)

Alan Guo Xiang Tan5dbd4a2f8069
diff --git a/plugins/discourse-calendar/spec/system/category_calendar_spec.rb b/plugins/discourse-calendar/spec/system/category_calendar_spec.rb
index 76ca2ebe272..45c2dd5da59 100644
--- a/plugins/discourse-calendar/spec/system/category_calendar_spec.rb
+++ b/plugins/discourse-calendar/spec/system/category_calendar_spec.rb
@@ -2,6 +2,7 @@
describe "Category calendar", type: :system do
fab!(:admin)
+ fab!(:user)
fab!(:category)
let(:category_page) { PageObjects::Pages::Category.new }
@@ -95,4 +96,64 @@ describe "Category calendar", type: :system do
expect(category_page).to have_selector("#category-events-calendar .fc")
end
end
+
+ context "with color mapping" do
+ before do
+ SiteSetting.calendar_enabled = true
+ SiteSetting.discourse_post_event_enabled = true
+ sign_in(user)
+ end
+
+ context "with tag color" do
+ fab!(:tag) { Fabricate(:tag, name: "awesome-tag") }
+
+ before do
+ SiteSetting.events_calendar_categories = category.id.to_s
+ SiteSetting.map_events_to_color = [
+ { type: "tag", color: "rgb(231, 76, 60)", slug: "awesome-tag" },
+ ].to_json
+ end
+
+ it "displays the event with the correct color" do
+ create_post(
+ user: admin,
+ topic: Fabricate(:topic, category: category, tags: [tag]),
+ raw: "[event start=\"#{Time.now.iso8601}\"]\n[/event]",
+ )
+
+ category_page.visit(category)
+
+ expect(category_page).to have_css(".fc-daygrid-event-harness")
+ expect(get_rgb_color(find(".fc-daygrid-event-dot"), "borderColor")).to eq(
+ "rgb(231, 76, 60)",
+ )
+ end
+ end
+
+ context "with category color" do
+ fab!(:category_for_color) { Fabricate(:category, slug: "colored-category") }
+
+ before do
+ SiteSetting.events_calendar_categories = category_for_color.id.to_s
+ SiteSetting.map_events_to_color = [
+ { type: "category", color: "rgb(46, 204, 113)", slug: "colored-category" },
+ ].to_json
+ end
+
+ it "displays the event with the correct color" do
+ create_post(
+ user: admin,
+ category: category_for_color,
+ raw: "[event start=\"#{Time.now.iso8601}\"]\n[/event]",
+ )
+
+ category_page.visit(category_for_color)
+
+ expect(category_page).to have_css(".fc-daygrid-event-harness")
+ expect(get_rgb_color(find(".fc-daygrid-event-dot"), "borderColor")).to eq(
+ "rgb(46, 204, 113)",
+ )
+ end
+ end
+ end
end