mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 17:02:45 +08:00
DEV: Remove ember legacy env conditional in sidebar tests (#17140)
This commit is contained in:
parent
222a7755a0
commit
ef5b504e9a
|
@ -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`
|
||||
);
|
||||
}
|
||||
);
|
||||
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();
|
||||
test("new and unread count for categories link", 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",
|
||||
},
|
||||
]);
|
||||
|
||||
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`
|
||||
);
|
||||
|
||||
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-${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", {
|
||||
this.container.lookup("topic-tracking-state:main").loadStates([
|
||||
{
|
||||
topic_id: 1,
|
||||
message_type: "read",
|
||||
payload: {
|
||||
last_read_post_number: 1,
|
||||
highest_post_number: 1,
|
||||
},
|
||||
});
|
||||
|
||||
await settled();
|
||||
|
||||
assert.ok(
|
||||
!exists(
|
||||
`.sidebar-section-link-${category1.slug} .sidebar-section-link-content-badge`
|
||||
),
|
||||
`does not display any badge ${category1.slug} section link`
|
||||
);
|
||||
|
||||
publishToMessageBus("/unread", {
|
||||
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,
|
||||
message_type: "read",
|
||||
payload: {
|
||||
last_read_post_number: 15,
|
||||
highest_post_number: 15,
|
||||
},
|
||||
});
|
||||
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 settled();
|
||||
await visit("/");
|
||||
|
||||
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-${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`
|
||||
);
|
||||
|
||||
conditionalTest(
|
||||
"clean up topic tracking state state changed callbacks when section is destroyed",
|
||||
!isLegacyEmber(),
|
||||
async function (assert) {
|
||||
setupTrackedCategories();
|
||||
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`
|
||||
);
|
||||
|
||||
await visit("/");
|
||||
publishToMessageBus("/unread", {
|
||||
topic_id: 2,
|
||||
message_type: "read",
|
||||
payload: {
|
||||
last_read_post_number: 12,
|
||||
highest_post_number: 12,
|
||||
},
|
||||
});
|
||||
|
||||
const topicTrackingState = this.container.lookup(
|
||||
"topic-tracking-state:main"
|
||||
);
|
||||
await settled();
|
||||
|
||||
const initialCallbackCount = Object.keys(
|
||||
topicTrackingState.stateChangeCallbacks
|
||||
).length;
|
||||
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`
|
||||
);
|
||||
|
||||
await click(".header-sidebar-toggle .btn");
|
||||
await click(".header-sidebar-toggle .btn");
|
||||
publishToMessageBus("/unread", {
|
||||
topic_id: 1,
|
||||
message_type: "read",
|
||||
payload: {
|
||||
last_read_post_number: 1,
|
||||
highest_post_number: 1,
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual(
|
||||
Object.keys(topicTrackingState.stateChangeCallbacks).length,
|
||||
initialCallbackCount
|
||||
);
|
||||
}
|
||||
);
|
||||
await settled();
|
||||
|
||||
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,
|
||||
},
|
||||
});
|
||||
|
||||
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`
|
||||
);
|
||||
});
|
||||
|
||||
test("clean up topic tracking state state changed callbacks when section is destroyed", async function (assert) {
|
||||
setupTrackedCategories();
|
||||
|
||||
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
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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,59 +65,87 @@ acceptance(
|
|||
});
|
||||
});
|
||||
|
||||
conditionalTest(
|
||||
"clicking on section header button",
|
||||
!isLegacyEmber(),
|
||||
async function (assert) {
|
||||
test("clicking on section header button", async function (assert) {
|
||||
await visit("/");
|
||||
|
||||
await click(".sidebar-section-messages .sidebar-section-header-button");
|
||||
|
||||
assert.ok(
|
||||
exists("#reply-control.private-message"),
|
||||
"it opens the composer"
|
||||
);
|
||||
});
|
||||
|
||||
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"
|
||||
);
|
||||
});
|
||||
|
||||
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"
|
||||
);
|
||||
|
||||
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("/");
|
||||
|
||||
await click(".sidebar-section-messages .sidebar-section-header-button");
|
||||
|
||||
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");
|
||||
|
||||
assert.strictEqual(
|
||||
currentURL(),
|
||||
`/u/eviltrout/messages`,
|
||||
"it should transistion to the user's messages"
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
conditionalTest(
|
||||
"personal messages section links",
|
||||
!isLegacyEmber(),
|
||||
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"
|
||||
);
|
||||
|
||||
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"
|
||||
|
@ -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("/");
|
||||
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 click(
|
||||
".sidebar-section-messages .sidebar-section-link-personal-messages-inbox"
|
||||
);
|
||||
await visit("/");
|
||||
|
||||
await click(
|
||||
`.sidebar-section-messages .sidebar-section-link-personal-messages-${type}`
|
||||
);
|
||||
assert.ok(
|
||||
exists(
|
||||
".sidebar-section-messages .sidebar-section-link-group-messages-inbox.group1"
|
||||
),
|
||||
"displays group1 inbox link"
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
currentURL(),
|
||||
`/u/eviltrout/messages/${type}`,
|
||||
`it should transition to user's ${type} personal messages`
|
||||
);
|
||||
assert.ok(
|
||||
exists(
|
||||
".sidebar-section-messages .sidebar-section-link-group-messages-inbox.group3"
|
||||
),
|
||||
"displays group3 inbox link"
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
queryAll(".sidebar-section-messages .sidebar-section-link.active")
|
||||
.length,
|
||||
2,
|
||||
"only two links are marked as active in the sidebar"
|
||||
);
|
||||
await visit("/u/eviltrout/messages/group/GrOuP1");
|
||||
|
||||
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,
|
||||
6,
|
||||
"expands and displays the links for group1 group messages"
|
||||
);
|
||||
|
||||
assert.ok(
|
||||
exists(
|
||||
`.sidebar-section-messages .sidebar-section-link-personal-messages-${type}.active`
|
||||
),
|
||||
`personal message ${type} link is marked as active`
|
||||
);
|
||||
}
|
||||
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"
|
||||
);
|
||||
|
||||
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.group1`
|
||||
);
|
||||
|
||||
await click(
|
||||
".sidebar-section-messages .sidebar-section-link-group-messages-inbox.group3"
|
||||
`.sidebar-section-messages .sidebar-section-link-group-messages-${type}.group1`
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
queryAll(".sidebar-section-messages .sidebar-section-link.group1")
|
||||
.length,
|
||||
1,
|
||||
"collapses 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.group3")
|
||||
queryAll(".sidebar-section-messages .sidebar-section-link.active")
|
||||
.length,
|
||||
4,
|
||||
"expands the links for group3 group messages"
|
||||
2,
|
||||
"only two links are marked as active in the sidebar"
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
["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,
|
||||
},
|
||||
],
|
||||
});
|
||||
assert.ok(
|
||||
exists(
|
||||
".sidebar-section-messages .sidebar-section-link-group-messages-inbox.group1.active"
|
||||
),
|
||||
"group1 group message inbox link is marked as active"
|
||||
);
|
||||
|
||||
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`
|
||||
);
|
||||
}
|
||||
);
|
||||
assert.ok(
|
||||
exists(
|
||||
`.sidebar-section-messages .sidebar-section-link-group-messages-${type}.group1.active`
|
||||
),
|
||||
`group1 group message ${type} link is marked as active`
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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("/");
|
||||
test("tags section is not shown", async function (assert) {
|
||||
await visit("/");
|
||||
|
||||
assert.ok(
|
||||
!exists(".sidebar-section-tags"),
|
||||
"does not display the tags section"
|
||||
);
|
||||
}
|
||||
);
|
||||
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");
|
||||
test("clicking on section header link", 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"
|
||||
);
|
||||
}
|
||||
);
|
||||
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("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 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"
|
||||
);
|
||||
}
|
||||
);
|
||||
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("/");
|
||||
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(
|
||||
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-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-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"
|
||||
);
|
||||
assert.strictEqual(
|
||||
query(".sidebar-section-link-tag3").textContent.trim(),
|
||||
"tag3",
|
||||
"displays the tag3 name for the link text"
|
||||
);
|
||||
|
||||
await click(".sidebar-section-link-tag1");
|
||||
await click(".sidebar-section-link-tag1");
|
||||
|
||||
assert.strictEqual(
|
||||
currentURL(),
|
||||
"/tag/tag1",
|
||||
"it should transition to tag1's topics discovery page"
|
||||
);
|
||||
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.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"
|
||||
);
|
||||
assert.ok(
|
||||
exists(`.sidebar-section-link-tag1.active`),
|
||||
"the tag1 section link is marked as active"
|
||||
);
|
||||
|
||||
await click(".sidebar-section-link-tag2");
|
||||
await click(".sidebar-section-link-tag2");
|
||||
|
||||
assert.strictEqual(
|
||||
currentURL(),
|
||||
"/tag/tag2",
|
||||
"it should transition to tag2's topics discovery page"
|
||||
);
|
||||
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.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"
|
||||
);
|
||||
}
|
||||
);
|
||||
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`);
|
||||
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.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"
|
||||
);
|
||||
}
|
||||
);
|
||||
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`);
|
||||
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.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.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`);
|
||||
test("visiting tag discovery unread route for tracked tags", 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.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"
|
||||
);
|
||||
}
|
||||
);
|
||||
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,
|
||||
},
|
||||
});
|
||||
|
||||
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", {
|
||||
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 settled();
|
||||
await visit("/");
|
||||
|
||||
assert.ok(
|
||||
!exists(
|
||||
`.sidebar-section-link-tag1 .sidebar-section-link-content-badge`
|
||||
),
|
||||
`does not display any badge tag1 section link`
|
||||
);
|
||||
}
|
||||
);
|
||||
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`
|
||||
);
|
||||
|
||||
conditionalTest(
|
||||
"cleans up topic tracking state state changed callbacks when section is destroyed",
|
||||
!isLegacyEmber(),
|
||||
async function (assert) {
|
||||
await visit("/");
|
||||
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`
|
||||
);
|
||||
|
||||
const topicTrackingState = this.container.lookup(
|
||||
"topic-tracking-state:main"
|
||||
);
|
||||
assert.ok(
|
||||
!exists(`.sidebar-section-link-tag3 .sidebar-section-link-content-badge`),
|
||||
"does not display any badge for tag3 section link"
|
||||
);
|
||||
|
||||
const initialCallbackCount = Object.keys(
|
||||
topicTrackingState.stateChangeCallbacks
|
||||
).length;
|
||||
publishToMessageBus("/unread", {
|
||||
topic_id: 2,
|
||||
message_type: "read",
|
||||
payload: {
|
||||
last_read_post_number: 12,
|
||||
highest_post_number: 12,
|
||||
},
|
||||
});
|
||||
|
||||
await click(".header-sidebar-toggle .btn");
|
||||
await click(".header-sidebar-toggle .btn");
|
||||
await settled();
|
||||
|
||||
assert.strictEqual(
|
||||
Object.keys(topicTrackingState.stateChangeCallbacks).length,
|
||||
initialCallbackCount
|
||||
);
|
||||
}
|
||||
);
|
||||
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`
|
||||
);
|
||||
|
||||
conditionalTest(
|
||||
"updating tags notification levels",
|
||||
!isLegacyEmber(),
|
||||
async function (assert) {
|
||||
await visit(`/tag/tag1/l/unread`);
|
||||
publishToMessageBus("/unread", {
|
||||
topic_id: 1,
|
||||
message_type: "read",
|
||||
payload: {
|
||||
last_read_post_number: 1,
|
||||
highest_post_number: 1,
|
||||
},
|
||||
});
|
||||
|
||||
const notificationLevelsDropdown = selectKit(".notifications-button");
|
||||
await settled();
|
||||
|
||||
await notificationLevelsDropdown.expand();
|
||||
assert.ok(
|
||||
!exists(`.sidebar-section-link-tag1 .sidebar-section-link-content-badge`),
|
||||
`does not display any badge tag1 section link`
|
||||
);
|
||||
});
|
||||
|
||||
await notificationLevelsDropdown.selectRowByValue(
|
||||
NotificationLevels.REGULAR
|
||||
);
|
||||
test("cleans up topic tracking state state changed callbacks when section is destroyed", async function (assert) {
|
||||
await visit("/");
|
||||
|
||||
assert.ok(
|
||||
!exists(".sidebar-section-tags .sidebar-section-link-tag1"),
|
||||
"tag1 section link is removed from sidebar"
|
||||
);
|
||||
}
|
||||
);
|
||||
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"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
});
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user