2022-08-02 09:58:38 -04:00
|
|
|
|
import {
|
|
|
|
|
acceptance,
|
|
|
|
|
query,
|
|
|
|
|
queryAll,
|
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
2021-06-09 10:58:55 -04:00
|
|
|
|
import { test } from "qunit";
|
2021-11-13 09:31:42 -05:00
|
|
|
|
import { click, fillIn, visit } from "@ember/test-helpers";
|
2022-03-30 20:58:38 -04:00
|
|
|
|
import selectKit from "discourse/tests/helpers/select-kit-helper";
|
2018-11-22 11:19:24 -05:00
|
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
|
acceptance("Local Dates - composer", function (needs) {
|
|
|
|
|
needs.user();
|
2022-10-11 06:25:32 -04:00
|
|
|
|
needs.settings({
|
|
|
|
|
discourse_local_dates_enabled: true,
|
|
|
|
|
discourse_local_dates_default_formats: "LLL|LTS|LL|LLLL",
|
|
|
|
|
});
|
2018-11-22 11:19:24 -05:00
|
|
|
|
|
2020-10-30 12:37:32 -04:00
|
|
|
|
test("composer bbcode", async function (assert) {
|
2020-10-20 13:56:52 -04:00
|
|
|
|
const getAttr = (attr) => {
|
2022-07-13 13:29:19 -04:00
|
|
|
|
return query(
|
2020-10-28 16:36:01 -04:00
|
|
|
|
".d-editor-preview .discourse-local-date.cooked-date"
|
2022-07-13 13:29:19 -04:00
|
|
|
|
).getAttribute(`data-${attr}`);
|
2020-10-20 13:56:52 -04:00
|
|
|
|
};
|
2018-11-22 11:19:24 -05:00
|
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
|
await visit("/");
|
|
|
|
|
await click("#create-topic");
|
2022-11-07 18:17:43 -05:00
|
|
|
|
const categoryChooser = selectKit(".category-chooser");
|
|
|
|
|
await categoryChooser.expand();
|
|
|
|
|
await categoryChooser.selectRowByValue(2);
|
2018-11-22 11:19:24 -05:00
|
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
|
await fillIn(
|
|
|
|
|
".d-editor-input",
|
2020-12-07 18:57:18 -05: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-20 13:56:52 -04:00
|
|
|
|
);
|
2018-11-22 11:19:24 -05:00
|
|
|
|
|
2021-11-08 04:26:28 -05: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-20 13:56:52 -04:00
|
|
|
|
getAttr("displayed-timezone"),
|
|
|
|
|
"America/Chicago",
|
|
|
|
|
"it has the correct displayed timezone"
|
|
|
|
|
);
|
2021-11-08 04:26:28 -05:00
|
|
|
|
assert.strictEqual(getAttr("format"), "LLLL", "it has the correct format");
|
|
|
|
|
assert.strictEqual(
|
2020-10-20 13:56:52 -04:00
|
|
|
|
getAttr("timezones"),
|
|
|
|
|
"Europe/Paris|America/Los_Angeles",
|
|
|
|
|
"it has the correct timezones"
|
|
|
|
|
);
|
2021-11-08 04:26:28 -05:00
|
|
|
|
assert.strictEqual(
|
2020-10-20 13:56:52 -04:00
|
|
|
|
getAttr("recurring"),
|
|
|
|
|
"1.weeks",
|
|
|
|
|
"it has the correct recurring"
|
|
|
|
|
);
|
2021-11-08 04:26:28 -05:00
|
|
|
|
assert.strictEqual(
|
2020-10-20 13:56:52 -04:00
|
|
|
|
getAttr("timezone"),
|
|
|
|
|
"Asia/Calcutta",
|
|
|
|
|
"it has the correct timezone"
|
|
|
|
|
);
|
2018-11-22 11:19:24 -05:00
|
|
|
|
|
2020-10-20 13:56:52 -04:00
|
|
|
|
await fillIn(
|
|
|
|
|
".d-editor-input",
|
|
|
|
|
'[date=2017-10-24 format="LL" timezone="Asia/Calcutta" timezones="Europe/Paris|America/Los_Angeles"]'
|
|
|
|
|
);
|
2018-11-22 11:19:24 -05:00
|
|
|
|
|
2021-11-08 04:26:28 -05:00
|
|
|
|
assert.strictEqual(
|
|
|
|
|
getAttr("date"),
|
|
|
|
|
"2017-10-24",
|
|
|
|
|
"it has the correct date"
|
|
|
|
|
);
|
2020-10-20 13:56:52 -04:00
|
|
|
|
assert.notOk(getAttr("time"), "it doesn’t have time");
|
|
|
|
|
});
|
2022-03-30 20:58:38 -04:00
|
|
|
|
|
|
|
|
|
test("date modal", async function (assert) {
|
|
|
|
|
await visit("/");
|
|
|
|
|
await click("#create-topic");
|
2022-11-07 18:17:43 -05:00
|
|
|
|
const categoryChooser = selectKit(".category-chooser");
|
|
|
|
|
await categoryChooser.expand();
|
|
|
|
|
await categoryChooser.selectRowByValue(2);
|
2022-03-30 20:58:38 -04:00
|
|
|
|
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"
|
|
|
|
|
);
|
|
|
|
|
});
|
2022-08-02 09:58:38 -04:00
|
|
|
|
|
|
|
|
|
test("date modal - controls", async function (assert) {
|
|
|
|
|
await visit("/");
|
|
|
|
|
await click("#create-topic");
|
2022-11-07 18:17:43 -05:00
|
|
|
|
const categoryChooser = selectKit(".category-chooser");
|
|
|
|
|
await categoryChooser.expand();
|
|
|
|
|
await categoryChooser.selectRowByValue(2);
|
2022-08-02 09:58:38 -04:00
|
|
|
|
await click(".d-editor-button-bar .local-dates");
|
|
|
|
|
|
|
|
|
|
await click('.pika-table td[data-day="5"] > .pika-button');
|
|
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
|
query("#from-date-time").textContent.includes("5,"),
|
|
|
|
|
"selected FROM date works"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await click(".date-time-control.to .date-time");
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
|
queryAll(".pika-table .is-disabled").length,
|
|
|
|
|
4,
|
|
|
|
|
"date just before selected FROM date is disabled"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await click('.pika-table td[data-day="10"] > .pika-button');
|
|
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
|
query(".date-time-control.to button").textContent.includes("10,"),
|
|
|
|
|
"selected TO date works"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
|
query(".pika-table .is-selected").textContent,
|
|
|
|
|
"10",
|
|
|
|
|
"selected date is the 10th"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await click(".delete-to-date");
|
|
|
|
|
|
|
|
|
|
assert.notOk(
|
|
|
|
|
query(".pika-table .is-selected"),
|
|
|
|
|
"deleting selected TO date works"
|
|
|
|
|
);
|
2022-10-11 06:25:32 -04:00
|
|
|
|
|
|
|
|
|
await click(".advanced-mode-btn");
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(query("input.format-input").value, "");
|
|
|
|
|
await click("ul.formats a.moment-format");
|
|
|
|
|
assert.strictEqual(query("input.format-input").value, "LLL");
|
2022-08-02 09:58:38 -04:00
|
|
|
|
});
|
2018-11-22 11:19:24 -05:00
|
|
|
|
});
|