DEV: add more tests for future-date-input-selector (#13836)

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.

diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-silence-user-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-silence-user-test.js
new file mode 100644
index 0000000..3c87d0a
--- /dev/null
+++ b/app/assets/javascripts/discourse/tests/acceptance/admin-silence-user-test.js
@@ -0,0 +1,58 @@
+import {
+  acceptance,
+  fakeTime,
+  query,
+  queryAll,
+} from "discourse/tests/helpers/qunit-helpers";
+import { click, visit } from "@ember/test-helpers";
+import { test } from "qunit";
+import I18n from "I18n";
+
+acceptance("Admin - Silence User", function (needs) {
+  let clock = null;
+  needs.user();
+
+  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) {
+    await visit("/admin/users/1234/regular");
+    await click(".silence-user");
+    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.one_year"),
+      I18n.t("topic.auto_update_input.forever"),
+      I18n.t("topic.auto_update_input.pick_date_and_time"),
+    ];
+
+    assert.deepEqual(options, expected, "options are correct");
+  });
+});
diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-suspend-user-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-suspend-user-test.js
index f9821d9..771118f 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/admin-suspend-user-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/admin-suspend-user-test.js
@@ -2,11 +2,14 @@ import {
   acceptance,
   count,
   exists,
+  fakeTime,
   query,
+  queryAll,
 } from "discourse/tests/helpers/qunit-helpers";
 import { click, fillIn, visit } from "@ember/test-helpers";
 import selectKit from "discourse/tests/helpers/select-kit-helper";
 import { test } from "qunit";
+import I18n from "I18n";
 
 acceptance("Admin - Suspend User", function (needs) {
   needs.user();
@@ -98,3 +101,52 @@ acceptance("Admin - Suspend User", function (needs) {
     assert.ok(!exists(".suspension-info"));
   });
 });
+
+acceptance("Admin - Suspend User - timeframe choosing", function (needs) {
+  let clock = null;
+  needs.user();
+
+  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) {
+    await visit("/admin/users/1234/regular");
+    await click(".suspend-user");
+    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.one_year"),
+      I18n.t("topic.auto_update_input.forever"),
+      I18n.t("topic.auto_update_input.pick_date_and_time"),
+    ];
+
+    assert.deepEqual(options, expected, "options are correct");
+  });
+});
diff --git a/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js b/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js
index 7702921..55105ba 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/create-invite-modal-test.js
@@ -3,8 +3,12 @@ import {
   acceptance,
   count,
   exists,
+  fakeTime,
+  query,
+  queryAll,
 } from "discourse/tests/helpers/qunit-helpers";
 import { test } from "qunit";
+import I18n from "I18n";
 
 acceptance("Invites - Create & Edit Invite Modal", function (needs) {
   let deleted;
@@ -185,3 +189,76 @@ acceptance("Invites - Email Invites", function (needs) {
     );
   });
 });
+
+acceptance(
+  "Invites - Create & Edit Invite Modal - timeframe choosing",
+  function (needs) {
+    let clock = null;
+
+    needs.user();
+    needs.pretender((server, helper) => {
+      const inviteData = {
+        id: 1,
+        invite_key: "52641ae8878790bc7b79916247cfe6ba",
+        link: "http://example.com/invites/52641ae8878790bc7b79916247cfe6ba",
+        max_redemptions_allowed: 1,
+        redemption_count: 0,
+        created_at: "2021-01-26T12:00:00.000Z",
+        updated_at: "2021-01-26T12:00:00.000Z",
+        expires_at: "2121-01-26T12:00:00.000Z",
+        expired: false,
+        topics: [],
+        groups: [],
+      };
+
+      server.post("/invites", () => helper.response(inviteData));
+      server.put("/invites/1", () => helper.response(inviteData));
+    });
+
+    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) {
+      await visit("/u/eviltrout/invited/pending");
+
+      await click(".invite-controls .btn:first-child");
+      await click(".modal-footer .show-advanced");
+      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");
+    });
+  }
+);
diff --git a/app/assets/javascripts/discourse/tests/acceptance/topic-set-slow-mode-test.js b/app/assets/javascripts/discourse/tests/acceptance/topic-set-slow-mode-test.js
new file mode 100644

[... diff too long, it was truncated ...]

GitHub sha: bd4b87245ee4c03ab3dc449d671e8cffb0a98570

This commit appears in #13836 which was approved by eviltrout. It was merged by AndrewPrigorshnev.