2023-10-11 02:38:59 +08:00
|
|
|
|
import { click, fillIn, visit } from "@ember/test-helpers";
|
|
|
|
|
import { test } from "qunit";
|
2024-11-28 18:22:27 +08:00
|
|
|
|
import { acceptance } from "discourse/tests/helpers/qunit-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();
|
2022-10-11 18:25:32 +08:00
|
|
|
|
needs.settings({
|
|
|
|
|
discourse_local_dates_enabled: true,
|
|
|
|
|
discourse_local_dates_default_formats: "LLL|LTS|LL|LLLL",
|
|
|
|
|
});
|
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
|
|
|
|
await visit("/");
|
|
|
|
|
await click("#create-topic");
|
2022-11-08 07:17:43 +08:00
|
|
|
|
const categoryChooser = selectKit(".category-chooser");
|
|
|
|
|
await categoryChooser.expand();
|
|
|
|
|
await categoryChooser.selectRowByValue(2);
|
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
|
|
|
|
|
2024-11-04 18:30:38 +08:00
|
|
|
|
assert
|
|
|
|
|
.dom(".d-editor-preview .discourse-local-date.cooked-date")
|
|
|
|
|
.hasAttribute("data-date", "2017-10-23", "has the correct date");
|
|
|
|
|
assert
|
|
|
|
|
.dom(".d-editor-preview .discourse-local-date.cooked-date")
|
|
|
|
|
.hasAttribute("data-time", "01:30:00", "has the correct time");
|
|
|
|
|
assert
|
|
|
|
|
.dom(".d-editor-preview .discourse-local-date.cooked-date")
|
|
|
|
|
.hasAttribute(
|
|
|
|
|
"data-displayed-timezone",
|
|
|
|
|
"America/Chicago",
|
|
|
|
|
"has the correct displayed timezone"
|
|
|
|
|
);
|
|
|
|
|
assert
|
|
|
|
|
.dom(".d-editor-preview .discourse-local-date.cooked-date")
|
|
|
|
|
.hasAttribute("data-format", "LLLL", "has the correct format");
|
|
|
|
|
assert
|
|
|
|
|
.dom(".d-editor-preview .discourse-local-date.cooked-date")
|
|
|
|
|
.hasAttribute(
|
|
|
|
|
"data-timezones",
|
|
|
|
|
"Europe/Paris|America/Los_Angeles",
|
|
|
|
|
"has the correct timezones"
|
|
|
|
|
);
|
|
|
|
|
assert
|
|
|
|
|
.dom(".d-editor-preview .discourse-local-date.cooked-date")
|
|
|
|
|
.hasAttribute("data-recurring", "1.weeks", "has the correct recurring");
|
|
|
|
|
assert
|
|
|
|
|
.dom(".d-editor-preview .discourse-local-date.cooked-date")
|
|
|
|
|
.hasAttribute(
|
|
|
|
|
"data-timezone",
|
|
|
|
|
"Asia/Calcutta",
|
|
|
|
|
"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
|
|
|
|
|
2024-11-04 18:30:38 +08:00
|
|
|
|
assert
|
|
|
|
|
.dom(".d-editor-preview .discourse-local-date.cooked-date")
|
|
|
|
|
.hasAttribute("data-date", "2017-10-24", "has the correct date");
|
|
|
|
|
assert
|
|
|
|
|
.dom(".d-editor-preview .discourse-local-date.cooked-date")
|
|
|
|
|
.doesNotHaveAttribute("data-time", "doesn’t have time");
|
2020-10-21 01:56:52 +08:00
|
|
|
|
});
|
2022-03-31 08:58:38 +08:00
|
|
|
|
|
|
|
|
|
test("date modal", async function (assert) {
|
|
|
|
|
await visit("/");
|
|
|
|
|
await click("#create-topic");
|
2022-11-08 07:17:43 +08:00
|
|
|
|
const categoryChooser = selectKit(".category-chooser");
|
|
|
|
|
await categoryChooser.expand();
|
|
|
|
|
await categoryChooser.selectRowByValue(2);
|
2022-03-31 08:58:38 +08:00
|
|
|
|
await click(".d-editor-button-bar .local-dates");
|
|
|
|
|
|
|
|
|
|
const timezoneChooser = selectKit(".timezone-input");
|
|
|
|
|
await timezoneChooser.expand();
|
|
|
|
|
await timezoneChooser.selectRowByValue("Asia/Macau");
|
|
|
|
|
|
2024-11-28 18:22:27 +08:00
|
|
|
|
assert
|
|
|
|
|
.dom(".preview .discourse-local-date")
|
|
|
|
|
.includesText("Macau", "outputs a preview date in selected timezone");
|
2022-03-31 08:58:38 +08:00
|
|
|
|
});
|
2022-08-02 21:58:38 +08:00
|
|
|
|
|
|
|
|
|
test("date modal - controls", async function (assert) {
|
|
|
|
|
await visit("/");
|
|
|
|
|
await click("#create-topic");
|
2022-11-08 07:17:43 +08:00
|
|
|
|
const categoryChooser = selectKit(".category-chooser");
|
|
|
|
|
await categoryChooser.expand();
|
|
|
|
|
await categoryChooser.selectRowByValue(2);
|
2022-08-02 21:58:38 +08:00
|
|
|
|
await click(".d-editor-button-bar .local-dates");
|
|
|
|
|
|
|
|
|
|
await click('.pika-table td[data-day="5"] > .pika-button');
|
|
|
|
|
|
2024-11-28 18:22:27 +08:00
|
|
|
|
assert
|
|
|
|
|
.dom("#from-date-time")
|
|
|
|
|
.includesText("5,", "selected FROM date works");
|
2022-08-02 21:58:38 +08:00
|
|
|
|
|
|
|
|
|
await click(".date-time-control.to .date-time");
|
|
|
|
|
|
2024-11-28 18:22:27 +08:00
|
|
|
|
assert
|
|
|
|
|
.dom(".pika-table .is-disabled")
|
|
|
|
|
.exists({ count: 4 }, "date just before selected FROM date is disabled");
|
2022-08-02 21:58:38 +08:00
|
|
|
|
|
|
|
|
|
await click('.pika-table td[data-day="10"] > .pika-button');
|
|
|
|
|
|
2024-11-28 18:22:27 +08:00
|
|
|
|
assert
|
|
|
|
|
.dom(".date-time-control.to button")
|
|
|
|
|
.includesText("10,", "selected TO date works");
|
2022-08-02 21:58:38 +08:00
|
|
|
|
|
2024-11-28 18:22:27 +08:00
|
|
|
|
assert
|
|
|
|
|
.dom(".pika-table .is-selected")
|
|
|
|
|
.hasText("10", "selected date is the 10th");
|
2022-08-02 21:58:38 +08:00
|
|
|
|
|
|
|
|
|
await click(".delete-to-date");
|
|
|
|
|
|
2024-11-28 18:22:27 +08:00
|
|
|
|
assert
|
|
|
|
|
.dom(".date-time-control.to.is-selected")
|
|
|
|
|
.doesNotExist("deleting selected TO date works");
|
2022-10-11 18:25:32 +08:00
|
|
|
|
|
|
|
|
|
await click(".advanced-mode-btn");
|
|
|
|
|
|
2024-10-15 23:11:20 +08:00
|
|
|
|
assert.dom("input.format-input").hasValue("");
|
2022-10-11 18:25:32 +08:00
|
|
|
|
await click("ul.formats a.moment-format");
|
2024-10-15 23:11:20 +08:00
|
|
|
|
assert.dom("input.format-input").hasValue("LLL");
|
2022-08-02 21:58:38 +08:00
|
|
|
|
});
|
2018-11-23 00:19:24 +08:00
|
|
|
|
});
|