Skip to content

A platform for community discussion. Free, open, simple.

DEV: Remove ember legacy env conditional in sidebar tests (#17140)

Alan Guo Xiang Tanef5b504e9ab9
diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-categories-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-categories-section-test.js
index d9d2b3281a7..9269776a2e2 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-categories-section-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-categories-section-test.js
@@ -1,17 +1,16 @@
import I18n from "I18n";
+import { test } from "qunit";
import { click, currentURL, settled, visit } from "@ember/test-helpers";
import {
acceptance,
- conditionalTest,
exists,
publishToMessageBus,
query,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
-import { isLegacyEmber } from "discourse-common/config/environment";
import Site from "discourse/models/site";
import { NotificationLevels } from "discourse/lib/notification-levels";
import discoveryFixture from "discourse/tests/fixtures/discovery-fixtures";
@@ -27,38 +26,34 @@ acceptance(
needs.user({ experimental_sidebar_enabled: true });
- conditionalTest(
- "uncategorized category is not shown",
- !isLegacyEmber(),
- async function (assert) {
- const categories = Site.current().categories;
- const category1 = categories[0];
+ test("uncategorized category is not shown", async function (assert) {
+ const categories = Site.current().categories;
+ const category1 = categories[0];
- const uncategorizedCategory = categories.find((category) => {
- return category.id === Site.current().uncategorized_category_id;
- });
+ const uncategorizedCategory = categories.find((category) => {
+ return category.id === Site.current().uncategorized_category_id;
+ });
- category1.set("notification_level", NotificationLevels.TRACKING);
+ category1.set("notification_level", NotificationLevels.TRACKING);
- uncategorizedCategory.set(
- "notification_level",
- NotificationLevels.TRACKING
- );
+ uncategorizedCategory.set(
+ "notification_level",
+ NotificationLevels.TRACKING
+ );
- await visit("/");
+ await visit("/");
- assert.strictEqual(
- queryAll(".sidebar-section-categories .sidebar-section-link").length,
- 1,
- "there should only be one section link under the section"
- );
+ assert.strictEqual(
+ queryAll(".sidebar-section-categories .sidebar-section-link").length,
+ 1,
+ "there should only be one section link under the section"
+ );
- assert.ok(
- exists(`.sidebar-section-link-${category1.slug}`),
- `only the ${category1.slug} section link is shown`
- );
- }
- );
+ assert.ok(
+ exists(`.sidebar-section-link-${category1.slug}`),
+ `only the ${category1.slug} section link is shown`
+ );
+ });
}
);
@@ -97,398 +92,358 @@ acceptance("Sidebar - Categories Section", function (needs) {
return { category1, category2 };
};
- conditionalTest(
- "clicking on section header link",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/t/280");
- await click(".sidebar-section-categories .sidebar-section-header-link");
+ test("clicking on section header link", async function (assert) {
+ await visit("/t/280");
+ await click(".sidebar-section-categories .sidebar-section-header-link");
- assert.strictEqual(
- currentURL(),
- "/categories",
- "it should transition to the categories page"
- );
- }
- );
+ assert.strictEqual(
+ currentURL(),
+ "/categories",
+ "it should transition to the categories page"
+ );
+ });
- conditionalTest(
- "category section links when user does not have any tracked categories",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/");
+ test("category section links when user does not have any tracked categories", async function (assert) {
+ await visit("/");
- assert.strictEqual(
- query(".sidebar-section-message").textContent.trim(),
- I18n.t("sidebar.sections.categories.no_tracked_categories"),
- "the no tracked categories message is displayed"
- );
- }
- );
+ assert.strictEqual(
+ query(".sidebar-section-message").textContent.trim(),
+ I18n.t("sidebar.sections.categories.no_tracked_categories"),
+ "the no tracked categories message is displayed"
+ );
+ });
- conditionalTest(
- "uncategorized category is shown when tracked",
- !isLegacyEmber(),
- async function (assert) {
- const categories = Site.current().categories;
+ test("uncategorized category is shown when tracked", async function (assert) {
+ const categories = Site.current().categories;
- const uncategorizedCategory = categories.find((category) => {
- return category.id === Site.current().uncategorized_category_id;
- });
+ const uncategorizedCategory = categories.find((category) => {
+ return category.id === Site.current().uncategorized_category_id;
+ });
- uncategorizedCategory.set(
- "notification_level",
- NotificationLevels.TRACKING
- );
+ uncategorizedCategory.set(
+ "notification_level",
+ NotificationLevels.TRACKING
+ );
- await visit("/");
+ await visit("/");
- assert.ok(
- exists(`.sidebar-section-link-${uncategorizedCategory.slug}`),
- `displays the section link for ${uncategorizedCategory.slug} category`
- );
- }
- );
+ assert.ok(
+ exists(`.sidebar-section-link-${uncategorizedCategory.slug}`),
+ `displays the section link for ${uncategorizedCategory.slug} category`
+ );
+ });
- conditionalTest(
- "category section links for tracked categories",
- !isLegacyEmber(),
- async function (assert) {
- const { category1, category2 } = setupTrackedCategories();
+ test("category section links for tracked categories", async function (assert) {
+ const { category1, category2 } = setupTrackedCategories();
- await visit("/");
+ await visit("/");
- assert.strictEqual(
- queryAll(".sidebar-section-categories .sidebar-section-link").length,
- 2,
- "there should only be two section link under the section"
- );
+ assert.strictEqual(
+ queryAll(".sidebar-section-categories .sidebar-section-link").length,
+ 2,
+ "there should only be two section link under the section"
+ );
- assert.ok(
- exists(`.sidebar-section-link-${category1.slug} .badge-category`),
- "category1 section link is rendered with category badge"
- );
+ assert.ok(
+ exists(`.sidebar-section-link-${category1.slug} .badge-category`),
+ "category1 section link is rendered with category badge"
+ );
- assert.strictEqual(
- query(`.sidebar-section-link-${category1.slug}`).textContent.trim(),
- category1.name,
- "displays category1's name for the link text"
- );
+ assert.strictEqual(
+ query(`.sidebar-section-link-${category1.slug}`).textContent.trim(),
+ category1.name,
+ "displays category1's name for the link text"
+ );
- await click(`.sidebar-section-link-${category1.slug}`);
+ await click(`.sidebar-section-link-${category1.slug}`);
- assert.strictEqual(
- currentURL(),
- `/c/${category1.slug}/${category1.id}/l/latest`,
- "it should transition to the category1's discovery page"
- );
+ assert.strictEqual(
+ currentURL(),
+ `/c/${category1.slug}/${category1.id}/l/latest`,
+ "it should transition to the category1's discovery page"
+ );
- assert.strictEqual(
- queryAll(".sidebar-section-categories .sidebar-section-link.active")
- .length,
- 1,
- "only one link is marked as active"
- );
+ assert.strictEqual(
+ queryAll(".sidebar-section-categories .sidebar-section-link.active")
+ .length,
+ 1,
+ "only one link is marked as active"
+ );
- assert.ok(
- exists(`.sidebar-section-link-${category1.slug}.active`),
- "the category1 section link is marked as active"
- );
+ assert.ok(
+ exists(`.sidebar-section-link-${category1.slug}.active`),
+ "the category1 section link is marked as active"
+ );
- await click(`.sidebar-section-link-${category2.slug}`);
+ await click(`.sidebar-section-link-${category2.slug}`);
- assert.strictEqual(
- currentURL(),
- `/c/${category2.slug}/${category2.id}/l/latest`,
- "it should transition to the category2's discovery page"
- );
+ assert.strictEqual(
+ currentURL(),
+ `/c/${category2.slug}/${category2.id}/l/latest`,
+ "it should transition to the category2's discovery page"
+ );
- assert.strictEqual(
- queryAll(".sidebar-section-categories .sidebar-section-link.active")
- .length,
- 1,
- "only one link is marked as active"
- );
+ assert.strictEqual(
+ queryAll(".sidebar-section-categories .sidebar-section-link.active")
+ .length,
+ 1,
+ "only one link is marked as active"
+ );
- assert.ok(
- exists(`.sidebar-section-link-${category2.slug}.active`),
- "the category2 section link is marked as active"
- );
- }
- );
+ assert.ok(
+ exists(`.sidebar-section-link-${category2.slug}.active`),
+ "the category2 section link is marked as active"
+ );
+ });
- conditionalTest(
- "visiting category discovery new route for tracked categories",
- !isLegacyEmber(),
- async function (assert) {
- const { category1 } = setupTrackedCategories();
+ test("visiting category discovery new route for tracked categories", async function (assert) {
+ const { category1 } = setupTrackedCategories();
- await visit(`/c/${category1.slug}/${category1.id}/l/new`);
+ await visit(`/c/${category1.slug}/${category1.id}/l/new`);
- assert.strictEqual(
- queryAll(".sidebar-section-categories .sidebar-section-link.active")
- .length,
- 1,
- "only one link is marked as active"
- );
+ assert.strictEqual(
+ queryAll(".sidebar-section-categories .sidebar-section-link.active")
+ .length,
+ 1,
+ "only one link is marked as active"
+ );
- assert.ok(
- exists(`.sidebar-section-link-${category1.slug}.active`),
- "the category1 section link is marked as active for the new route"
- );
- }
- );
+ assert.ok(
+ exists(`.sidebar-section-link-${category1.slug}.active`),
+ "the category1 section link is marked as active for the new route"
+ );
+ });
- conditionalTest(
- "visiting category discovery unread route for tracked categories",
- !isLegacyEmber(),
- async function (assert) {
- const { category1 } = setupTrackedCategories();
+ test("visiting category discovery unread route for tracked categories", async function (assert) {
+ const { category1 } = setupTrackedCategories();
- await visit(`/c/${category1.slug}/${category1.id}/l/unread`);
+ await visit(`/c/${category1.slug}/${category1.id}/l/unread`);
- assert.strictEqual(
- queryAll(".sidebar-section-categories .sidebar-section-link.active")
- .length,
- 1,
- "only one link is marked as active"
- );
+ assert.strictEqual(
+ queryAll(".sidebar-section-categories .sidebar-section-link.active")
+ .length,
+ 1,
+ "only one link is marked as active"
+ );
- assert.ok(
- exists(`.sidebar-section-link-${category1.slug}.active`),
- "the category1 section link is marked as active for the unread route"
- );
- }
- );
+ assert.ok(
+ exists(`.sidebar-section-link-${category1.slug}.active`),
+ "the category1 section link is marked as active for the unread route"
+ );
+ });
- conditionalTest(
- "visiting category discovery top route for tracked categories",
- !isLegacyEmber(),
- async function (assert) {
- const { category1 } = setupTrackedCategories();
+ test("visiting category discovery top route for tracked categories", async function (assert) {
+ const { category1 } = setupTrackedCategories();
- await visit(`/c/${category1.slug}/${category1.id}/l/top`);
+ await visit(`/c/${category1.slug}/${category1.id}/l/top`);
- assert.strictEqual(
- queryAll(".sidebar-section-categories .sidebar-section-link.active")
- .length,
- 1,
- "only one link is marked as active"
- );
+ assert.strictEqual(
+ queryAll(".sidebar-section-categories .sidebar-section-link.active")
+ .length,
+ 1,
+ "only one link is marked as active"
+ );
- assert.ok(
- exists(`.sidebar-section-link-${category1.slug}.active`),
- "the category1 section link is marked as active for the top route"
- );
- }
- );
+ assert.ok(
+ exists(`.sidebar-section-link-${category1.slug}.active`),
+ "the category1 section link is marked as active for the top route"
+ );
+ });
- conditionalTest(
- "updating category notification level",
- !isLegacyEmber(),
- async function (assert) {
- const { category1, category2 } = setupTrackedCategories();
+ test("updating category notification level", async function (assert) {
+ const { category1, category2 } = setupTrackedCategories();
- await visit(`/c/${category1.slug}/${category1.id}/l/top`);
+ await visit(`/c/${category1.slug}/${category1.id}/l/top`);
- assert.ok(
- exists(`.sidebar-section-link-${category1.slug}`),
- `has ${category1.name} section link in sidebar`
- );
+ assert.ok(
+ exists(`.sidebar-section-link-${category1.slug}`),
+ `has ${category1.name} section link in sidebar`
+ );
- assert.ok(
- exists(`.sidebar-section-link-${category2.slug}`),
- `has ${category2.name} section link in sidebar`
- );
+ assert.ok(
+ exists(`.sidebar-section-link-${category2.slug}`),
+ `has ${category2.name} section link in sidebar`
+ );
- const notificationLevelsDropdown = selectKit(".notifications-button");
+ const notificationLevelsDropdown = selectKit(".notifications-button");
- await notificationLevelsDropdown.expand();
+ await notificationLevelsDropdown.expand();
- await notificationLevelsDropdown.selectRowByValue(
- NotificationLevels.REGULAR
- );
+ await notificationLevelsDropdown.selectRowByValue(
+ NotificationLevels.REGULAR
+ );
- assert.ok(
- !exists(`.sidebar-section-link-${category1.slug}`),
- `does not have ${category1.name} section link in sidebar`
- );
+ assert.ok(
+ !exists(`.sidebar-section-link-${category1.slug}`),
+ `does not have ${category1.name} section link in sidebar`
+ );
- assert.ok(
- exists(`.sidebar-section-link-${category2.slug}`),
- `has ${category2.name} section link in sidebar`
- );
+ assert.ok(
+ exists(`.sidebar-section-link-${category2.slug}`),
+ `has ${category2.name} section link in sidebar`
+ );
- await notificationLevelsDropdown.expand();
+ await notificationLevelsDropdown.expand();
- await notificationLevelsDropdown.selectRowByValue(
- NotificationLevels.TRACKING
- );
+ await notificationLevelsDropdown.selectRowByValue(
+ NotificationLevels.TRACKING
+ );
- assert.ok(
- exists(`.sidebar-section-link-${category1.slug}`),
- `has ${category1.name} section link in sidebar`
- );
+ assert.ok(
+ exists(`.sidebar-section-link-${category1.slug}`),
+ `has ${category1.name} section link in sidebar`
+ );
- assert.ok(
- exists(`.sidebar-section-link-${category2.slug}`),
- `has ${category2.name} section link in sidebar`
- );
- }
- );
-
- conditionalTest(
- "new and unread count for categories link",
- !isLegacyEmber(),
- async function (assert) {
- const { category1, category2 } = setupTrackedCategories();
-
- this.container.lookup("topic-tracking-state:main").loadStates([
- {
- topic_id: 1,
- highest_post_number: 1,
- last_read_post_number: null,
- created_at: "2022-05-11T03:09:31.959Z",
- category_id: category1.id,
- notification_level: null,
- created_in_new_period: true,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- },
- {
- topic_id: 2,
- highest_post_number: 12,
- last_read_post_number: 11,
- created_at: "2020-02-09T09:40:02.672Z",
- category_id: category1.id,
- notification_level: 2,
- created_in_new_period: false,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- },
- {
- topic_id: 3,
- highest_post_number: 15,
- last_read_post_number: 14,
- created_at: "2021-06-14T12:41:02.477Z",
- category_id: category2.id,
- notification_level: 2,
- created_in_new_period: false,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- },
- {
- topic_id: 4,
- highest_post_number: 17,
- last_read_post_number: 16,
- created_at: "2020-10-31T03:41:42.257Z",
- category_id: category2.id,
- notification_level: 2,
- created_in_new_period: false,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- },
- ]);
+ assert.ok(
+ exists(`.sidebar-section-link-${category2.slug}`),
+ `has ${category2.name} section link in sidebar`
+ );
+ });
- await visit("/");
+ test("new and unread count for categories link", async function (assert) {
+ const { category1, category2 } = setupTrackedCategories();
- assert.strictEqual(
- query(
- `.sidebar-section-link-${category1.slug} .sidebar-section-link-content-badge`
- ).textContent.trim(),
- I18n.t("sidebar.unread_count", { count: 1 }),
- `displays 1 unread count for ${category1.slug} section link`
- );
+ this.container.lookup("topic-tracking-state:main").loadStates([
+ {
+ topic_id: 1,
+ highest_post_number: 1,
+ last_read_post_number: null,
+ created_at: "2022-05-11T03:09:31.959Z",
+ category_id: category1.id,
+ notification_level: null,
+ created_in_new_period: true,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ },
+ {
+ topic_id: 2,
+ highest_post_number: 12,
+ last_read_post_number: 11,
+ created_at: "2020-02-09T09:40:02.672Z",
+ category_id: category1.id,
+ notification_level: 2,
+ created_in_new_period: false,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ },
+ {
+ topic_id: 3,
+ highest_post_number: 15,
+ last_read_post_number: 14,
+ created_at: "2021-06-14T12:41:02.477Z",
+ category_id: category2.id,
+ notification_level: 2,
+ created_in_new_period: false,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ },
+ {
+ topic_id: 4,
+ highest_post_number: 17,
+ last_read_post_number: 16,
+ created_at: "2020-10-31T03:41:42.257Z",
+ category_id: category2.id,
+ notification_level: 2,
+ created_in_new_period: false,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ },
+ ]);
+
+ await visit("/");
+
+ assert.strictEqual(
+ query(
+ `.sidebar-section-link-${category1.slug} .sidebar-section-link-content-badge`
+ ).textContent.trim(),
+ I18n.t("sidebar.unread_count", { count: 1 }),
+ `displays 1 unread count for ${category1.slug} section link`
+ );
- assert.strictEqual(
- query(
- `.sidebar-section-link-${category2.slug} .sidebar-section-link-content-badge`
- ).textContent.trim(),
- I18n.t("sidebar.unread_count", { count: 2 }),
- `displays 2 unread count for ${category2.slug} section link`
- );
+ assert.strictEqual(
+ query(
+ `.sidebar-section-link-${category2.slug} .sidebar-section-link-content-badge`
+ ).textContent.trim(),
+ I18n.t("sidebar.unread_count", { count: 2 }),
+ `displays 2 unread count for ${category2.slug} section link`
+ );
- publishToMessageBus("/unread", {
- topic_id: 2,
- message_type: "read",
- payload: {
- last_read_post_number: 12,
- highest_post_number: 12,
- },
- });
+ publishToMessageBus("/unread", {
+ topic_id: 2,
+ message_type: "read",
+ payload: {
+ last_read_post_number: 12,
+ highest_post_number: 12,
+ },
+ });
- await settled();
+ await settled();
- assert.strictEqual(
- query(
- `.sidebar-section-link-${category1.slug} .sidebar-section-link-content-badge`
- ).textContent.trim(),
- I18n.t("sidebar.new_count", { count: 1 }),
- `displays 1 new count for ${category1.slug} section link`
- );
+ assert.strictEqual(
+ query(
+ `.sidebar-section-link-${category1.slug} .sidebar-section-link-content-badge`
+ ).textContent.trim(),
+ I18n.t("sidebar.new_count", { count: 1 }),
+ `displays 1 new count for ${category1.slug} section link`
+ );
- publishToMessageBus("/unread", {
- topic_id: 1,
- message_type: "read",
- payload: {
- last_read_post_number: 1,
- highest_post_number: 1,
- },
- });
+ publishToMessageBus("/unread", {
+ topic_id: 1,
+ message_type: "read",
+ payload: {
+ last_read_post_number: 1,
+ highest_post_number: 1,
+ },
+ });
- await settled();
+ await settled();
- assert.ok(
- !exists(
- `.sidebar-section-link-${category1.slug} .sidebar-section-link-content-badge`
- ),
- `does not display any badge ${category1.slug} section link`
- );
+ assert.ok(
+ !exists(
+ `.sidebar-section-link-${category1.slug} .sidebar-section-link-content-badge`
+ ),
+ `does not display any badge ${category1.slug} section link`
+ );
- publishToMessageBus("/unread", {
- topic_id: 3,
- message_type: "read",
- payload: {
- last_read_post_number: 15,
- highest_post_number: 15,
- },
- });
+ publishToMessageBus("/unread", {
+ topic_id: 3,
+ message_type: "read",
+ payload: {
+ last_read_post_number: 15,
+ highest_post_number: 15,
+ },
+ });
- await settled();
+ await settled();
- assert.strictEqual(
- query(
- `.sidebar-section-link-${category2.slug} .sidebar-section-link-content-badge`
- ).textContent.trim(),
- I18n.t("sidebar.unread_count", { count: 1 }),
- `displays 1 unread count for ${category2.slug} section link`
- );
- }
- );
+ assert.strictEqual(
+ query(
+ `.sidebar-section-link-${category2.slug} .sidebar-section-link-content-badge`
+ ).textContent.trim(),
+ I18n.t("sidebar.unread_count", { count: 1 }),
+ `displays 1 unread count for ${category2.slug} section link`
+ );
+ });
- conditionalTest(
- "clean up topic tracking state state changed callbacks when section is destroyed",
- !isLegacyEmber(),
- async function (assert) {
- setupTrackedCategories();
+ test("clean up topic tracking state state changed callbacks when section is destroyed", async function (assert) {
+ setupTrackedCategories();
- await visit("/");
+ await visit("/");
- const topicTrackingState = this.container.lookup(
- "topic-tracking-state:main"
- );
+ const topicTrackingState = this.container.lookup(
+ "topic-tracking-state:main"
+ );
- const initialCallbackCount = Object.keys(
- topicTrackingState.stateChangeCallbacks
- ).length;
+ const initialCallbackCount = Object.keys(
+ topicTrackingState.stateChangeCallbacks
+ ).length;
- await click(".header-sidebar-toggle .btn");
- await click(".header-sidebar-toggle .btn");
+ await click(".header-sidebar-toggle .btn");
+ await click(".header-sidebar-toggle .btn");
- assert.strictEqual(
- Object.keys(topicTrackingState.stateChangeCallbacks).length,
- initialCallbackCount
- );
- }
- );
+ assert.strictEqual(
+ Object.keys(topicTrackingState.stateChangeCallbacks).length,
+ initialCallbackCount
+ );
+ });
});
diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-messages-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-messages-section-test.js
index 5eeda44c281..5865a4a45bd 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-messages-section-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-messages-section-test.js
@@ -1,13 +1,13 @@
+import { test } from "qunit";
+
import { click, currentURL, visit } from "@ember/test-helpers";
import {
acceptance,
- conditionalTest,
exists,
queryAll,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
-import { isLegacyEmber } from "discourse-common/config/environment";
acceptance(
"Sidebar - Messages Section - enable_personal_messages disabled",
@@ -20,18 +20,14 @@ acceptance(
enable_personal_messages: false,
});
- conditionalTest(
- "clicking on section header button",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/");
+ test("clicking on section header button", async function (assert) {
+ await visit("/");
- assert.ok(
- !exists(".sidebar-section-messages"),
- "does not display messages section in sidebar"
- );
- }
- );
+ assert.ok(
+ !exists(".sidebar-section-messages"),
+ "does not display messages section in sidebar"
+ );
+ });
}
);
@@ -69,57 +65,85 @@ acceptance(
});
});
- conditionalTest(
- "clicking on section header button",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/");
+ test("clicking on section header button", async function (assert) {
+ await visit("/");
- await click(".sidebar-section-messages .sidebar-section-header-button");
+ await click(".sidebar-section-messages .sidebar-section-header-button");
- assert.ok(
- exists("#reply-control.private-message"),
- "it opens the composer"
- );
- }
- );
+ assert.ok(
+ exists("#reply-control.private-message"),
+ "it opens the composer"
+ );
+ });
- conditionalTest(
- "clicking on section header link",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/");
- await click(".sidebar-section-messages .sidebar-section-header-link");
+ test("clicking on section header link", async function (assert) {
+ await visit("/");
+ await click(".sidebar-section-messages .sidebar-section-header-link");
- assert.strictEqual(
- currentURL(),
- `/u/eviltrout/messages`,
- "it should transistion to the user's messages"
- );
- }
- );
+ assert.strictEqual(
+ currentURL(),
+ `/u/eviltrout/messages`,
+ "it should transistion to the user's messages"
+ );
+ });
+
+ test("personal messages section links", async function (assert) {
+ await visit("/");
+
+ assert.ok(
+ exists(
+ ".sidebar-section-messages .sidebar-section-link-personal-messages-inbox"
+ ),
+ "displays the personal message inbox link"
+ );
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-messages .sidebar-section-link").length,
+ 1,
+ "only displays the personal message inbox link"
+ );
+
+ await click(
+ ".sidebar-section-messages .sidebar-section-link-personal-messages-inbox"
+ );
- conditionalTest(
- "personal messages section links",
- !isLegacyEmber(),
- async function (assert) {
+ assert.ok(
+ exists(
+ ".sidebar-section-messages .sidebar-section-link-personal-messages-inbox.active"
+ ),
+ "personal message inbox link is marked as active"
+ );
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-messages .sidebar-section-link").length,
+ 5,
+ "expands and displays the links for personal messages"
+ );
+ });
+
+ ["new", "archive", "sent", "unread"].forEach((type) => {
+ test(`${type} personal messages section link`, async function (assert) {
await visit("/");
- assert.ok(
- exists(
- ".sidebar-section-messages .sidebar-section-link-personal-messages-inbox"
- ),
- "displays the personal message inbox link"
+ await click(
+ ".sidebar-section-messages .sidebar-section-link-personal-messages-inbox"
+ );
+
+ await click(
+ `.sidebar-section-messages .sidebar-section-link-personal-messages-${type}`
);
assert.strictEqual(
- queryAll(".sidebar-section-messages .sidebar-section-link").length,
- 1,
- "only displays the personal message inbox link"
+ currentURL(),
+ `/u/eviltrout/messages/${type}`,
+ `it should transition to user's ${type} personal messages`
);
- await click(
- ".sidebar-section-messages .sidebar-section-link-personal-messages-inbox"
+ assert.strictEqual(
+ queryAll(".sidebar-section-messages .sidebar-section-link.active")
+ .length,
+ 2,
+ "only two links are marked as active in the sidebar"
);
assert.ok(
@@ -129,63 +153,85 @@ acceptance(
"personal message inbox link is marked as active"
);
- assert.strictEqual(
- queryAll(".sidebar-section-messages .sidebar-section-link").length,
- 5,
- "expands and displays the links for personal messages"
+ assert.ok(
+ exists(
+ `.sidebar-section-messages .sidebar-section-link-personal-messages-${type}.active`
+ ),
+ `personal message ${type} link is marked as active`
);
- }
- );
+ });
+ });
- ["new", "archive", "sent", "unread"].forEach((type) => {
- conditionalTest(
- `${type} personal messages section link`,
- !isLegacyEmber(),
- async function (assert) {
- await visit("/");
-
- await click(
- ".sidebar-section-messages .sidebar-section-link-personal-messages-inbox"
- );
-
- await click(
- `.sidebar-section-messages .sidebar-section-link-personal-messages-${type}`
- );
-
- assert.strictEqual(
- currentURL(),
- `/u/eviltrout/messages/${type}`,
- `it should transition to user's ${type} personal messages`
- );
-
- assert.strictEqual(
- queryAll(".sidebar-section-messages .sidebar-section-link.active")
- .length,
- 2,
- "only two links are marked as active in the sidebar"
- );
-
- assert.ok(
- exists(
- ".sidebar-section-messages .sidebar-section-link-personal-messages-inbox.active"
- ),
- "personal message inbox link is marked as active"
- );
-
- assert.ok(
- exists(
- `.sidebar-section-messages .sidebar-section-link-personal-messages-${type}.active`
- ),
- `personal message ${type} link is marked as active`
- );
- }
+ test("group messages section links", async function (assert) {
+ updateCurrentUser({
+ groups: [
+ {
+ name: "group1",
+ has_messages: true,
+ },
+ {
+ name: "group2",
+ has_messages: false,
+ },
+ {
+ name: "group3",
+ has_messages: true,
+ },
+ ],
+ });
+
+ await visit("/");
+
+ assert.ok(
+ exists(
+ ".sidebar-section-messages .sidebar-section-link-group-messages-inbox.group1"
+ ),
+ "displays group1 inbox link"
+ );
+
+ assert.ok(
+ exists(
+ ".sidebar-section-messages .sidebar-section-link-group-messages-inbox.group3"
+ ),
+ "displays group3 inbox link"
+ );
+
+ await visit("/u/eviltrout/messages/group/GrOuP1");
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-messages .sidebar-section-link").length,
+ 6,
+ "expands and displays the links for group1 group messages"
+ );
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-messages .sidebar-section-link.group1")
+ .length,
+ 4,
+ "expands the links for group1 group messages"
+ );
+
+ await click(
+ ".sidebar-section-messages .sidebar-section-link-group-messages-inbox.group3"
+ );
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-messages .sidebar-section-link.group1")
+ .length,
+ 1,
+ "collapses the links for group1 group messages"
+ );
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-messages .sidebar-section-link.group3")
+ .length,
+ 4,
+ "expands the links for group3 group messages"
);
});
- conditionalTest(
- "group messages section links",
- !isLegacyEmber(),
- async function (assert) {
+ ["new", "archive", "unread"].forEach((type) => {
+ test(`${type} group messages section link`, async function (assert) {
updateCurrentUser({
groups: [
{
@@ -205,115 +251,41 @@ acceptance(
await visit("/");
- assert.ok(
- exists(
- ".sidebar-section-messages .sidebar-section-link-group-messages-inbox.group1"
- ),
- "displays group1 inbox link"
+ await click(
+ `.sidebar-section-messages .sidebar-section-link-group-messages-inbox.group1`
);
- assert.ok(
- exists(
- ".sidebar-section-messages .sidebar-section-link-group-messages-inbox.group3"
- ),
- "displays group3 inbox link"
+ await click(
+ `.sidebar-section-messages .sidebar-section-link-group-messages-${type}.group1`
);
- await visit("/u/eviltrout/messages/group/GrOuP1");
-
assert.strictEqual(
- queryAll(".sidebar-section-messages .sidebar-section-link").length,
- 6,
- "expands and displays the links for group1 group messages"
+ currentURL(),
+ `/u/eviltrout/messages/group/group1/${type}`,
+ `it should transition to user's ${type} personal messages`
);
assert.strictEqual(
- queryAll(".sidebar-section-messages .sidebar-section-link.group1")
+ queryAll(".sidebar-section-messages .sidebar-section-link.active")
.length,
- 4,
- "expands the links for group1 group messages"
- );
-
- await click(
- ".sidebar-section-messages .sidebar-section-link-group-messages-inbox.group3"
+ 2,
+ "only two links are marked as active in the sidebar"
);
- assert.strictEqual(
- queryAll(".sidebar-section-messages .sidebar-section-link.group1")
- .length,
- 1,
- "collapses the links for group1 group messages"
+ assert.ok(
+ exists(
+ ".sidebar-section-messages .sidebar-section-link-group-messages-inbox.group1.active"
+ ),
+ "group1 group message inbox link is marked as active"
);
- assert.strictEqual(
- queryAll(".sidebar-section-messages .sidebar-section-link.group3")
- .length,
- 4,
- "expands the links for group3 group messages"
+ assert.ok(
+ exists(
+ `.sidebar-section-messages .sidebar-section-link-group-messages-${type}.group1.active`
+ ),
+ `group1 group message ${type} link is marked as active`
);
- }
- );
-
- ["new", "archive", "unread"].forEach((type) => {
- conditionalTest(
- `${type} group messages section link`,
- !isLegacyEmber(),
- async function (assert) {
- updateCurrentUser({
- groups: [
- {
- name: "group1",
- has_messages: true,
- },
- {
- name: "group2",
- has_messages: false,
- },
- {
- name: "group3",
- has_messages: true,
- },
- ],
- });
-
- await visit("/");
-
- await click(
- `.sidebar-section-messages .sidebar-section-link-group-messages-inbox.group1`
- );
-
- await click(
- `.sidebar-section-messages .sidebar-section-link-group-messages-${type}.group1`
- );
-
- assert.strictEqual(
- currentURL(),
- `/u/eviltrout/messages/group/group1/${type}`,
- `it should transition to user's ${type} personal messages`
- );
-
- assert.strictEqual(
- queryAll(".sidebar-section-messages .sidebar-section-link.active")
- .length,
- 2,
- "only two links are marked as active in the sidebar"
- );
-
- assert.ok(
- exists(
- ".sidebar-section-messages .sidebar-section-link-group-messages-inbox.group1.active"
- ),
- "group1 group message inbox link is marked as active"
- );
-
- assert.ok(
- exists(
- `.sidebar-section-messages .sidebar-section-link-group-messages-${type}.group1.active`
- ),
- `group1 group message ${type} link is marked as active`
- );
- }
- );
+ });
});
}
);
diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-tags-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-tags-section-test.js
index cf220996fb9..17aa7a78612 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-tags-section-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-tags-section-test.js
@@ -1,17 +1,16 @@
import I18n from "I18n";
+import { test } from "qunit";
import { click, currentURL, settled, visit } from "@ember/test-helpers";
import {
acceptance,
- conditionalTest,
exists,
publishToMessageBus,
query,
queryAll,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
-import { isLegacyEmber } from "discourse-common/config/environment";
import discoveryFixture from "discourse/tests/fixtures/discovery-fixtures";
import { cloneJSON } from "discourse-common/lib/object";
import selectKit from "discourse/tests/helpers/select-kit-helper";
@@ -24,18 +23,14 @@ acceptance("Sidebar - Tags section - tagging disabled", function (needs) {
needs.user({ experimental_sidebar_enabled: true });
- conditionalTest(
- "tags section is not shown",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/");
-
- assert.ok(
- !exists(".sidebar-section-tags"),
- "does not display the tags section"
- );
- }
- );
+ test("tags section is not shown", async function (assert) {
+ await visit("/");
+
+ assert.ok(
+ !exists(".sidebar-section-tags"),
+ "does not display the tags section"
+ );
+ });
});
acceptance("Sidebar - Tags section", function (needs) {
@@ -76,331 +71,291 @@ acceptance("Sidebar - Tags section", function (needs) {
});
});
- conditionalTest(
- "clicking on section header link",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/");
- await click(".sidebar-section-tags .sidebar-section-header-link");
-
- assert.strictEqual(
- currentURL(),
- "/tags",
- "it should transition to the tags page"
- );
- }
- );
-
- conditionalTest(
- "section content when user does not have any tracked tags",
- !isLegacyEmber(),
- async function (assert) {
- updateCurrentUser({
- tracked_tags: [],
- watched_tags: [],
- watching_first_post_tags: [],
- });
+ test("clicking on section header link", async function (assert) {
+ await visit("/");
+ await click(".sidebar-section-tags .sidebar-section-header-link");
- await visit("/");
-
- assert.strictEqual(
- query(
- ".sidebar-section-tags .sidebar-section-message"
- ).textContent.trim(),
- I18n.t("sidebar.sections.tags.no_tracked_tags"),
- "the no tracked tags message is displayed"
- );
- }
- );
-
- conditionalTest(
- "tag section links for tracked tags",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/");
-
- assert.strictEqual(
- queryAll(".sidebar-section-tags .sidebar-section-link").length,
- 3,
- "3 section links under the section"
- );
-
- assert.strictEqual(
- query(".sidebar-section-link-tag1").textContent.trim(),
- "tag1",
- "displays the tag1 name for the link text"
- );
-
- assert.strictEqual(
- query(".sidebar-section-link-tag2").textContent.trim(),
- "tag2",
- "displays the tag2 name for the link text"
- );
-
- assert.strictEqual(
- query(".sidebar-section-link-tag3").textContent.trim(),
- "tag3",
- "displays the tag3 name for the link text"
- );
-
- await click(".sidebar-section-link-tag1");
-
- assert.strictEqual(
- currentURL(),
- "/tag/tag1",
- "it should transition to tag1's topics discovery page"
- );
-
- assert.strictEqual(
- queryAll(".sidebar-section-tags .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(`.sidebar-section-link-tag1.active`),
- "the tag1 section link is marked as active"
- );
-
- await click(".sidebar-section-link-tag2");
-
- assert.strictEqual(
- currentURL(),
- "/tag/tag2",
- "it should transition to tag2's topics discovery page"
- );
-
- assert.strictEqual(
- queryAll(".sidebar-section-tags .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(`.sidebar-section-link-tag2.active`),
- "the tag2 section link is marked as active"
- );
- }
- );
-
- conditionalTest(
- "visiting tag discovery top route for tracked tags",
- !isLegacyEmber(),
- async function (assert) {
- await visit(`/tag/tag1/l/top`);
-
- assert.strictEqual(
- queryAll(".sidebar-section-tags .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(".sidebar-section-link-tag1.active"),
- "the tag1 section link is marked as active for the top route"
- );
- }
- );
-
- conditionalTest(
- "visiting tag discovery new route for tracked tags",
- !isLegacyEmber(),
- async function (assert) {
- await visit(`/tag/tag1/l/new`);
-
- assert.strictEqual(
- queryAll(".sidebar-section-tags .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(".sidebar-section-link-tag1.active"),
- "the tag1 section link is marked as active for the new route"
- );
- }
- );
-
- conditionalTest(
- "visiting tag discovery unread route for tracked tags",
- !isLegacyEmber(),
- async function (assert) {
- await visit(`/tag/tag1/l/unread`);
-
- assert.strictEqual(
- queryAll(".sidebar-section-tags .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(".sidebar-section-link-tag1.active"),
- "the tag1 section link is marked as active for the unread route"
- );
- }
- );
-
- conditionalTest(
- "new and unread count for tag section links",
- !isLegacyEmber(),
- async function (assert) {
- this.container.lookup("topic-tracking-state:main").loadStates([
- {
- topic_id: 1,
- highest_post_number: 1,
- last_read_post_number: null,
- created_at: "2022-05-11T03:09:31.959Z",
- category_id: 1,
- notification_level: null,
- created_in_new_period: true,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- tags: ["tag1"],
- },
- {
- topic_id: 2,
- highest_post_number: 12,
- last_read_post_number: 11,
- created_at: "2020-02-09T09:40:02.672Z",
- category_id: 2,
- notification_level: 2,
- created_in_new_period: false,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- tags: ["tag1"],
- },
- {
- topic_id: 3,
- highest_post_number: 15,
- last_read_post_number: 14,
- created_at: "2021-06-14T12:41:02.477Z",
- category_id: 3,
- notification_level: 2,
- created_in_new_period: false,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- tags: ["tag2"],
- },
- {
- topic_id: 4,
- highest_post_number: 17,
- last_read_post_number: 16,
- created_at: "2020-10-31T03:41:42.257Z",
- category_id: 4,
- notification_level: 2,
- created_in_new_period: false,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- tags: ["tag4"],
- },
- ]);
-
- await visit("/");
-
- assert.strictEqual(
- query(
- `.sidebar-section-link-tag1 .sidebar-section-link-content-badge`
- ).textContent.trim(),
- I18n.t("sidebar.unread_count", { count: 1 }),
- `displays 1 unread count for tag1 section link`
- );
-
- assert.strictEqual(
- query(
- `.sidebar-section-link-tag2 .sidebar-section-link-content-badge`
- ).textContent.trim(),
- I18n.t("sidebar.unread_count", { count: 1 }),
- `displays 1 unread count for tag2 section link`
- );
-
- assert.ok(
- !exists(
- `.sidebar-section-link-tag3 .sidebar-section-link-content-badge`
- ),
- "does not display any badge for tag3 section link"
- );
-
- publishToMessageBus("/unread", {
- topic_id: 2,
- message_type: "read",
- payload: {
- last_read_post_number: 12,
- highest_post_number: 12,
- },
- });
+ assert.strictEqual(
+ currentURL(),
+ "/tags",
+ "it should transition to the tags page"
+ );
+ });
+
+ test("section content when user does not have any tracked tags", async function (assert) {
+ updateCurrentUser({
+ tracked_tags: [],
+ watched_tags: [],
+ watching_first_post_tags: [],
+ });
+
+ await visit("/");
- await settled();
+ assert.strictEqual(
+ query(
+ ".sidebar-section-tags .sidebar-section-message"
+ ).textContent.trim(),
+ I18n.t("sidebar.sections.tags.no_tracked_tags"),
+ "the no tracked tags message is displayed"
+ );
+ });
+
+ test("tag section links for tracked tags", async function (assert) {
+ await visit("/");
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-tags .sidebar-section-link").length,
+ 3,
+ "3 section links under the section"
+ );
+
+ assert.strictEqual(
+ query(".sidebar-section-link-tag1").textContent.trim(),
+ "tag1",
+ "displays the tag1 name for the link text"
+ );
+
+ assert.strictEqual(
+ query(".sidebar-section-link-tag2").textContent.trim(),
+ "tag2",
+ "displays the tag2 name for the link text"
+ );
+
+ assert.strictEqual(
+ query(".sidebar-section-link-tag3").textContent.trim(),
+ "tag3",
+ "displays the tag3 name for the link text"
+ );
+
+ await click(".sidebar-section-link-tag1");
+
+ assert.strictEqual(
+ currentURL(),
+ "/tag/tag1",
+ "it should transition to tag1's topics discovery page"
+ );
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-tags .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(`.sidebar-section-link-tag1.active`),
+ "the tag1 section link is marked as active"
+ );
+
+ await click(".sidebar-section-link-tag2");
+
+ assert.strictEqual(
+ currentURL(),
+ "/tag/tag2",
+ "it should transition to tag2's topics discovery page"
+ );
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-tags .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(`.sidebar-section-link-tag2.active`),
+ "the tag2 section link is marked as active"
+ );
+ });
+
+ test("visiting tag discovery top route for tracked tags", async function (assert) {
+ await visit(`/tag/tag1/l/top`);
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-tags .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-link-tag1.active"),
+ "the tag1 section link is marked as active for the top route"
+ );
+ });
+
+ test("visiting tag discovery new route for tracked tags", async function (assert) {
+ await visit(`/tag/tag1/l/new`);
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-tags .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-link-tag1.active"),
+ "the tag1 section link is marked as active for the new route"
+ );
+ });
- assert.strictEqual(
- query(
- `.sidebar-section-link-tag1 .sidebar-section-link-content-badge`
- ).textContent.trim(),
- I18n.t("sidebar.new_count", { count: 1 }),
- `displays 1 new count for tag1 section link`
- );
+ test("visiting tag discovery unread route for tracked tags", async function (assert) {
+ await visit(`/tag/tag1/l/unread`);
- publishToMessageBus("/unread", {
+ assert.strictEqual(
+ queryAll(".sidebar-section-tags .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-link-tag1.active"),
+ "the tag1 section link is marked as active for the unread route"
+ );
+ });
+
+ test("new and unread count for tag section links", async function (assert) {
+ this.container.lookup("topic-tracking-state:main").loadStates([
+ {
topic_id: 1,
- message_type: "read",
- payload: {
- last_read_post_number: 1,
- highest_post_number: 1,
- },
- });
+ highest_post_number: 1,
+ last_read_post_number: null,
+ created_at: "2022-05-11T03:09:31.959Z",
+ category_id: 1,
+ notification_level: null,
+ created_in_new_period: true,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ tags: ["tag1"],
+ },
+ {
+ topic_id: 2,
+ highest_post_number: 12,
+ last_read_post_number: 11,
+ created_at: "2020-02-09T09:40:02.672Z",
+ category_id: 2,
+ notification_level: 2,
+ created_in_new_period: false,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ tags: ["tag1"],
+ },
+ {
+ topic_id: 3,
+ highest_post_number: 15,
+ last_read_post_number: 14,
+ created_at: "2021-06-14T12:41:02.477Z",
+ category_id: 3,
+ notification_level: 2,
+ created_in_new_period: false,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ tags: ["tag2"],
+ },
+ {
+ topic_id: 4,
+ highest_post_number: 17,
+ last_read_post_number: 16,
+ created_at: "2020-10-31T03:41:42.257Z",
+ category_id: 4,
+ notification_level: 2,
+ created_in_new_period: false,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ tags: ["tag4"],
+ },
+ ]);
+
+ await visit("/");
+
+ assert.strictEqual(
+ query(
+ `.sidebar-section-link-tag1 .sidebar-section-link-content-badge`
+ ).textContent.trim(),
+ I18n.t("sidebar.unread_count", { count: 1 }),
+ `displays 1 unread count for tag1 section link`
+ );
+
+ assert.strictEqual(
+ query(
+ `.sidebar-section-link-tag2 .sidebar-section-link-content-badge`
+ ).textContent.trim(),
+ I18n.t("sidebar.unread_count", { count: 1 }),
+ `displays 1 unread count for tag2 section link`
+ );
+
+ assert.ok(
+ !exists(`.sidebar-section-link-tag3 .sidebar-section-link-content-badge`),
+ "does not display any badge for tag3 section link"
+ );
+
+ publishToMessageBus("/unread", {
+ topic_id: 2,
+ message_type: "read",
+ payload: {
+ last_read_post_number: 12,
+ highest_post_number: 12,
+ },
+ });
+
+ await settled();
+
+ assert.strictEqual(
+ query(
+ `.sidebar-section-link-tag1 .sidebar-section-link-content-badge`
+ ).textContent.trim(),
+ I18n.t("sidebar.new_count", { count: 1 }),
+ `displays 1 new count for tag1 section link`
+ );
+
+ publishToMessageBus("/unread", {
+ topic_id: 1,
+ message_type: "read",
+ payload: {
+ last_read_post_number: 1,
+ highest_post_number: 1,
+ },
+ });
+
+ await settled();
+
+ assert.ok(
+ !exists(`.sidebar-section-link-tag1 .sidebar-section-link-content-badge`),
+ `does not display any badge tag1 section link`
+ );
+ });
- await settled();
-
- assert.ok(
- !exists(
- `.sidebar-section-link-tag1 .sidebar-section-link-content-badge`
- ),
- `does not display any badge tag1 section link`
- );
- }
- );
-
- conditionalTest(
- "cleans up topic tracking state state changed callbacks when section is destroyed",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/");
-
- const topicTrackingState = this.container.lookup(
- "topic-tracking-state:main"
- );
-
- const initialCallbackCount = Object.keys(
- topicTrackingState.stateChangeCallbacks
- ).length;
-
- await click(".header-sidebar-toggle .btn");
- await click(".header-sidebar-toggle .btn");
-
- assert.strictEqual(
- Object.keys(topicTrackingState.stateChangeCallbacks).length,
- initialCallbackCount
- );
- }
- );
-
- conditionalTest(
- "updating tags notification levels",
- !isLegacyEmber(),
- async function (assert) {
- await visit(`/tag/tag1/l/unread`);
-
- const notificationLevelsDropdown = selectKit(".notifications-button");
-
- await notificationLevelsDropdown.expand();
-
- await notificationLevelsDropdown.selectRowByValue(
- NotificationLevels.REGULAR
- );
-
- assert.ok(
- !exists(".sidebar-section-tags .sidebar-section-link-tag1"),
- "tag1 section link is removed from sidebar"
- );
- }
- );
+ test("cleans up topic tracking state state changed callbacks when section is destroyed", async function (assert) {
+ await visit("/");
+
+ const topicTrackingState = this.container.lookup(
+ "topic-tracking-state:main"
+ );
+
+ const initialCallbackCount = Object.keys(
+ topicTrackingState.stateChangeCallbacks
+ ).length;
+
+ await click(".header-sidebar-toggle .btn");
+ await click(".header-sidebar-toggle .btn");
+
+ assert.strictEqual(
+ Object.keys(topicTrackingState.stateChangeCallbacks).length,
+ initialCallbackCount
+ );
+ });
+
+ test("updating tags notification levels", async function (assert) {
+ await visit(`/tag/tag1/l/unread`);
+
+ const notificationLevelsDropdown = selectKit(".notifications-button");
+
+ await notificationLevelsDropdown.expand();
+
+ await notificationLevelsDropdown.selectRowByValue(
+ NotificationLevels.REGULAR
+ );
+
+ assert.ok(
+ !exists(".sidebar-section-tags .sidebar-section-link-tag1"),
+ "tag1 section link is removed from sidebar"
+ );
+ });
});
diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-test.js
index c173b7e4d17..69424130d52 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-test.js
@@ -1,11 +1,7 @@
-import { click, visit } from "@ember/test-helpers";
-import {
- acceptance,
- conditionalTest,
- exists,
-} from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
-import { isLegacyEmber } from "discourse-common/config/environment";
+
+import { click, visit } from "@ember/test-helpers";
+import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
acceptance("Sidebar - Anon User", function () {
// Don't show sidebar for anon user until we know what we want to display
@@ -20,46 +16,38 @@ acceptance("Sidebar - Anon User", function () {
acceptance("Sidebar - User with sidebar disabled", function (needs) {
needs.user({ experimental_sidebar_enabled: false });
- conditionalTest(
- "sidebar is not displayed",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/");
+ test("sidebar is not displayed", async function (assert) {
+ await visit("/");
- assert.ok(!exists("#main-outlet-wrapper.has-sidebar"));
- assert.ok(!exists(".sidebar-wrapper"));
- }
- );
+ assert.ok(!exists("#main-outlet-wrapper.has-sidebar"));
+ assert.ok(!exists(".sidebar-wrapper"));
+ });
});
acceptance("Sidebar - User with sidebar enabled", function (needs) {
needs.user({ experimental_sidebar_enabled: true });
- conditionalTest(
- "hiding and displaying sidebar",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/");
+ test("hiding and displaying sidebar", async function (assert) {
+ await visit("/");
- assert.ok(
- exists("#main-outlet-wrapper.has-sidebar"),
- "adds sidebar utility class on main outlet wrapper"
- );
+ assert.ok(
+ exists("#main-outlet-wrapper.has-sidebar"),
+ "adds sidebar utility class on main outlet wrapper"
+ );
- assert.ok(exists(".sidebar-wrapper"), "displays the sidebar by default");
+ assert.ok(exists(".sidebar-wrapper"), "displays the sidebar by default");
- await click(".header-sidebar-toggle .btn");
+ await click(".header-sidebar-toggle .btn");
- assert.ok(
- !exists("#main-outlet-wrapper.has-sidebar"),
- "removes sidebar utility class from main outlet wrapper"
- );
+ assert.ok(
+ !exists("#main-outlet-wrapper.has-sidebar"),
+ "removes sidebar utility class from main outlet wrapper"
+ );
- assert.ok(!exists(".sidebar-wrapper"), "hides the sidebar");
+ assert.ok(!exists(".sidebar-wrapper"), "hides the sidebar");
- await click(".header-sidebar-toggle .btn");
+ await click(".header-sidebar-toggle .btn");
- assert.ok(exists(".sidebar-wrapper"), "displays the sidebar");
- }
- );
+ assert.ok(exists(".sidebar-wrapper"), "displays the sidebar");
+ });
});
diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-topics-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-topics-section-test.js
index 898faa49bcb..5f04e100d6c 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-topics-section-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-topics-section-test.js
@@ -1,15 +1,15 @@
+import { test } from "qunit";
+
import { click, currentURL, settled, visit } from "@ember/test-helpers";
import {
acceptance,
- conditionalTest,
exists,
loggedInUser,
publishToMessageBus,
query,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
-import { isLegacyEmber } from "discourse-common/config/environment";
import topicFixtures from "discourse/tests/fixtures/discovery-fixtures";
import { cloneJSON } from "discourse-common/lib/object";
import { withPluginApi } from "discourse/lib/plugin-api";
@@ -38,799 +38,703 @@ acceptance("Sidebar - Topics Section", function (needs) {
});
});
- conditionalTest(
- "clicking on section header button",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/");
- await click(".sidebar-section-topics .sidebar-section-header-button");
-
- assert.ok(exists("#reply-control"), "it opens the composer");
- }
- );
-
- conditionalTest(
- "clicking on section header button while viewing a category",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/c/bug");
- await click(".sidebar-section-topics .sidebar-section-header-button");
-
- assert.ok(exists("#reply-control"), "it opens the composer");
-
- assert.strictEqual(
- query(".category-input .selected-name .category-name").textContent,
- "bug",
- "the current category is prefilled in the composer input"
- );
- }
- );
-
- conditionalTest(
- "clicking on section caret button",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/");
-
- assert.ok(
- exists(".sidebar-section-topics .sidebar-section-content"),
- "shows content section"
- );
-
- await click(".sidebar-section-topics .sidebar-section-header-caret");
-
- assert.ok(
- !exists(".sidebar-section-topics .sidebar-section-content"),
- "hides content section"
- );
-
- await click(".sidebar-section-topics .sidebar-section-header-caret");
-
- assert.ok(
- exists(".sidebar-section-topics .sidebar-section-content"),
- "shows content section"
- );
- }
- );
-
- conditionalTest(
- "clicking on section header link",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/t/280");
- await click(".sidebar-section-topics .sidebar-section-header-link");
-
- assert.strictEqual(
- currentURL(),
- "/latest",
- "it should transistion to the homepage"
- );
-
- assert.strictEqual(
- queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(
- ".sidebar-section-topics .sidebar-section-link-everything.active"
- ),
- "the everything link is marked as active"
- );
- }
- );
-
- conditionalTest(
- "clicking on everything link",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/t/280");
- await click(".sidebar-section-topics .sidebar-section-link-everything");
-
- assert.strictEqual(
- currentURL(),
- "/latest",
- "it should transistion to the latest page"
- );
-
- assert.strictEqual(
- queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(
- ".sidebar-section-topics .sidebar-section-link-everything.active"
- ),
- "the everything link is marked as active"
- );
- }
- );
-
- conditionalTest(
- "clicking on tracked link",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/t/280");
- await click(".sidebar-section-topics .sidebar-section-link-tracked");
-
- assert.strictEqual(
- currentURL(),
- "/latest?f=tracked",
- "it should transistion to the tracked url"
- );
-
- assert.strictEqual(
- queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(".sidebar-section-topics .sidebar-section-link-tracked.active"),
- "the tracked link is marked as active"
- );
- }
- );
-
- conditionalTest(
- "clicking on bookmarked link",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/t/280");
- await click(".sidebar-section-topics .sidebar-section-link-bookmarked");
-
- assert.strictEqual(
- currentURL(),
- `/u/${loggedInUser().username}/activity/bookmarks`,
- "it should transistion to the bookmarked url"
- );
-
- assert.strictEqual(
- queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(
- ".sidebar-section-topics .sidebar-section-link-bookmarked.active"
- ),
- "the bookmarked link is marked as active"
- );
- }
- );
-
- conditionalTest(
- "clicking on my posts link",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/t/280");
- await click(".sidebar-section-topics .sidebar-section-link-my-posts");
-
- assert.strictEqual(
- currentURL(),
- `/u/${loggedInUser().username}/activity`,
- "it should transistion to the user's activity url"
- );
-
- assert.strictEqual(
- queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(".sidebar-section-topics .sidebar-section-link-my-posts.active"),
- "the my posts link is marked as active"
- );
-
- await visit(`/u/${loggedInUser().username}/activity/drafts`);
-
- assert.notOk(
- exists(".sidebar-section-topics .sidebar-section-link-my-posts.active"),
- "the my posts link is not marked as active when user has no drafts and visiting the user activity drafts URL"
- );
- }
- );
-
- conditionalTest(
- "clicking on my posts link when user has a draft",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/t/280");
-
- publishToMessageBus(`/user-drafts/${loggedInUser().id}`, {
- draft_count: 1,
- });
+ test("clicking on section header button", async function (assert) {
+ await visit("/");
+ await click(".sidebar-section-topics .sidebar-section-header-button");
- await settled();
-
- await click(".sidebar-section-topics .sidebar-section-link-my-posts");
-
- assert.strictEqual(
- currentURL(),
- `/u/${loggedInUser().username}/activity/drafts`,
- "it transistions to the user's activity drafts url"
- );
-
- assert.strictEqual(
- queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(".sidebar-section-topics .sidebar-section-link-my-posts.active"),
- "the my posts link is marked as active"
- );
-
- await visit(`/u/${loggedInUser().username}/activity`);
-
- assert.ok(
- exists(".sidebar-section-topics .sidebar-section-link-my-posts.active"),
- "the my posts link is marked as active"
- );
- }
- );
-
- conditionalTest(
- "visiting top route",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/top");
-
- assert.strictEqual(
- queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(
- ".sidebar-section-topics .sidebar-section-link-everything.active"
- ),
- "the everything link is marked as active"
- );
- }
- );
-
- conditionalTest(
- "visiting unread route",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/unread");
-
- assert.strictEqual(
- queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(
- ".sidebar-section-topics .sidebar-section-link-everything.active"
- ),
- "the everything link is marked as active"
- );
- }
- );
-
- conditionalTest(
- "visiting new route",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/new");
-
- assert.strictEqual(
- queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(
- ".sidebar-section-topics .sidebar-section-link-everything.active"
- ),
- "the everything link is marked as active"
- );
- }
- );
-
- conditionalTest(
- "new and unread count for everything link",
- !isLegacyEmber(),
- async function (assert) {
- this.container.lookup("topic-tracking-state:main").loadStates([
- {
- topic_id: 1,
- highest_post_number: 1,
- last_read_post_number: null,
- created_at: "2022-05-11T03:09:31.959Z",
- category_id: 1,
- notification_level: null,
- created_in_new_period: true,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- },
- {
- topic_id: 2,
- highest_post_number: 12,
- last_read_post_number: 11,
- created_at: "2020-02-09T09:40:02.672Z",
- category_id: 2,
- notification_level: 2,
- created_in_new_period: false,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- },
- {
- topic_id: 3,
- highest_post_number: 15,
- last_read_post_number: 14,
- created_at: "2021-06-14T12:41:02.477Z",
- category_id: 3,
- notification_level: 2,
- created_in_new_period: false,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- },
- {
- topic_id: 4,
- highest_post_number: 17,
- last_read_post_number: 16,
- created_at: "2020-10-31T03:41:42.257Z",
- category_id: 4,
- notification_level: 2,
- created_in_new_period: false,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- },
- ]);
-
- await visit("/");
-
- assert.strictEqual(
- query(
- ".sidebar-section-link-everything .sidebar-section-link-content-badge"
- ).textContent.trim(),
- "3 unread",
- "it displays the right unread count"
- );
-
- assert.ok(
- query(".sidebar-section-link-everything").href.endsWith("/unread"),
- "it links to unread filter"
- );
-
- // simulate reading topic 2
- publishToMessageBus("/unread", {
- topic_id: 2,
- message_type: "read",
- payload: {
- last_read_post_number: 12,
- highest_post_number: 12,
- notification_level: 2,
- },
- });
+ assert.ok(exists("#reply-control"), "it opens the composer");
+ });
- await settled();
+ test("clicking on section header button while viewing a category", async function (assert) {
+ await visit("/c/bug");
+ await click(".sidebar-section-topics .sidebar-section-header-button");
- assert.strictEqual(
- query(
- ".sidebar-section-link-everything .sidebar-section-link-content-badge"
- ).textContent.trim(),
- "2 unread",
- "it updates the unread count"
- );
+ assert.ok(exists("#reply-control"), "it opens the composer");
- // simulate reading topic 3
- publishToMessageBus("/unread", {
- topic_id: 3,
- message_type: "read",
- payload: {
- last_read_post_number: 15,
- highest_post_number: 15,
- notification_level: 2,
- },
- });
+ assert.strictEqual(
+ query(".category-input .selected-name .category-name").textContent,
+ "bug",
+ "the current category is prefilled in the composer input"
+ );
+ });
- // simulate reading topic 4
- publishToMessageBus("/unread", {
- topic_id: 4,
- message_type: "read",
- payload: {
- last_read_post_number: 17,
- highest_post_number: 17,
- notification_level: 2,
- },
- });
+ test("clicking on section caret button", async function (assert) {
+ await visit("/");
- await settled();
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-content"),
+ "shows content section"
+ );
- assert.strictEqual(
- query(
- ".sidebar-section-link-everything .sidebar-section-link-content-badge"
- ).textContent.trim(),
- "1 new",
- "it displays the new count once there are no unread topics"
- );
+ await click(".sidebar-section-topics .sidebar-section-header-caret");
- assert.ok(
- query(".sidebar-section-link-everything").href.endsWith("/new"),
- "it links to new filter"
- );
+ assert.ok(
+ !exists(".sidebar-section-topics .sidebar-section-content"),
+ "hides content section"
+ );
- publishToMessageBus("/unread", {
- topic_id: 1,
- message_type: "read",
- payload: {
- last_read_post_number: 1,
- highest_post_number: 1,
- notification_level: 2,
- },
- });
+ await click(".sidebar-section-topics .sidebar-section-header-caret");
- await settled();
-
- assert.ok(
- !exists(
- ".sidebar-section-link-everything .sidebar-section-link-content-badge"
- ),
- "it removes new count once there are no new topics"
- );
-
- assert.ok(
- query(".sidebar-section-link-everything").href.endsWith("/latest"),
- "it links to latest filter"
- );
- }
- );
-
- conditionalTest(
- "visiting top route with tracked filter",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/top?f=tracked");
-
- assert.strictEqual(
- queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(".sidebar-section-topics .sidebar-section-link-tracked.active"),
- "the tracked link is marked as active"
- );
- }
- );
-
- conditionalTest(
- "visiting unread route with tracked filter",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/unread?f=tracked");
-
- assert.strictEqual(
- queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(".sidebar-section-topics .sidebar-section-link-tracked.active"),
- "the tracked link is marked as active"
- );
- }
- );
-
- conditionalTest(
- "visiting new route with tracked filter",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/new?f=tracked");
-
- assert.strictEqual(
- queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
- 1,
- "only one link is marked as active"
- );
-
- assert.ok(
- exists(".sidebar-section-topics .sidebar-section-link-tracked.active"),
- "the tracked link is marked as active"
- );
- }
- );
-
- conditionalTest(
- "new and unread count for tracked link",
- !isLegacyEmber(),
- async function (assert) {
- const categories = Site.current().categories;
-
- // Category id 1001 has two subcategories
- const category = categories.find((c) => c.id === 1001);
- category.set("notification_level", NotificationLevels.TRACKING);
-
- this.container.lookup("topic-tracking-state:main").loadStates([
- {
- topic_id: 1,
- highest_post_number: 1,
- last_read_post_number: null,
- created_at: "2022-05-11T03:09:31.959Z",
- category_id: category.id,
- notification_level: NotificationLevels.TRACKING,
- created_in_new_period: true,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- },
- {
- topic_id: 2,
- highest_post_number: 12,
- last_read_post_number: 11,
- created_at: "2020-02-09T09:40:02.672Z",
- category_id: category.subcategories[0].id,
- notification_level: NotificationLevels.TRACKING,
- created_in_new_period: false,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- },
- {
- topic_id: 3,
- highest_post_number: 12,
- last_read_post_number: 11,
- created_at: "2020-02-09T09:40:02.672Z",
- category_id: category.subcategories[0].subcategories[0].id,
- notification_level: NotificationLevels.TRACKING,
- created_in_new_period: false,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- },
- {
- topic_id: 4,
- highest_post_number: 15,
- last_read_post_number: 14,
- created_at: "2021-06-14T12:41:02.477Z",
- category_id: 3,
- notification_level: NotificationLevels.TRACKING,
- created_in_new_period: false,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- },
- {
- topic_id: 5,
- highest_post_number: 1,
- last_read_post_number: null,
- created_at: "2021-06-14T12:41:02.477Z",
- category_id: 3,
- notification_level: null,
- created_in_new_period: true,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- },
- {
- topic_id: 6,
- highest_post_number: 17,
- last_read_post_number: 16,
- created_at: "2020-10-31T03:41:42.257Z",
- category_id: 1234,
- notification_level: NotificationLevels.TRACKING,
- created_in_new_period: false,
- unread_not_too_old: true,
- treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
- tags: ["tag3"],
- },
- ]);
-
- await visit("/");
-
- assert.strictEqual(
- query(
- ".sidebar-section-link-tracked .sidebar-section-link-content-badge"
- ).textContent.trim(),
- "3 unread",
- "it displays the right unread count"
- );
-
- assert.ok(
- query(".sidebar-section-link-tracked").href.endsWith(
- "/unread?f=tracked"
- ),
- "it links to unread url with tracked filter"
- );
-
- // simulate reading topic id 2
- publishToMessageBus("/unread", {
- topic_id: 2,
- message_type: "read",
- payload: {
- last_read_post_number: 12,
- highest_post_number: 12,
- },
- });
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-content"),
+ "shows content section"
+ );
+ });
+
+ test("clicking on section header link", async function (assert) {
+ await visit("/t/280");
+ await click(".sidebar-section-topics .sidebar-section-header-link");
+
+ assert.strictEqual(
+ currentURL(),
+ "/latest",
+ "it should transistion to the homepage"
+ );
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-link-everything.active"),
+ "the everything link is marked as active"
+ );
+ });
+
+ test("clicking on everything link", async function (assert) {
+ await visit("/t/280");
+ await click(".sidebar-section-topics .sidebar-section-link-everything");
+
+ assert.strictEqual(
+ currentURL(),
+ "/latest",
+ "it should transistion to the latest page"
+ );
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-link-everything.active"),
+ "the everything link is marked as active"
+ );
+ });
+
+ test("clicking on tracked link", async function (assert) {
+ await visit("/t/280");
+ await click(".sidebar-section-topics .sidebar-section-link-tracked");
+
+ assert.strictEqual(
+ currentURL(),
+ "/latest?f=tracked",
+ "it should transistion to the tracked url"
+ );
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-link-tracked.active"),
+ "the tracked link is marked as active"
+ );
+ });
+
+ test("clicking on bookmarked link", async function (assert) {
+ await visit("/t/280");
+ await click(".sidebar-section-topics .sidebar-section-link-bookmarked");
+
+ assert.strictEqual(
+ currentURL(),
+ `/u/${loggedInUser().username}/activity/bookmarks`,
+ "it should transistion to the bookmarked url"
+ );
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-link-bookmarked.active"),
+ "the bookmarked link is marked as active"
+ );
+ });
+
+ test("clicking on my posts link", async function (assert) {
+ await visit("/t/280");
+ await click(".sidebar-section-topics .sidebar-section-link-my-posts");
+
+ assert.strictEqual(
+ currentURL(),
+ `/u/${loggedInUser().username}/activity`,
+ "it should transistion to the user's activity url"
+ );
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-link-my-posts.active"),
+ "the my posts link is marked as active"
+ );
+
+ await visit(`/u/${loggedInUser().username}/activity/drafts`);
+
+ assert.notOk(
+ exists(".sidebar-section-topics .sidebar-section-link-my-posts.active"),
+ "the my posts link is not marked as active when user has no drafts and visiting the user activity drafts URL"
+ );
+ });
+
+ test("clicking on my posts link when user has a draft", async function (assert) {
+ await visit("/t/280");
+
+ publishToMessageBus(`/user-drafts/${loggedInUser().id}`, {
+ draft_count: 1,
+ });
+
+ await settled();
+
+ await click(".sidebar-section-topics .sidebar-section-link-my-posts");
+
+ assert.strictEqual(
+ currentURL(),
+ `/u/${loggedInUser().username}/activity/drafts`,
+ "it transistions to the user's activity drafts url"
+ );
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-link-my-posts.active"),
+ "the my posts link is marked as active"
+ );
+
+ await visit(`/u/${loggedInUser().username}/activity`);
- await settled();
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-link-my-posts.active"),
+ "the my posts link is marked as active"
+ );
+ });
+
+ test("visiting top route", async function (assert) {
+ await visit("/top");
- assert.strictEqual(
- query(
- ".sidebar-section-link-tracked .sidebar-section-link-content-badge"
- ).textContent.trim(),
- "2 unread",
- "it updates the unread count"
- );
+ assert.strictEqual(
+ queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-link-everything.active"),
+ "the everything link is marked as active"
+ );
+ });
- // simulate reading topic id 3
- publishToMessageBus("/unread", {
+ test("visiting unread route", async function (assert) {
+ await visit("/unread");
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-link-everything.active"),
+ "the everything link is marked as active"
+ );
+ });
+
+ test("visiting new route", async function (assert) {
+ await visit("/new");
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-link-everything.active"),
+ "the everything link is marked as active"
+ );
+ });
+
+ test("new and unread count for everything link", async function (assert) {
+ this.container.lookup("topic-tracking-state:main").loadStates([
+ {
+ topic_id: 1,
+ highest_post_number: 1,
+ last_read_post_number: null,
+ created_at: "2022-05-11T03:09:31.959Z",
+ category_id: 1,
+ notification_level: null,
+ created_in_new_period: true,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ },
+ {
+ topic_id: 2,
+ highest_post_number: 12,
+ last_read_post_number: 11,
+ created_at: "2020-02-09T09:40:02.672Z",
+ category_id: 2,
+ notification_level: 2,
+ created_in_new_period: false,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ },
+ {
topic_id: 3,
- message_type: "read",
- payload: {
- last_read_post_number: 17,
- highest_post_number: 17,
- },
- });
+ highest_post_number: 15,
+ last_read_post_number: 14,
+ created_at: "2021-06-14T12:41:02.477Z",
+ category_id: 3,
+ notification_level: 2,
+ created_in_new_period: false,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ },
+ {
+ topic_id: 4,
+ highest_post_number: 17,
+ last_read_post_number: 16,
+ created_at: "2020-10-31T03:41:42.257Z",
+ category_id: 4,
+ notification_level: 2,
+ created_in_new_period: false,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ },
+ ]);
+
+ await visit("/");
+
+ assert.strictEqual(
+ query(
+ ".sidebar-section-link-everything .sidebar-section-link-content-badge"
+ ).textContent.trim(),
+ "3 unread",
+ "it displays the right unread count"
+ );
+
+ assert.ok(
+ query(".sidebar-section-link-everything").href.endsWith("/unread"),
+ "it links to unread filter"
+ );
+
+ // simulate reading topic 2
+ publishToMessageBus("/unread", {
+ topic_id: 2,
+ message_type: "read",
+ payload: {
+ last_read_post_number: 12,
+ highest_post_number: 12,
+ notification_level: 2,
+ },
+ });
- // simulate reading topic id 6
- publishToMessageBus("/unread", {
- topic_id: 6,
- message_type: "read",
- payload: {
- last_read_post_number: 17,
- highest_post_number: 17,
- },
- });
+ await settled();
+
+ assert.strictEqual(
+ query(
+ ".sidebar-section-link-everything .sidebar-section-link-content-badge"
+ ).textContent.trim(),
+ "2 unread",
+ "it updates the unread count"
+ );
+
+ // simulate reading topic 3
+ publishToMessageBus("/unread", {
+ topic_id: 3,
+ message_type: "read",
+ payload: {
+ last_read_post_number: 15,
+ highest_post_number: 15,
+ notification_level: 2,
+ },
+ });
- assert.strictEqual(
- query(
- ".sidebar-section-link-tracked .sidebar-section-link-content-badge"
- ).textContent.trim(),
- "1 new",
- "it displays the new count once there are no tracked unread topics"
- );
-
- assert.ok(
- query(".sidebar-section-link-tracked").href.endsWith("/new?f=tracked"),
- "it links to new url with tracked filter"
- );
-
- // simulate reading topic id 1
- publishToMessageBus("/unread", {
+ // simulate reading topic 4
+ publishToMessageBus("/unread", {
+ topic_id: 4,
+ message_type: "read",
+ payload: {
+ last_read_post_number: 17,
+ highest_post_number: 17,
+ notification_level: 2,
+ },
+ });
+
+ await settled();
+
+ assert.strictEqual(
+ query(
+ ".sidebar-section-link-everything .sidebar-section-link-content-badge"
+ ).textContent.trim(),
+ "1 new",
+ "it displays the new count once there are no unread topics"
+ );
+
+ assert.ok(
+ query(".sidebar-section-link-everything").href.endsWith("/new"),
+ "it links to new filter"
+ );
+
+ publishToMessageBus("/unread", {
+ topic_id: 1,
+ message_type: "read",
+ payload: {
+ last_read_post_number: 1,
+ highest_post_number: 1,
+ notification_level: 2,
+ },
+ });
+
+ await settled();
+
+ assert.ok(
+ !exists(
+ ".sidebar-section-link-everything .sidebar-section-link-content-badge"
+ ),
+ "it removes new count once there are no new topics"
+ );
+
+ assert.ok(
+ query(".sidebar-section-link-everything").href.endsWith("/latest"),
+ "it links to latest filter"
+ );
+ });
+
+ test("visiting top route with tracked filter", async function (assert) {
+ await visit("/top?f=tracked");
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-link-tracked.active"),
+ "the tracked link is marked as active"
+ );
+ });
+
+ test("visiting unread route with tracked filter", async function (assert) {
+ await visit("/unread?f=tracked");
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-link-tracked.active"),
+ "the tracked link is marked as active"
+ );
+ });
+
+ test("visiting new route with tracked filter", async function (assert) {
+ await visit("/new?f=tracked");
+
+ assert.strictEqual(
+ queryAll(".sidebar-section-topics .sidebar-section-link.active").length,
+ 1,
+ "only one link is marked as active"
+ );
+
+ assert.ok(
+ exists(".sidebar-section-topics .sidebar-section-link-tracked.active"),
+ "the tracked link is marked as active"
+ );
+ });
+
+ test("new and unread count for tracked link", async function (assert) {
+ const categories = Site.current().categories;
+
+ // Category id 1001 has two subcategories
+ const category = categories.find((c) => c.id === 1001);
+ category.set("notification_level", NotificationLevels.TRACKING);
+
+ this.container.lookup("topic-tracking-state:main").loadStates([
+ {
topic_id: 1,
- message_type: "read",
- payload: {
- last_read_post_number: 1,
- highest_post_number: 1,
- },
- });
+ highest_post_number: 1,
+ last_read_post_number: null,
+ created_at: "2022-05-11T03:09:31.959Z",
+ category_id: category.id,
+ notification_level: NotificationLevels.TRACKING,
+ created_in_new_period: true,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ },
+ {
+ topic_id: 2,
+ highest_post_number: 12,
+ last_read_post_number: 11,
+ created_at: "2020-02-09T09:40:02.672Z",
+ category_id: category.subcategories[0].id,
+ notification_level: NotificationLevels.TRACKING,
+ created_in_new_period: false,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ },
+ {
+ topic_id: 3,
+ highest_post_number: 12,
+ last_read_post_number: 11,
+ created_at: "2020-02-09T09:40:02.672Z",
+ category_id: category.subcategories[0].subcategories[0].id,
+ notification_level: NotificationLevels.TRACKING,
+ created_in_new_period: false,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ },
+ {
+ topic_id: 4,
+ highest_post_number: 15,
+ last_read_post_number: 14,
+ created_at: "2021-06-14T12:41:02.477Z",
+ category_id: 3,
+ notification_level: NotificationLevels.TRACKING,
+ created_in_new_period: false,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ },
+ {
+ topic_id: 5,
+ highest_post_number: 1,
+ last_read_post_number: null,
+ created_at: "2021-06-14T12:41:02.477Z",
+ category_id: 3,
+ notification_level: null,
+ created_in_new_period: true,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ },
+ {
+ topic_id: 6,
+ highest_post_number: 17,
+ last_read_post_number: 16,
+ created_at: "2020-10-31T03:41:42.257Z",
+ category_id: 1234,
+ notification_level: NotificationLevels.TRACKING,
+ created_in_new_period: false,
+ unread_not_too_old: true,
+ treat_as_new_topic_start_date: "2022-05-09T03:17:34.286Z",
+ tags: ["tag3"],
+ },
+ ]);
+
+ await visit("/");
+
+ assert.strictEqual(
+ query(
+ ".sidebar-section-link-tracked .sidebar-section-link-content-badge"
+ ).textContent.trim(),
+ "3 unread",
+ "it displays the right unread count"
+ );
+
+ assert.ok(
+ query(".sidebar-section-link-tracked").href.endsWith("/unread?f=tracked"),
+ "it links to unread url with tracked filter"
+ );
+
+ // simulate reading topic id 2
+ publishToMessageBus("/unread", {
+ topic_id: 2,
+ message_type: "read",
+ payload: {
+ last_read_post_number: 12,
+ highest_post_number: 12,
+ },
+ });
+
+ await settled();
+
+ assert.strictEqual(
+ query(
+ ".sidebar-section-link-tracked .sidebar-section-link-content-badge"
+ ).textContent.trim(),
+ "2 unread",
+ "it updates the unread count"
+ );
+
+ // simulate reading topic id 3
+ publishToMessageBus("/unread", {
+ topic_id: 3,
+ message_type: "read",
+ payload: {
+ last_read_post_number: 17,
+ highest_post_number: 17,
+ },
+ });
+
+ // simulate reading topic id 6
+ publishToMessageBus("/unread", {
+ topic_id: 6,
+ message_type: "read",
+ payload: {
+ last_read_post_number: 17,
+ highest_post_number: 17,
+ },
+ });
+
+ assert.strictEqual(
+ query(
+ ".sidebar-section-link-tracked .sidebar-section-link-content-badge"
+ ).textContent.trim(),
+ "1 new",
+ "it displays the new count once there are no tracked unread topics"
+ );
+
+ assert.ok(
+ query(".sidebar-section-link-tracked").href.endsWith("/new?f=tracked"),
+ "it links to new url with tracked filter"
+ );
+
+ // simulate reading topic id 1
+ publishToMessageBus("/unread", {
+ topic_id: 1,
+ message_type: "read",
+ payload: {
+ last_read_post_number: 1,
+ highest_post_number: 1,
+ },
+ });
- await settled();
-
- assert.ok(
- !exists(
- ".sidebar-section-link-tracked .sidebar-section-link-content-badge"
- ),
- "it removes new count once there are no tracked new topics"
- );
-
- assert.ok(
- query(".sidebar-section-link-tracked").href.endsWith(
- "/latest?f=tracked"
- ),
- "it links to latest url with tracked filter"
- );
- }
- );
-
- conditionalTest(
- "adding section link via plugin API with Object",
- !isLegacyEmber(),
- async function (assert) {
- withPluginApi("1.2.0", (api) => {
- api.addTopicsSectionLink({
- name: "unread",
- route: "discovery.unread",
- text: "unread topics",
- title: "List of unread topics",
- });
+ await settled();
+
+ assert.ok(
+ !exists(
+ ".sidebar-section-link-tracked .sidebar-section-link-content-badge"
+ ),
+ "it removes new count once there are no tracked new topics"
+ );
+
+ assert.ok(
+ query(".sidebar-section-link-tracked").href.endsWith("/latest?f=tracked"),
+ "it links to latest url with tracked filter"
+ );
+ });
+
+ test("adding section link via plugin API with Object", async function (assert) {
+ withPluginApi("1.2.0", (api) => {
+ api.addTopicsSectionLink({
+ name: "unread",
+ route: "discovery.unread",
+ text: "unread topics",
+ title: "List of unread topics",
});
+ });
+
+ await visit("/");
- await visit("/");
-
- assert.strictEqual(
- query(".sidebar-section-link-unread").textContent.trim(),
- "unread topics",
- "displays the right text for the link"
- );
-
- assert.strictEqual(
- query(".sidebar-section-link-unread").title,
- "List of unread topics",
- "displays the right title for the link"
- );
-
- await click(".sidebar-section-link-unread");
-
- assert.strictEqual(currentURL(), "/unread", "links to the right URL");
- }
- );
-
- conditionalTest(
- "adding section link via plugin API with callback function",
- !isLegacyEmber(),
- async function (assert) {
- withPluginApi("1.2.0", (api) => {
- api.addTopicsSectionLink((baseSectionLink) => {
- return class CustomSectionLink extends baseSectionLink {
- get name() {
- return "user-summary";
- }
-
- get route() {
- return "user.summary";
- }
-
- get model() {
- return this.currentUser;
- }
-
- get title() {
- return `${this.currentUser.username} summary`;
- }
-
- get text() {
- return "my summary";
- }
- };
- });
+ assert.strictEqual(
+ query(".sidebar-section-link-unread").textContent.trim(),
+ "unread topics",
+ "displays the right text for the link"
+ );
+
+ assert.strictEqual(
+ query(".sidebar-section-link-unread").title,
+ "List of unread topics",
+ "displays the right title for the link"
+ );
+
+ await click(".sidebar-section-link-unread");
+
+ assert.strictEqual(currentURL(), "/unread", "links to the right URL");
+ });
+
+ test("adding section link via plugin API with callback function", async function (assert) {
+ withPluginApi("1.2.0", (api) => {
+ api.addTopicsSectionLink((baseSectionLink) => {
+ return class CustomSectionLink extends baseSectionLink {
+ get name() {
+ return "user-summary";
+ }
+
+ get route() {
+ return "user.summary";
+ }
+
+ get model() {
+ return this.currentUser;
+ }
+
+ get title() {
+ return `${this.currentUser.username} summary`;
+ }
+
+ get text() {
+ return "my summary";
+ }
+ };
});
+ });
- await visit("/");
- await click(".sidebar-section-link-user-summary");
-
- assert.strictEqual(
- currentURL(),
- "/u/eviltrout/summary",
- "links to the right URL"
- );
-
- assert.strictEqual(
- query(".sidebar-section-link-user-summary").textContent.trim(),
- "my summary",
- "displays the right text for the link"
- );
-
- assert.strictEqual(
- query(".sidebar-section-link-user-summary").title,
- "eviltrout summary",
- "displays the right title for the link"
- );
- }
- );
-
- conditionalTest(
- "clean up topic tracking state state changed callbacks when section is destroyed",
- !isLegacyEmber(),
- async function (assert) {
- await visit("/");
-
- const topicTrackingState = this.container.lookup(
- "topic-tracking-state:main"
- );
-
- const initialCallbackCount = Object.keys(
- topicTrackingState.stateChangeCallbacks
- ).length;
-
- await click(".header-sidebar-toggle .btn");
- await click(".header-sidebar-toggle .btn");
-
- assert.strictEqual(
- Object.keys(topicTrackingState.stateChangeCallbacks).length,
- initialCallbackCount
- );
- }
- );
+ await visit("/");
+ await click(".sidebar-section-link-user-summary");
+
+ assert.strictEqual(
+ currentURL(),
+ "/u/eviltrout/summary",
+ "links to the right URL"
+ );
+
+ assert.strictEqual(
+ query(".sidebar-section-link-user-summary").textContent.trim(),
+ "my summary",
+ "displays the right text for the link"
+ );
+
+ assert.strictEqual(
+ query(".sidebar-section-link-user-summary").title,
+ "eviltrout summary",
+ "displays the right title for the link"
+ );
+ });
+
+ test("clean up topic tracking state state changed callbacks when section is destroyed", async function (assert) {
+ await visit("/");
+
+ const topicTrackingState = this.container.lookup(
+ "topic-tracking-state:main"
+ );
+
+ const initialCallbackCount = Object.keys(
+ topicTrackingState.stateChangeCallbacks
+ ).length;
+
+ await click(".header-sidebar-toggle .btn");
+ await click(".header-sidebar-toggle .btn");
+
+ assert.strictEqual(
+ Object.keys(topicTrackingState.stateChangeCallbacks).length,
+ initialCallbackCount
+ );
+ });
});