0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-09 18:01:48 +08:00
discourse/plugins/discourse-calendar/test/javascripts/acceptance/topic-calendar-events-test.js
Jarek Radosz 81ec46fe6a
DEV: Fixup the calendar test helper (#39487)
This was causing flakiness (depending on test order it could still have
the other element, which made it pass)

Added more assertions to have more info in case it fails again.
2026-04-23 12:48:14 +02:00

49 lines
1.8 KiB
JavaScript
Vendored

import { visit, waitFor } from "@ember/test-helpers";
import { test } from "qunit";
import { cloneJSON } from "discourse/lib/object";
import pretender, { response } from "discourse/tests/helpers/create-pretender";
import { acceptance, fakeTime } from "discourse/tests/helpers/qunit-helpers";
import eventTopicFixture from "../helpers/event-topic-fixture";
import getEventByText from "../helpers/get-event-by-text";
function fixtureWithFullDay(fullDay) {
const fixture = cloneJSON(eventTopicFixture);
fixture.post_stream.posts[0].cooked =
fixture.post_stream.posts[0].cooked.replace(
/data-calendar-full-day="(true|false)"/,
`data-calendar-full-day="${fullDay}"`
);
return response(fixture);
}
acceptance("Topic Calendar Events", function (needs) {
needs.hooks.beforeEach(function () {
this.clock = fakeTime("2023-09-10T00:00:00", "Europe/Lisbon", true);
});
needs.hooks.afterEach(function () {
this.clock.restore();
});
needs.settings({ calendar_enabled: true });
test("renders calendar events with fullDay='true'", async function (assert) {
pretender.get("/t/252.json", () => fixtureWithFullDay("true"));
await visit("/t/-/252");
await waitFor(".fc-daygrid-event-harness");
assert.dom(".fc-daygrid-day").exists("the calendar rendered");
assert.dom(getEventByText("Event 1")).exists();
assert.dom(getEventByText("Event 2")).exists();
});
test("renders calendar events with fullDay='false'", async function (assert) {
pretender.get("/t/252.json", () => fixtureWithFullDay("false"));
await visit("/t/-/252");
await waitFor(".fc-daygrid-event-harness");
assert.dom(".fc-daygrid-day").exists("the calendar rendered");
assert.dom(getEventByText("Event 1")).exists();
assert.dom(getEventByText("Event 2")).exists();
});
});