Skip to content

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

FIX: ensures calendar_categories shows calendar (#36991)

Joffrey JAFFEUX199315f8a4ab
diff --git a/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs b/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs
index 662a39844ce..76777e47eb6 100644
--- a/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs
+++ b/plugins/discourse-calendar/assets/javascripts/discourse/components/category-calendar.gjs
@@ -21,7 +21,6 @@ export default class CategoryCalendar extends Component {
const params = {
after: info.startStr,
before: info.endStr,
- post_id: this.categorySetting?.postId,
category_id: this.category.id,
include_subcategories: true,
};
@@ -149,7 +148,7 @@ export default class CategoryCalendar extends Component {
<FullCalendar
@onLoadEvents={{this.loadEvents}}
@height="650px"
- @initialView={{this.categorySetting?.defaultView}}
+ @initialView={{this.categorySetting.defaultView}}
@weekends={{this.renderWeekends}}
@refreshKey={{this.category.id}}
/>
diff --git a/plugins/discourse-calendar/config/locales/server.en.yml b/plugins/discourse-calendar/config/locales/server.en.yml
index f4102c58682..c6361d650d9 100644
--- a/plugins/discourse-calendar/config/locales/server.en.yml
+++ b/plugins/discourse-calendar/config/locales/server.en.yml
@@ -45,7 +45,7 @@ en:
all_day_event_start_time: "Events that do not have a start time specified will start at this time. Format is HH:mm. For 6:00 am, enter 06:00"
all_day_event_end_time: "Events that do not have a end time specified will end at this time. Format is HH:mm. For 6:00 pm, enter 18:00"
all_day_event_time_error: "Invalid time. Format needs to be HH:mm (ex: 08:00)."
- calendar_categories: "Display a calendar at the top of a category. Mandatory settings are categoryId and postId. eg: categoryId=6;postId=453\n Other valid settings: tzPicker, weekends and defaultView."
+ calendar_categories: "Display a calendar at the top of a category. categoryId is mandatory. eg: categoryId=6;weekends=false;defaultView=year;\n Other valid settings: weekends(true/false) and defaultView(day,week,month,year)."
calendar_categories_outlet: "Allows to change which outlet should show the category calendar."
working_days: "Set working days. You can display the availability of a group using the `timezones` tag in a post, eg: `[timezones group=admins][timezones]`"
working_day_start_hour: "Start time of the working day hours."
diff --git a/plugins/discourse-calendar/spec/system/category_calendar_spec.rb b/plugins/discourse-calendar/spec/system/category_calendar_spec.rb
index eae5fb1a7cc..76ca2ebe272 100644
--- a/plugins/discourse-calendar/spec/system/category_calendar_spec.rb
+++ b/plugins/discourse-calendar/spec/system/category_calendar_spec.rb
@@ -6,51 +6,93 @@ describe "Category calendar", type: :system do
let(:category_page) { PageObjects::Pages::Category.new }
- before do
- SiteSetting.calendar_enabled = true
- SiteSetting.discourse_post_event_enabled = true
- SiteSetting.events_calendar_categories = category.id.to_s
-
- PostCreator.create!(
- admin,
- title: "Sell a boat party",
- category: category.id,
- raw: "[event start=\"#{Time.now.iso8601}\"]\n[/event]",
- )
-
- sign_in(admin)
- end
+ context "with events_calendar_categories" do
+ before do
+ SiteSetting.calendar_enabled = true
+ SiteSetting.discourse_post_event_enabled = true
+ SiteSetting.events_calendar_categories = category.id.to_s
+
+ PostCreator.create!(
+ admin,
+ title: "Sell a boat party",
+ category: category.id,
+ raw: "[event start=\"#{Time.now.iso8601}\"]\n[/event]",
+ )
- it "shows the calendar on the category page" do
- category_page.visit(category)
+ sign_in(admin)
+ end
+
+ it "shows the calendar on the category page" do
+ category_page.visit(category)
- expect(category_page).to have_selector(
- "#category-events-calendar.--discovery-list-container-top .fc",
- )
- expect(category_page).to have_css(
- ".fc-daygrid-event-harness .fc-event-title",
- text: "Sell a boat party",
- )
+ expect(category_page).to have_selector(
+ "#category-events-calendar.--discovery-list-container-top .fc",
+ )
+ expect(category_page).to have_css(
+ ".fc-daygrid-event-harness .fc-event-title",
+ text: "Sell a boat party",
+ )
- find(".nav-item_hot").click
+ find(".nav-item_hot").click
+
+ expect(page).to have_current_path("#{category.relative_url}/l/hot")
+ expect(category_page).to have_selector("#category-events-calendar .fc")
+
+ find(".nav-item_latest").click
+
+ expect(page).to have_current_path("#{category.relative_url}/l/latest")
+ expect(category_page).to have_selector("#category-events-calendar .fc")
+ end
- expect(page).to have_current_path("#{category.relative_url}/l/hot")
- expect(category_page).to have_selector("#category-events-calendar .fc")
+ context "when discourse_post_event_enabled is false" do
+ before { SiteSetting.discourse_post_event_enabled = false }
- find(".nav-item_latest").click
+ it "does not crash the page" do
+ category_page.visit(category)
- expect(page).to have_current_path("#{category.relative_url}/l/latest")
- expect(category_page).to have_selector("#category-events-calendar .fc")
+ expect(category_page).to have_no_selector("#category-events-calendar .fc")
+ expect(category_page).to have_content("Sell a boat party")
+ end
+ end
end
- context "when discourse_post_event_enabled is false" do
- before { SiteSetting.discourse_post_event_enabled = false }
+ context "with calendar_categories" do
+ before do
+ SiteSetting.calendar_enabled = true
+ SiteSetting.discourse_post_event_enabled = true
+ # postId should be irrelevant now, it's a legacy property
+ SiteSetting.calendar_categories = "categoryId=#{category.id};postId=2313"
+
+ PostCreator.create!(
+ admin,
+ title: "Sell a boat party",
+ category: category.id,
+ raw: "[event start=\"#{Time.now.iso8601}\"]\n[/event]",
+ )
+
+ sign_in(admin)
+ end
- it "does not crash the page" do
+ it "shows the calendar on the category page" do
category_page.visit(category)
- expect(category_page).to have_no_selector("#category-events-calendar .fc")
- expect(category_page).to have_content("Sell a boat party")
+ expect(category_page).to have_selector(
+ "#category-events-calendar.--discovery-list-container-top .fc",
+ )
+ expect(category_page).to have_css(
+ ".fc-daygrid-event-harness .fc-event-title",
+ text: "Sell a boat party",
+ )
+
+ find(".nav-item_hot").click
+
+ expect(page).to have_current_path("#{category.relative_url}/l/hot")
+ expect(category_page).to have_selector("#category-events-calendar .fc")
+
+ find(".nav-item_latest").click
+
+ expect(page).to have_current_path("#{category.relative_url}/l/latest")
+ expect(category_page).to have_selector("#category-events-calendar .fc")
end
end
end