mirror of
https://github.com/discourse/discourse.git
synced 2026-08-14 13:58:53 +08:00
The new formatting for recurrence in the configuration modal wasn't synced up with the rendered event in the post — this adds a new helper so they share the same source logic. Added tests to avoid future regression. Also fixed some minor CSS in the modal. Before: <img width="1398" height="660" alt="image" src="https://github.com/user-attachments/assets/7cd36ac1-8106-404a-92ed-e35f64a44342" /> After: <img width="1496" height="712" alt="image" src="https://github.com/user-attachments/assets/2c068a45-d5b0-4fc7-8ba1-980e9720c156" />
92 lines
3 KiB
Text
Vendored
92 lines
3 KiB
Text
Vendored
import { getOwner } from "@ember/owner";
|
|
import { render, waitFor } from "@ember/test-helpers";
|
|
import { module, test } from "qunit";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
import DiscoursePostEvent from "../../discourse/components/discourse-post-event";
|
|
import DiscoursePostEventEvent from "../../discourse/models/discourse-post-event-event";
|
|
|
|
function buildEvent(overrides = {}) {
|
|
return DiscoursePostEventEvent.create({
|
|
id: 1,
|
|
// 2026-06-04 is a Thursday
|
|
starts_at: "2026-06-04T14:00:00Z",
|
|
ends_at: "2026-06-04T15:00:00Z",
|
|
timezone: "UTC",
|
|
status: "public",
|
|
name: "Product team office hours",
|
|
post: { id: 1, url: "/t/foo/1", topic: { id: 1 } },
|
|
creator: { username: "bob", id: 5 },
|
|
should_display_invitees: false,
|
|
sample_invitees: [],
|
|
...overrides,
|
|
});
|
|
}
|
|
|
|
module("Integration | Component | DiscoursePostEvent", function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
function stubApi(event) {
|
|
getOwner(this).unregister("service:discourse-post-event-api");
|
|
getOwner(this).register(
|
|
"service:discourse-post-event-api",
|
|
{
|
|
async event() {
|
|
return event;
|
|
},
|
|
},
|
|
{ instantiate: false }
|
|
);
|
|
}
|
|
|
|
test("interpolates the weekday into the recurrence label", async function (assert) {
|
|
stubApi.call(this, buildEvent({ recurrence: "every_week" }));
|
|
|
|
const event = { id: 1, startsAt: "2026-06-04T14:00:00Z" };
|
|
await render(<template><DiscoursePostEvent @event={{event}} /></template>);
|
|
await waitFor(".event-recurrence");
|
|
|
|
assert
|
|
.dom(".event-recurrence")
|
|
.hasText(
|
|
"Every Thursday",
|
|
"renders the weekday instead of a missing placeholder"
|
|
);
|
|
});
|
|
|
|
test("interpolates the ordinal and weekday into the monthly recurrence label", async function (assert) {
|
|
stubApi.call(this, buildEvent({ recurrence: "every_month" }));
|
|
|
|
const event = { id: 1, startsAt: "2026-06-04T14:00:00Z" };
|
|
await render(<template><DiscoursePostEvent @event={{event}} /></template>);
|
|
await waitFor(".event-recurrence");
|
|
|
|
assert
|
|
.dom(".event-recurrence")
|
|
.hasText(
|
|
"The first Thursday of every month",
|
|
"renders both the ordinal and weekday placeholders"
|
|
);
|
|
});
|
|
|
|
test("derives the weekday from the date for all-day events, ignoring the timezone offset", async function (assert) {
|
|
// Midnight UTC in a negative-offset timezone rolls back to the previous
|
|
// day; an all-day event's weekday must come from the date, not the offset.
|
|
stubApi.call(
|
|
this,
|
|
buildEvent({
|
|
recurrence: "every_week",
|
|
all_day: true,
|
|
timezone: "America/New_York",
|
|
starts_at: "2026-06-04T00:00:00Z",
|
|
})
|
|
);
|
|
|
|
const event = { id: 1, startsAt: "2026-06-04T00:00:00Z" };
|
|
await render(<template><DiscoursePostEvent @event={{event}} /></template>);
|
|
await waitFor(".event-recurrence");
|
|
|
|
assert
|
|
.dom(".event-recurrence")
|
|
.hasText("Every Thursday", "uses the date's weekday, not the prior day");
|
|
});
|
|
});
|