FEATURE: Register assigned link under sidebar topics section. (#341)

This commit is contained in:
Alan Guo Xiang Tan 2022-05-26 09:13:40 +08:00 committed by GitHub
parent 8d1aa65d5f
commit 959525b079
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,41 @@
import { withPluginApi } from "discourse/lib/plugin-api";
import I18n from "I18n";
export default {
name: "assign-sidebar",
initialize(container) {
withPluginApi("1.2.0", (api) => {
const currentUser = container.lookup("current-user:main");
if (
currentUser?.experimental_sidebar_enabled &&
currentUser?.can_assign
) {
api.addTopicsSectionLink((baseSectionLink) => {
return class AssignedSectionLink extends baseSectionLink {
get name() {
return "assigned";
}
get route() {
return "userActivity.assigned";
}
get model() {
return this.currentUser;
}
get title() {
return I18n.t("sidebar.assigned_link_title");
}
get text() {
return I18n.t("sidebar.assigned_link_text");
}
};
});
}
});
},
};

View File

@ -135,3 +135,6 @@ en:
assigned: "%{username} assigned you"
titles:
assigned: "Assigned"
sidebar:
assigned_link_title: "Topics assigned to you"
assigned_link_text: "Assigned"

View File

@ -0,0 +1,71 @@
import I18n from "I18n";
import { click, currentURL, visit } from "@ember/test-helpers";
import {
acceptance,
conditionalTest,
exists,
query,
} from "discourse/tests/helpers/qunit-helpers";
import { isLegacyEmber } from "discourse-common/config/environment";
import AssignedTopics from "../fixtures/assigned-topics-fixtures";
import { cloneJSON } from "discourse-common/lib/object";
acceptance(
"Discourse Assign | Sidebar when user cannot assign",
function (needs) {
needs.user({ experimental_sidebar_enabled: true, can_assign: false });
conditionalTest(
"assign sidebar link is hidden",
!isLegacyEmber(),
async function (assert) {
await visit("/");
assert.ok(
!exists(".sidebar-section-link-assigned"),
"it does not display the assign link in sidebar"
);
}
);
}
);
acceptance("Discourse Assign | Sidebar when user can assign", function (needs) {
needs.user({ experimental_sidebar_enabled: true, can_assign: true });
needs.pretender((server, helper) => {
const messagesPath = "/topics/messages-assigned/eviltrout.json";
const assigns = AssignedTopics[messagesPath];
server.get(messagesPath, () => helper.response(cloneJSON(assigns)));
});
conditionalTest(
"clicking on assign link",
!isLegacyEmber(),
async function (assert) {
await visit("/");
assert.strictEqual(
query(".sidebar-section-link-assigned").textContent.trim(),
I18n.t("sidebar.assigned_link_text"),
"displays the right text for the link"
);
assert.strictEqual(
query(".sidebar-section-link-assigned").title,
I18n.t("sidebar.assigned_link_title"),
"displays the right title for the link"
);
await click(".sidebar-section-link-assigned");
assert.strictEqual(
currentURL(),
"/u/eviltrout/activity/assigned",
"it navigates to the right page"
);
}
);
});