import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import topicFixtures from "discourse/tests/fixtures/topic";
import {
acceptance,
query,
selectText,
} from "discourse/tests/helpers/qunit-helpers";
import { cloneJSON } from "discourse-common/lib/object";
acceptance("Local Dates - quoting", function (needs) {
needs.user();
needs.settings({ discourse_local_dates_enabled: true });
needs.pretender((server, helper) => {
const topicResponse = cloneJSON(topicFixtures["/t/280/1.json"]);
const firstPost = topicResponse.post_stream.posts[0];
firstPost.cooked += `
This is a test
June 17, 2022 8:00 AM (Perth)
`;
server.get("/t/280.json", () => helper.response(topicResponse));
server.get("/t/280/:post_number.json", () => {
helper.response(topicResponse);
});
});
test("quoting single local dates with basic options", async function (assert) {
await visit("/t/internationalization-localization/280");
await selectText("#post_1 .select-local-date-test");
await click(".insert-quote");
assert.strictEqual(
query(".d-editor-input").value.trim(),
`[quote=\"uwe_keim, post:1, topic:280\"]
This is a test [date=2022-06-17 time=10:00:00 timezone="Australia/Brisbane" displayedTimezone="Australia/Perth"]
[/quote]`,
"converts the date to markdown with all options correctly"
);
});
});
acceptance("Local Dates - quoting range", function (needs) {
needs.user();
needs.settings({ discourse_local_dates_enabled: true });
needs.pretender((server, helper) => {
const topicResponse = cloneJSON(topicFixtures["/t/280/1.json"]);
const firstPost = topicResponse.post_stream.posts[0];
firstPost.cooked += `Some text
June 17, 2022
→
June 18, 2022
`;
server.get("/t/280.json", () => helper.response(topicResponse));
server.get("/t/280/:post_number.json", () => {
helper.response(topicResponse);
});
});
test("quoting a range of local dates", async function (assert) {
await visit("/t/internationalization-localization/280");
await selectText("#post_1 .select-local-date-test");
await click(".insert-quote");
assert.strictEqual(
query(".d-editor-input").value.trim(),
`[quote=\"uwe_keim, post:1, topic:280\"]
Some text [date-range from=2022-06-17T09:30:00 to=2022-06-18T10:30:00 format="LL" timezone="Australia/Brisbane" timezones="Africa/Accra|Australia/Brisbane|Europe/Paris"]
[/quote]`,
"converts the date range to markdown with all options correctly"
);
});
});
acceptance(
"Local Dates - quoting with recurring and countdown",
function (needs) {
needs.user();
needs.settings({ discourse_local_dates_enabled: true });
needs.pretender((server, helper) => {
const topicResponse = cloneJSON(topicFixtures["/t/280/1.json"]);
const firstPost = topicResponse.post_stream.posts[0];
firstPost.cooked += `Testing countdown
21 hours
Testing recurring
Wednesday
`;
server.get("/t/280.json", () => helper.response(topicResponse));
server.get("/t/280/:post_number.json", () => {
helper.response(topicResponse);
});
});
test("quoting single local dates with recurring and countdown options", async function (assert) {
await visit("/t/internationalization-localization/280");
await selectText("#post_1 .select-local-date-test");
await click(".insert-quote");
assert.strictEqual(
query(".d-editor-input").value.trim(),
`[quote=\"uwe_keim, post:1, topic:280\"]
Testing countdown [date=2022-06-21 time=09:30:00 format="LL" timezone="Australia/Brisbane" countdown="true"]
Testing recurring [date=2022-06-22 timezone="Australia/Brisbane" recurring="2.weeks"]
[/quote]`,
"converts the dates to markdown with all options correctly"
);
});
}
);