completed logic and added tests for existing code and implemented code
This commit is contained in:
parent
730c9bd02e
commit
64fe74c318
|
@ -105,14 +105,6 @@ function avatarHtml(user, size, classes) {
|
|||
});
|
||||
}
|
||||
|
||||
// function nameOrUsername() {
|
||||
// if (this.siteSettings.prioritize_full_name_in_ux) {
|
||||
// topic.assigned_to_user?.name || topic.assigned_to_user?.username;
|
||||
// } else {
|
||||
// topic.assigned_to_user?.username;
|
||||
// }
|
||||
// }
|
||||
|
||||
function extractPostId(buttonId) {
|
||||
// buttonId format is "unassign-from-post-${postId}"
|
||||
const start = buttonId.lastIndexOf("-") + 1;
|
||||
|
|
|
@ -479,7 +479,13 @@ function initialize(api) {
|
|||
assignedPath = `/t/${topic.id}`;
|
||||
}
|
||||
const icon = iconHTML(assignee.username ? "user-plus" : "group-plus");
|
||||
const name = assignee.username || assignee.name;
|
||||
let name;
|
||||
if (siteSettings.prioritize_full_name_in_ux) {
|
||||
name = assignee.name;
|
||||
} else {
|
||||
name = assignee.username;
|
||||
}
|
||||
|
||||
const tagName = params.tagName || "a";
|
||||
const href =
|
||||
tagName === "a"
|
||||
|
@ -572,14 +578,19 @@ function initialize(api) {
|
|||
})
|
||||
)}</span>`;
|
||||
};
|
||||
|
||||
let displayedName = "";
|
||||
if (assignedToUser) {
|
||||
if (this.siteSettings.prioritize_full_name_in_ux) {
|
||||
displayedName = assignedToUser.name;
|
||||
} else {
|
||||
displayedName = assignedToUser.username;
|
||||
}
|
||||
assigneeElements.push(
|
||||
h(
|
||||
"span.assignee",
|
||||
new RawHtml({
|
||||
html: assignedHtml(
|
||||
assignedToUser.username,
|
||||
displayedName,
|
||||
assignedToUserPath(assignedToUser),
|
||||
"user"
|
||||
),
|
||||
|
@ -601,10 +612,18 @@ function initialize(api) {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (indirectlyAssignedTo) {
|
||||
Object.keys(indirectlyAssignedTo).map((postId) => {
|
||||
const assignee = indirectlyAssignedTo[postId].assigned_to;
|
||||
const postNumber = indirectlyAssignedTo[postId].post_number;
|
||||
|
||||
if (this.siteSettings.prioritize_full_name_in_ux) {
|
||||
displayedName = assignee.name;
|
||||
} else {
|
||||
displayedName = assignee.username;
|
||||
}
|
||||
|
||||
assigneeElements.push(
|
||||
h("span.assignee", [
|
||||
h(
|
||||
|
@ -617,14 +636,14 @@ function initialize(api) {
|
|||
},
|
||||
i18n("discourse_assign.assign_post_to_multiple", {
|
||||
post_number: postNumber,
|
||||
username: assignee.username || assignee.name,
|
||||
username: displayedName,
|
||||
})
|
||||
),
|
||||
])
|
||||
);
|
||||
});
|
||||
}
|
||||
console.log(assigneeElements);
|
||||
|
||||
if (!isEmpty(assigneeElements)) {
|
||||
return h("p.assigned-to", [
|
||||
assignedToUser ? iconNode("user-plus") : iconNode("group-plus"),
|
||||
|
|
|
@ -6,7 +6,6 @@ export class Assignment extends EmberObject {
|
|||
const assignment = new Assignment();
|
||||
assignment.id = 0;
|
||||
assignment.username = topic.assigned_to_user?.username;
|
||||
assignment.name = topic.assigned_to_user?.name;
|
||||
assignment.groupName = topic.assigned_to_group?.name;
|
||||
assignment.status = topic.assignment_status;
|
||||
assignment.note = topic.assignment_note;
|
||||
|
|
|
@ -0,0 +1,184 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe "Assign | Assigning posts", type: :system do
|
||||
let(:topic_page) { PageObjects::Pages::Topic.new }
|
||||
let(:assign_modal) { PageObjects::Modals::Assign.new }
|
||||
fab!(:staff_user) { Fabricate(:user, groups: [Group[:staff]]) }
|
||||
fab!(:admin)
|
||||
fab!(:topic)
|
||||
fab!(:post1) { Fabricate(:post, topic: topic) }
|
||||
fab!(:post2) { Fabricate(:post, topic: topic) }
|
||||
|
||||
before do
|
||||
SiteSetting.assign_enabled = true
|
||||
|
||||
# # The system tests in this file are flaky and auth token related so turning this on
|
||||
# SiteSetting.verbose_auth_token_logging = true
|
||||
|
||||
sign_in(admin)
|
||||
end
|
||||
|
||||
describe "with open topic" do
|
||||
before { SiteSetting.prioritize_full_name_in_ux = false }
|
||||
|
||||
it "can assign and unassign" do
|
||||
visit "/t/#{topic.id}"
|
||||
|
||||
topic_page.click_assign_post(post2)
|
||||
assign_modal.assignee = staff_user
|
||||
assign_modal.confirm
|
||||
|
||||
expect(assign_modal).to be_closed
|
||||
|
||||
expect(topic_page).to have_assigned_post(user: staff_user, at_post: 3)
|
||||
|
||||
expect(topic_page.find_post_assign(post1.post_number)).to have_content(staff_user.username)
|
||||
expect(topic_page.find_post_assign(post2.post_number)).to have_content(staff_user.username)
|
||||
|
||||
visit "/t/#{topic.id}"
|
||||
|
||||
topic_page.click_unassign_post(post2)
|
||||
|
||||
expect(topic_page).to have_unassigned_from_post(user: staff_user, at_post: 4)
|
||||
expect(page).to have_no_css("#topic .assigned-to")
|
||||
end
|
||||
|
||||
it "can submit form with shortcut from texatea" do
|
||||
visit "/t/#{topic.id}"
|
||||
|
||||
topic_page.click_assign_post(post2)
|
||||
assign_modal.assignee = staff_user
|
||||
|
||||
find("body").send_keys(:tab)
|
||||
find("body").send_keys(:control, :enter)
|
||||
|
||||
expect(assign_modal).to be_closed
|
||||
expect(topic_page).to have_assigned_post(user: staff_user, at_post: 3)
|
||||
expect(topic_page.find_post_assign(post1.post_number)).to have_content(staff_user.username)
|
||||
expect(topic_page.find_post_assign(post2.post_number)).to have_content(staff_user.username)
|
||||
end
|
||||
|
||||
context "when prioritize_full_name_in_ux setting is enabled" do
|
||||
before { SiteSetting.prioritize_full_name_in_ux = true }
|
||||
|
||||
it "shows the user's name after assign" do
|
||||
visit "/t/#{topic.id}"
|
||||
|
||||
topic_page.click_assign_post(post2)
|
||||
assign_modal.assignee = staff_user
|
||||
assign_modal.confirm
|
||||
expect(topic_page.find_post_assign(post1.post_number)).to have_content(staff_user.name)
|
||||
expect(topic_page.find_post_assign(post2.post_number)).to have_content(staff_user.name)
|
||||
end
|
||||
end
|
||||
|
||||
context "when assigns are not public" do
|
||||
before { SiteSetting.assigns_public = false }
|
||||
|
||||
it "assigned small action post has 'private-assign' in class attribute" do
|
||||
visit "/t/#{topic.id}"
|
||||
|
||||
topic_page.click_assign_post(post2)
|
||||
assign_modal.assignee = staff_user
|
||||
assign_modal.confirm
|
||||
|
||||
expect(assign_modal).to be_closed
|
||||
expect(topic_page).to have_assigned_post(
|
||||
user: staff_user,
|
||||
at_post: 3,
|
||||
class_attribute: ".private-assign",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "when unassign_on_close is set to true" do
|
||||
before { SiteSetting.unassign_on_close = true }
|
||||
|
||||
it "unassigns the topic on close" do
|
||||
visit "/t/#{topic.id}"
|
||||
|
||||
topic_page.click_assign_post(post2)
|
||||
assign_modal.assignee = staff_user
|
||||
assign_modal.confirm
|
||||
|
||||
expect(assign_modal).to be_closed
|
||||
expect(topic_page).to have_assigned_post(user: staff_user, at_post: 3)
|
||||
|
||||
find(".timeline-controls .toggle-admin-menu").click
|
||||
find(".topic-admin-close").click
|
||||
|
||||
expect(find("#post_4")).to have_content(
|
||||
I18n.t("js.action_codes.closed.enabled", when: "just now"),
|
||||
)
|
||||
expect(page).to have_no_css("#post_5")
|
||||
expect(page).to have_no_css("#topic .assigned-to")
|
||||
end
|
||||
|
||||
it "can assign the previous assignee" do
|
||||
visit "/t/#{topic.id}"
|
||||
|
||||
topic_page.click_assign_post(post2)
|
||||
assign_modal.assignee = staff_user
|
||||
assign_modal.confirm
|
||||
|
||||
expect(assign_modal).to be_closed
|
||||
expect(topic_page).to have_assigned_post(user: staff_user, at_post: 3)
|
||||
|
||||
find(".timeline-controls .toggle-admin-menu").click
|
||||
find(".topic-admin-close").click
|
||||
|
||||
expect(find("#post_4")).to have_content(
|
||||
I18n.t("js.action_codes.closed.enabled", when: "just now"),
|
||||
)
|
||||
expect(page).to have_no_css("#post_5")
|
||||
expect(page).to have_no_css("#topic .assigned-to")
|
||||
|
||||
topic_page.click_assign_post(post2)
|
||||
assign_modal.assignee = staff_user
|
||||
assign_modal.confirm
|
||||
|
||||
expect(page).to have_no_css("#post_5")
|
||||
expect(topic_page.find_post_assign(post1.post_number)).to have_content(staff_user.username)
|
||||
expect(topic_page.find_post_assign(post2.post_number)).to have_content(staff_user.username)
|
||||
end
|
||||
|
||||
context "when reassign_on_open is set to true" do
|
||||
before { SiteSetting.reassign_on_open = true }
|
||||
|
||||
it "reassigns the topic on open" do
|
||||
visit "/t/#{topic.id}"
|
||||
|
||||
topic_page.click_assign_post(post2)
|
||||
assign_modal.assignee = staff_user
|
||||
assign_modal.confirm
|
||||
|
||||
expect(assign_modal).to be_closed
|
||||
expect(topic_page).to have_assigned_post(user: staff_user, at_post: 3)
|
||||
|
||||
find(".timeline-controls .toggle-admin-menu").click
|
||||
find(".topic-admin-close").click
|
||||
|
||||
expect(find("#post_4")).to have_content(
|
||||
I18n.t("js.action_codes.closed.enabled", when: "just now"),
|
||||
)
|
||||
expect(page).to have_no_css("#post_5")
|
||||
expect(page).to have_no_css("#topic .assigned-to")
|
||||
|
||||
find(".timeline-controls .toggle-admin-menu").click
|
||||
find(".topic-admin-open").click
|
||||
|
||||
expect(find("#post_5")).to have_content(
|
||||
I18n.t("js.action_codes.closed.disabled", when: "just now"),
|
||||
)
|
||||
expect(page).to have_no_css("#post_6")
|
||||
expect(topic_page.find_post_assign(post1.post_number)).to have_content(
|
||||
staff_user.username,
|
||||
)
|
||||
expect(topic_page.find_post_assign(post2.post_number)).to have_content(
|
||||
staff_user.username,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -49,6 +49,19 @@ describe "Assign | Assigning topics", type: :system do
|
|||
expect(find("#topic .assigned-to")).to have_content(staff_user.username)
|
||||
end
|
||||
|
||||
context "when prioritize_full_name_in_ux setting is enabled" do
|
||||
before { SiteSetting.prioritize_full_name_in_ux = true }
|
||||
|
||||
it "shows the user's name after assign" do
|
||||
visit "/t/#{topic.id}"
|
||||
|
||||
topic_page.click_assign_topic
|
||||
assign_modal.assignee = staff_user
|
||||
assign_modal.confirm
|
||||
expect(find("#topic .assigned-to")).to have_content(staff_user.name)
|
||||
end
|
||||
end
|
||||
|
||||
context "when assigns are not public" do
|
||||
before { SiteSetting.assigns_public = false }
|
||||
|
||||
|
|
|
@ -12,28 +12,62 @@ module PageObjects
|
|||
find("[data-value='unassign']").click
|
||||
end
|
||||
|
||||
def click_unassign_post(post)
|
||||
find("#topic-footer-dropdown-reassign").click
|
||||
data_value = "unassign-from-post-#{post.id}"
|
||||
find("[data-value=\"#{data_value}\"]").click
|
||||
end
|
||||
|
||||
def click_assign_post(post)
|
||||
find_post_action_button(post, :show_more).click
|
||||
assign_post = within_post(post) { find(".post-action-menu__assign-post") }
|
||||
assign_post.click
|
||||
end
|
||||
|
||||
def click_edit_topic_assignment
|
||||
find("#topic-footer-dropdown-reassign").click
|
||||
find("[data-value='reassign']").click
|
||||
end
|
||||
|
||||
def find_post_assign(post_number)
|
||||
within("#post_#{post_number}") { find(".assigned-to") }
|
||||
end
|
||||
|
||||
def has_assigned?(args)
|
||||
has_assignment_action?(action: "assigned", **args)
|
||||
end
|
||||
|
||||
def has_assigned_post?(args)
|
||||
has_assignment_action?(action: "assigned_to_post", **args)
|
||||
end
|
||||
|
||||
def has_unassigned?(args)
|
||||
has_assignment_action?(action: "unassigned", **args)
|
||||
end
|
||||
|
||||
def has_unassigned_from_post?(args)
|
||||
has_assignment_action?(action: "unassigned_from_post", **args)
|
||||
end
|
||||
|
||||
def has_assignment_action?(args)
|
||||
assignee = args[:group]&.name || args[:user]&.username
|
||||
|
||||
container =
|
||||
args[:at_post] ? find("#post_#{args[:at_post]}#{args[:class_attribute] || ""}") : page
|
||||
|
||||
container.has_content?(
|
||||
I18n.t("js.action_codes.#{args[:action]}", who: "@#{assignee}", when: "just now"),
|
||||
post_content =
|
||||
I18n.t(
|
||||
"js.action_codes.#{args[:action]}",
|
||||
path: "",
|
||||
who: "@#{assignee}",
|
||||
when: "just now",
|
||||
)
|
||||
|
||||
if args[:action] == "assigned_to_post" || args[:action] == "unassigned_from_post"
|
||||
post_content.gsub!(%r{<a[^>]*>(.*?)</a>}, '\1')
|
||||
end
|
||||
|
||||
container.has_content?(post_content)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue