mirror of
https://github.com/discourse/discourse.git
synced 2026-08-02 09:29:37 -05:00
FIX: disable category calendar when post event are disabled (#34897)
Disabling post event with category events set would cause an error when visiting the category, this commit ensures it's not the case and adds a test for it. Also added tests to ensure we correctly render category calendar in different outlets as the before-topic-list-body one was broken.
This commit is contained in:
+4
@@ -39,6 +39,10 @@ export default class CategoryCalendar extends Component {
|
||||
}
|
||||
|
||||
get shouldRender() {
|
||||
if (!this.siteSettings.discourse_post_event_enabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.siteSettings.login_required && !this.currentUser) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+6
-2
@@ -1,6 +1,7 @@
|
||||
import Component from "@glimmer/component";
|
||||
import CategoryCalendar from "../../components/category-calendar";
|
||||
|
||||
export default class CategoryCalendar extends Component {
|
||||
export default class CategoryEventsCalendar extends Component {
|
||||
static shouldRender(_, ctx) {
|
||||
return (
|
||||
ctx.siteSettings.calendar_categories_outlet === "before-topic-list-body"
|
||||
@@ -8,6 +9,9 @@ export default class CategoryCalendar extends Component {
|
||||
}
|
||||
|
||||
<template>
|
||||
<div class="before-topic-list-body-outlet category-calendar"></div>
|
||||
<div
|
||||
id="category-events-calendar"
|
||||
class="--before-topic-list-body"
|
||||
><CategoryCalendar /></div>
|
||||
</template>
|
||||
}
|
||||
|
||||
+4
-1
@@ -10,6 +10,9 @@ export default class CategoryEventsCalendar extends Component {
|
||||
}
|
||||
|
||||
<template>
|
||||
<div id="category-events-calendar"><CategoryCalendar /></div>
|
||||
<div
|
||||
id="category-events-calendar"
|
||||
class="--discovery-list-container-top"
|
||||
><CategoryCalendar /></div>
|
||||
</template>
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ describe "Category calendar", type: :system do
|
||||
it "shows the calendar on the category page" do
|
||||
category_page.visit(category)
|
||||
|
||||
expect(category_page).to have_selector("#category-events-calendar .fc")
|
||||
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",
|
||||
@@ -40,4 +42,15 @@ describe "Category calendar", type: :system do
|
||||
expect(page).to have_current_path("#{category.relative_url}/l/latest")
|
||||
expect(category_page).to have_selector("#category-events-calendar .fc")
|
||||
end
|
||||
|
||||
context "when discourse_post_event_enabled is false" do
|
||||
before { SiteSetting.discourse_post_event_enabled = false }
|
||||
|
||||
it "does not crash the 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")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
+26
-6
@@ -85,7 +85,7 @@ acceptance(
|
||||
);
|
||||
|
||||
acceptance(
|
||||
"Discourse Calendar - Category Events Calendar Outlet Container Before Topic List",
|
||||
"Discourse Calendar - Category Events Calendar Outlet Container before-topic-list-body",
|
||||
function (needs) {
|
||||
needs.user();
|
||||
needs.settings({
|
||||
@@ -101,11 +101,31 @@ acceptance(
|
||||
test("display the specific calendar for before-topic-list-body outlet", async function (assert) {
|
||||
await visit("/c/bug/1");
|
||||
|
||||
assert
|
||||
.dom("#category-events-calendar")
|
||||
.doesNotExist("Category Events calendar div does not exist");
|
||||
|
||||
assert.dom(".category-calendar").exists("Category calendar div exists");
|
||||
assert.dom("#category-events-calendar.--before-topic-list-body").exists();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
acceptance(
|
||||
"Discourse Calendar - Category Events Calendar Outlet Container discovery-list-container-top",
|
||||
function (needs) {
|
||||
needs.user();
|
||||
needs.settings({
|
||||
calendar_enabled: true,
|
||||
discourse_post_event_enabled: true,
|
||||
events_calendar_categories: "1",
|
||||
calendar_categories: "",
|
||||
calendar_categories_outlet: "discovery-list-container-top",
|
||||
});
|
||||
|
||||
needs.pretender(eventsPretender);
|
||||
|
||||
test("display the specific calendar for discovery-list-container-top outlet", async function (assert) {
|
||||
await visit("/c/bug/1");
|
||||
|
||||
assert
|
||||
.dom("#category-events-calendar.--discovery-list-container-top")
|
||||
.exists();
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user