This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/integration/components/user-menu/reviewable-item-test.js
Osama Sayegh 4fdb275683
DEV: Add bookmarks tab to the new user menu (#17814)
Some of the changes in this commit are extracted from https://github.com/discourse/discourse/pull/17379.

The bookmarks tab in the new user menu is different from the other tabs in that it can display a mixture of notifications and bookmarks. When there are unread bookmark reminder notifications, the tab displays all of these notifications at the top and fills the remaining space in the menu with the rest of the bookmarks. The bubble/badge count on the bookmarks tab indicates how many unread bookmark reminder notifications there are.

On the technical aspect, since this commit introduces a new `bookmark-item` component, we've done some refactoring so that all 3 "item" components (`notification-item`, `reviewable-item` and the new `bookmark-item`) inherit from a base component and get identical HTML structure so they all look consistent.

Internal tickets: t70584 and t65045.
2022-08-08 17:24:04 +03:00

76 lines
2.4 KiB
JavaScript

import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { exists, query } from "discourse/tests/helpers/qunit-helpers";
import UserMenuReviewable from "discourse/models/user-menu-reviewable";
import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";
import I18n from "I18n";
function getReviewable(overrides = {}) {
return UserMenuReviewable.create(
Object.assign(
{
flagger_username: "sayo2",
id: 17,
pending: false,
post_number: 3,
topic_fancy_title: "anything hello world",
type: "Reviewable",
},
overrides
)
);
}
module(
"Integration | Component | user-menu | reviewable-item",
function (hooks) {
setupRenderingTest(hooks);
const template = hbs`<UserMenu::ReviewableItem @item={{this.item}}/>`;
test("doesn't push `reviewed` to the classList if the reviewable is pending", async function (assert) {
this.set("item", getReviewable({ pending: true }));
await render(template);
assert.ok(!exists("li.reviewed"));
assert.ok(exists("li"));
});
test("pushes `reviewed` to the classList if the reviewable isn't pending", async function (assert) {
this.set("item", getReviewable({ pending: false }));
await render(template);
assert.ok(exists("li.reviewed"));
});
test("has elements for label and description", async function (assert) {
this.set("item", getReviewable());
await render(template);
const label = query("li .item-label");
const description = query("li .item-description");
assert.strictEqual(
label.textContent.trim(),
"sayo2",
"the label is the flagger_username"
);
assert.strictEqual(
description.textContent.trim(),
I18n.t("user_menu.reviewable.default_item", {
reviewable_id: this.item.id,
}),
"displays the description for the reviewable"
);
});
test("the item's label is a placeholder that indicates deleted user if flagger_username is absent", async function (assert) {
this.set("item", getReviewable({ flagger_username: null }));
await render(template);
const label = query("li .item-label");
assert.strictEqual(
label.textContent.trim(),
I18n.t("user_menu.reviewable.deleted_user")
);
});
}
);