FIX: shows category calendar on hot/latest (#611)
* FIX: shows category calendar on hot/latest The previous URL parsing code was not resilient to these paths, we now use the router to recognize these paths and extract the params we need. * linting * Update category_calendar_spec.rb
This commit is contained in:
		
							parent
							
								
									8a6acef386
								
							
						
					
					
						commit
						499f29a2a0
					
				| 
						 | 
				
			
			@ -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`;
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
		Loading…
	
		Reference in New Issue