mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 13:08:40 +08:00
Previously, embedded upcoming events calendars always fetched all
visible events and created events without a category.
This change lets callers pass a category scope to
`UpcomingEventsCalendar`, uses it for event fetching and composer
defaults, and lets embedded callers opt out of the calendar's existing
route/date syncing via `@updateRouteOnDatesChange={{false}}`. The
default preserves the existing `/upcoming-events` behavior for backwards
compatibility.
78 lines
2 KiB
Text
Vendored
78 lines
2 KiB
Text
Vendored
import { render, waitFor } from "@ember/test-helpers";
|
|
import { module, test } from "qunit";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
|
import UpcomingEventsCalendar from "../../discourse/components/upcoming-events-calendar";
|
|
|
|
module("Integration | Component | UpcomingEventsCalendar", function (hooks) {
|
|
setupRenderingTest(hooks, { stubRouter: true });
|
|
|
|
test("renders events from the requested category", async function (assert) {
|
|
const requests = [];
|
|
|
|
pretender.get("/discourse-post-event/events", ({ queryParams }) => {
|
|
requests.push(queryParams);
|
|
|
|
if (queryParams.category_id === "2") {
|
|
return response({ events: [eventForCategory(2, "Beauty event")] });
|
|
}
|
|
|
|
return response({ events: [] });
|
|
});
|
|
|
|
await render(
|
|
<template>
|
|
<UpcomingEventsCalendar
|
|
@categoryId={{2}}
|
|
@includeSubcategories={{true}}
|
|
@initialDate="2026-07-01"
|
|
@initialView="dayGridMonth"
|
|
@updateRouteOnDatesChange={{false}}
|
|
/>
|
|
</template>
|
|
);
|
|
|
|
await waitFor(".fc-event-title");
|
|
|
|
assert
|
|
.dom(".fc-event-title")
|
|
.hasText(
|
|
"Beauty event",
|
|
"renders the event returned for the selected category"
|
|
);
|
|
|
|
assert.strictEqual(
|
|
requests[0].category_id,
|
|
"2",
|
|
"category id is passed through to the event API"
|
|
);
|
|
assert.strictEqual(
|
|
requests[0].include_subcategories,
|
|
"true",
|
|
"include subcategories is passed through to the event API"
|
|
);
|
|
});
|
|
});
|
|
|
|
function eventForCategory(categoryId, name) {
|
|
return {
|
|
id: categoryId,
|
|
name,
|
|
category_id: categoryId,
|
|
timezone: "UTC",
|
|
post: {
|
|
id: categoryId,
|
|
post_number: 1,
|
|
topic: {
|
|
id: categoryId,
|
|
title: name,
|
|
},
|
|
},
|
|
occurrences: [
|
|
{
|
|
starts_at: "2026-07-10T10:00:00.000Z",
|
|
ends_at: "2026-07-10T11:00:00.000Z",
|
|
},
|
|
],
|
|
};
|
|
}
|