This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/acceptance/topic-set-slow-mode-test.js
Andrei Prigorshnev bd4b87245e
DEV: add more tests for future-date-input-selector (#13836)
This PR contains only tests. These tests are from my old PR with refactoring of future-date-input-selector. That PR was closed because we had some changes in our planes about our time-pickers and additionally these tests were flaky.

Tests in this PR aren't flaky, since they use fake time moments in the future. Tests just document current behaviour of future-date-input-selector.
2021-07-23 22:44:23 +04:00

76 lines
2.1 KiB
JavaScript

import {
acceptance,
fakeTime,
query,
queryAll,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import I18n from "I18n";
acceptance("Topic - Set Slow Mode", function (needs) {
let clock = null;
needs.user();
needs.pretender((server, helper) => {
server.post("/t/280/timer", () =>
helper.response({
success: "OK",
execute_at: new Date(
new Date().getTime() + 1 * 60 * 60 * 1000
).toISOString(),
duration_minutes: 1440,
based_on_last_post: false,
closed: false,
category_id: null,
})
);
});
needs.hooks.beforeEach(() => {
const timezone = moment.tz.guess();
clock = fakeTime("2100-05-03T08:00:00", timezone, true); // Monday morning
});
needs.hooks.afterEach(() => {
clock.restore();
});
test("shows correct timeframe options", async function (assert) {
updateCurrentUser({ moderator: true });
await visit("/t/internationalization-localization");
await click(".toggle-admin-menu");
await click(".topic-admin-slow-mode button");
await click(".future-date-input-selector-header");
assert.equal(
query(".future-date-input-selector-header").getAttribute("aria-expanded"),
"true",
"selector is expanded"
);
const options = Array.from(
queryAll(`ul.select-kit-collection li span.name`).map((_, x) =>
x.innerText.trim()
)
);
const expected = [
I18n.t("topic.auto_update_input.later_today"),
I18n.t("topic.auto_update_input.tomorrow"),
I18n.t("topic.auto_update_input.next_week"),
I18n.t("topic.auto_update_input.two_weeks"),
I18n.t("topic.auto_update_input.next_month"),
I18n.t("topic.auto_update_input.two_months"),
I18n.t("topic.auto_update_input.three_months"),
I18n.t("topic.auto_update_input.four_months"),
I18n.t("topic.auto_update_input.six_months"),
I18n.t("topic.auto_update_input.pick_date_and_time"),
];
assert.deepEqual(options, expected, "options are correct");
});
});