2022-03-31 08:58:38 +08:00
|
|
|
|
import {
|
|
|
|
|
acceptance,
|
|
|
|
|
query,
|
|
|
|
|
queryAll,
|
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
2021-06-09 22:58:55 +08:00
|
|
|
|
import { test } from "qunit";
|
2021-11-13 22:31:42 +08:00
|
|
|
|
import { click, fillIn, visit } from "@ember/test-helpers";
|
2022-03-31 08:58:38 +08:00
|
|
|
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
2018-11-23 00:19:24 +08:00
|
|
|
|
|
2020-10-21 01:56:52 +08:00
|
|
|
|
acceptance("Local Dates - composer", function (needs) {
|
|
|
|
|
needs.user();
|
|
|
|
|
needs.settings({ discourse_local_dates_enabled: true });
|
2018-11-23 00:19:24 +08:00
|
|
|
|
|
2020-10-31 00:37:32 +08:00
|
|
|
|
test("composer bbcode", async function (assert) {
|
2020-10-21 01:56:52 +08:00
|
|
|
|
const getAttr = (attr) => {
|
2020-10-29 04:36:01 +08:00
|
|
|
|
return queryAll(
|
|
|
|
|
".d-editor-preview .discourse-local-date.cooked-date"
|
|
|
|
|
).attr(`data-${attr}`);
|
2020-10-21 01:56:52 +08:00
|
|
|
|
};
|
2018-11-23 00:19:24 +08:00
|
|
|
|
|
2020-10-21 01:56:52 +08:00
|
|
|
|
await visit("/");
|
|
|
|
|
await click("#create-topic");
|
2018-11-23 00:19:24 +08:00
|
|
|
|
|
2020-10-21 01:56:52 +08:00
|
|
|
|
await fillIn(
|
|
|
|
|
".d-editor-input",
|
2020-12-08 07:57:18 +08:00
|
|
|
|
'[date=2017-10-23 time=01:30:00 displayedTimezone="America/Chicago" format="LLLL" calendar="off" recurring="1.weeks" timezone=" Asia/Calcutta" timezones="Europe/Paris|America/Los_Angeles"]'
|
2020-10-21 01:56:52 +08:00
|
|
|
|
);
|
2018-11-23 00:19:24 +08:00
|
|
|
|
|
2021-11-08 17:26:28 +08:00
|
|
|
|
assert.strictEqual(
|
|
|
|
|
getAttr("date"),
|
|
|
|
|
"2017-10-23",
|
|
|
|
|
"it has the correct date"
|
|
|
|
|
);
|
|
|
|
|
assert.strictEqual(getAttr("time"), "01:30:00", "it has the correct time");
|
|
|
|
|
assert.strictEqual(
|
2020-10-21 01:56:52 +08:00
|
|
|
|
getAttr("displayed-timezone"),
|
|
|
|
|
"America/Chicago",
|
|
|
|
|
"it has the correct displayed timezone"
|
|
|
|
|
);
|
2021-11-08 17:26:28 +08:00
|
|
|
|
assert.strictEqual(getAttr("format"), "LLLL", "it has the correct format");
|
|
|
|
|
assert.strictEqual(
|
2020-10-21 01:56:52 +08:00
|
|
|
|
getAttr("timezones"),
|
|
|
|
|
"Europe/Paris|America/Los_Angeles",
|
|
|
|
|
"it has the correct timezones"
|
|
|
|
|
);
|
2021-11-08 17:26:28 +08:00
|
|
|
|
assert.strictEqual(
|
2020-10-21 01:56:52 +08:00
|
|
|
|
getAttr("recurring"),
|
|
|
|
|
"1.weeks",
|
|
|
|
|
"it has the correct recurring"
|
|
|
|
|
);
|
2021-11-08 17:26:28 +08:00
|
|
|
|
assert.strictEqual(
|
2020-10-21 01:56:52 +08:00
|
|
|
|
getAttr("timezone"),
|
|
|
|
|
"Asia/Calcutta",
|
|
|
|
|
"it has the correct timezone"
|
|
|
|
|
);
|
2018-11-23 00:19:24 +08:00
|
|
|
|
|
2020-10-21 01:56:52 +08:00
|
|
|
|
await fillIn(
|
|
|
|
|
".d-editor-input",
|
|
|
|
|
'[date=2017-10-24 format="LL" timezone="Asia/Calcutta" timezones="Europe/Paris|America/Los_Angeles"]'
|
|
|
|
|
);
|
2018-11-23 00:19:24 +08:00
|
|
|
|
|
2021-11-08 17:26:28 +08:00
|
|
|
|
assert.strictEqual(
|
|
|
|
|
getAttr("date"),
|
|
|
|
|
"2017-10-24",
|
|
|
|
|
"it has the correct date"
|
|
|
|
|
);
|
2020-10-21 01:56:52 +08:00
|
|
|
|
assert.notOk(getAttr("time"), "it doesn’t have time");
|
|
|
|
|
});
|
2022-03-31 08:58:38 +08:00
|
|
|
|
|
|
|
|
|
test("date modal", async function (assert) {
|
|
|
|
|
await visit("/");
|
|
|
|
|
await click("#create-topic");
|
|
|
|
|
await click(".d-editor-button-bar .local-dates");
|
|
|
|
|
|
|
|
|
|
const timezoneChooser = selectKit(".timezone-input");
|
|
|
|
|
await timezoneChooser.expand();
|
|
|
|
|
await timezoneChooser.selectRowByValue("Asia/Macau");
|
|
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
|
query(".preview .discourse-local-date").textContent.includes("Macau"),
|
|
|
|
|
"it outputs a preview date in selected timezone"
|
|
|
|
|
);
|
|
|
|
|
});
|
2018-11-23 00:19:24 +08:00
|
|
|
|
});
|