|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +describe "Assign | Assigning posts", type: :system do |
| 4 | + let(:topic_page) { PageObjects::Pages::Topic.new } |
| 5 | + let(:assign_modal) { PageObjects::Modals::Assign.new } |
| 6 | + fab!(:staff_user) { Fabricate(:user, groups: [Group[:staff]]) } |
| 7 | + fab!(:admin) |
| 8 | + fab!(:topic) |
| 9 | + fab!(:post1) { Fabricate(:post, topic: topic) } |
| 10 | + fab!(:post2) { Fabricate(:post, topic: topic) } |
| 11 | + |
| 12 | + before do |
| 13 | + SiteSetting.assign_enabled = true |
| 14 | + |
| 15 | + # # The system tests in this file are flaky and auth token related so turning this on |
| 16 | + # SiteSetting.verbose_auth_token_logging = true |
| 17 | + |
| 18 | + sign_in(admin) |
| 19 | + end |
| 20 | + |
| 21 | + describe "with open topic" do |
| 22 | + before { SiteSetting.prioritize_full_name_in_ux = false } |
| 23 | + |
| 24 | + it "can assign and unassign" do |
| 25 | + visit "/t/#{topic.id}" |
| 26 | + |
| 27 | + topic_page.click_assign_post(post2) |
| 28 | + assign_modal.assignee = staff_user |
| 29 | + assign_modal.confirm |
| 30 | + |
| 31 | + expect(assign_modal).to be_closed |
| 32 | + |
| 33 | + expect(topic_page).to have_assigned_post(user: staff_user, at_post: 3) |
| 34 | + |
| 35 | + expect(topic_page.find_post_assign(post1.post_number)).to have_content(staff_user.username) |
| 36 | + expect(topic_page.find_post_assign(post2.post_number)).to have_content(staff_user.username) |
| 37 | + |
| 38 | + visit "/t/#{topic.id}" |
| 39 | + |
| 40 | + topic_page.click_unassign_post(post2) |
| 41 | + |
| 42 | + expect(topic_page).to have_unassigned_from_post(user: staff_user, at_post: 4) |
| 43 | + expect(page).to have_no_css("#topic .assigned-to") |
| 44 | + end |
| 45 | + |
| 46 | + it "can submit form with shortcut from texatea" do |
| 47 | + visit "/t/#{topic.id}" |
| 48 | + |
| 49 | + topic_page.click_assign_post(post2) |
| 50 | + assign_modal.assignee = staff_user |
| 51 | + |
| 52 | + find("body").send_keys(:tab) |
| 53 | + find("body").send_keys(:control, :enter) |
| 54 | + |
| 55 | + expect(assign_modal).to be_closed |
| 56 | + expect(topic_page).to have_assigned_post(user: staff_user, at_post: 3) |
| 57 | + expect(topic_page.find_post_assign(post1.post_number)).to have_content(staff_user.username) |
| 58 | + expect(topic_page.find_post_assign(post2.post_number)).to have_content(staff_user.username) |
| 59 | + end |
| 60 | + |
| 61 | + context "when prioritize_full_name_in_ux setting is enabled" do |
| 62 | + before { SiteSetting.prioritize_full_name_in_ux = true } |
| 63 | + |
| 64 | + it "shows the user's name after assign" do |
| 65 | + visit "/t/#{topic.id}" |
| 66 | + |
| 67 | + topic_page.click_assign_post(post2) |
| 68 | + assign_modal.assignee = staff_user |
| 69 | + assign_modal.confirm |
| 70 | + expect(topic_page.find_post_assign(post1.post_number)).to have_content(staff_user.name) |
| 71 | + expect(topic_page.find_post_assign(post2.post_number)).to have_content(staff_user.name) |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + context "when assigns are not public" do |
| 76 | + before { SiteSetting.assigns_public = false } |
| 77 | + |
| 78 | + it "assigned small action post has 'private-assign' in class attribute" do |
| 79 | + visit "/t/#{topic.id}" |
| 80 | + |
| 81 | + topic_page.click_assign_post(post2) |
| 82 | + assign_modal.assignee = staff_user |
| 83 | + assign_modal.confirm |
| 84 | + |
| 85 | + expect(assign_modal).to be_closed |
| 86 | + expect(topic_page).to have_assigned_post( |
| 87 | + user: staff_user, |
| 88 | + at_post: 3, |
| 89 | + class_attribute: ".private-assign", |
| 90 | + ) |
| 91 | + end |
| 92 | + end |
| 93 | + |
| 94 | + context "when unassign_on_close is set to true" do |
| 95 | + before { SiteSetting.unassign_on_close = true } |
| 96 | + |
| 97 | + it "unassigns the topic on close" do |
| 98 | + visit "/t/#{topic.id}" |
| 99 | + |
| 100 | + topic_page.click_assign_post(post2) |
| 101 | + assign_modal.assignee = staff_user |
| 102 | + assign_modal.confirm |
| 103 | + |
| 104 | + expect(assign_modal).to be_closed |
| 105 | + expect(topic_page).to have_assigned_post(user: staff_user, at_post: 3) |
| 106 | + |
| 107 | + find(".timeline-controls .toggle-admin-menu").click |
| 108 | + find(".topic-admin-close").click |
| 109 | + |
| 110 | + expect(find("#post_4")).to have_content( |
| 111 | + I18n.t("js.action_codes.closed.enabled", when: "just now"), |
| 112 | + ) |
| 113 | + expect(page).to have_no_css("#post_5") |
| 114 | + expect(page).to have_no_css("#topic .assigned-to") |
| 115 | + end |
| 116 | + |
| 117 | + it "can assign the previous assignee" do |
| 118 | + visit "/t/#{topic.id}" |
| 119 | + |
| 120 | + topic_page.click_assign_post(post2) |
| 121 | + assign_modal.assignee = staff_user |
| 122 | + assign_modal.confirm |
| 123 | + |
| 124 | + expect(assign_modal).to be_closed |
| 125 | + expect(topic_page).to have_assigned_post(user: staff_user, at_post: 3) |
| 126 | + |
| 127 | + find(".timeline-controls .toggle-admin-menu").click |
| 128 | + find(".topic-admin-close").click |
| 129 | + |
| 130 | + expect(find("#post_4")).to have_content( |
| 131 | + I18n.t("js.action_codes.closed.enabled", when: "just now"), |
| 132 | + ) |
| 133 | + expect(page).to have_no_css("#post_5") |
| 134 | + expect(page).to have_no_css("#topic .assigned-to") |
| 135 | + |
| 136 | + topic_page.click_assign_post(post2) |
| 137 | + assign_modal.assignee = staff_user |
| 138 | + assign_modal.confirm |
| 139 | + |
| 140 | + expect(page).to have_no_css("#post_5") |
| 141 | + expect(topic_page.find_post_assign(post1.post_number)).to have_content(staff_user.username) |
| 142 | + expect(topic_page.find_post_assign(post2.post_number)).to have_content(staff_user.username) |
| 143 | + end |
| 144 | + |
| 145 | + context "when reassign_on_open is set to true" do |
| 146 | + before { SiteSetting.reassign_on_open = true } |
| 147 | + |
| 148 | + it "reassigns the topic on open" do |
| 149 | + visit "/t/#{topic.id}" |
| 150 | + |
| 151 | + topic_page.click_assign_post(post2) |
| 152 | + assign_modal.assignee = staff_user |
| 153 | + assign_modal.confirm |
| 154 | + |
| 155 | + expect(assign_modal).to be_closed |
| 156 | + expect(topic_page).to have_assigned_post(user: staff_user, at_post: 3) |
| 157 | + |
| 158 | + find(".timeline-controls .toggle-admin-menu").click |
| 159 | + find(".topic-admin-close").click |
| 160 | + |
| 161 | + expect(find("#post_4")).to have_content( |
| 162 | + I18n.t("js.action_codes.closed.enabled", when: "just now"), |
| 163 | + ) |
| 164 | + expect(page).to have_no_css("#post_5") |
| 165 | + expect(page).to have_no_css("#topic .assigned-to") |
| 166 | + |
| 167 | + find(".timeline-controls .toggle-admin-menu").click |
| 168 | + find(".topic-admin-open").click |
| 169 | + |
| 170 | + expect(find("#post_5")).to have_content( |
| 171 | + I18n.t("js.action_codes.closed.disabled", when: "just now"), |
| 172 | + ) |
| 173 | + expect(page).to have_no_css("#post_6") |
| 174 | + expect(topic_page.find_post_assign(post1.post_number)).to have_content( |
| 175 | + staff_user.username, |
| 176 | + ) |
| 177 | + expect(topic_page.find_post_assign(post2.post_number)).to have_content( |
| 178 | + staff_user.username, |
| 179 | + ) |
| 180 | + end |
| 181 | + end |
| 182 | + end |
| 183 | + end |
| 184 | +end |
0 commit comments