Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: shows category calendar on hot/latest #611

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion assets/javascripts/discourse/initializers/discourse-calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ function initializeDiscourseCalendar(api) {
const site = api.container.lookup("service:site");
const isMobileView = site && site.mobileView;

const router = api.container.lookup("service:router");

let selector = `.${outletName}-outlet`;
if (outletName === "before-topic-list-body") {
selector = `.topic-list:not(.shared-drafts) .${outletName}-outlet`;
Expand All @@ -59,7 +61,14 @@ function initializeDiscourseCalendar(api) {
categoryEventNode.innerHTML = "";
}

const browsedCategory = Category.findBySlugPathWithID(url.split("?")[0]);
const route = router.recognize(url);
if (!route?.params?.category_slug_path_with_id) {
return;
}

const browsedCategory = Category.findBySlugPathWithID(
route.params.category_slug_path_with_id
);
if (!browsedCategory) {
return;
}
Expand Down
29 changes: 29 additions & 0 deletions spec/system/category_calendar_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

describe "Category calendar", type: :system do
fab!(:admin)
fab!(:category)

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
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.fc")

find(".nav-item_hot").click

expect(category_page).to have_selector("#category-events-calendar.fc")

find(".nav-item_latest").click

expect(category_page).to have_selector("#category-events-calendar.fc")
end
end