|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# -- copyright |
| 4 | +# OpenProject is an open source project management software. |
| 5 | +# Copyright (C) the OpenProject GmbH |
| 6 | +# |
| 7 | +# This program is free software; you can redistribute it and/or |
| 8 | +# modify it under the terms of the GNU General Public License version 3. |
| 9 | +# |
| 10 | +# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
| 11 | +# Copyright (C) 2006-2013 Jean-Philippe Lang |
| 12 | +# Copyright (C) 2010-2013 the ChiliProject Team |
| 13 | +# |
| 14 | +# This program is free software; you can redistribute it and/or |
| 15 | +# modify it under the terms of the GNU General Public License |
| 16 | +# as published by the Free Software Foundation; either version 2 |
| 17 | +# of the License, or (at your option) any later version. |
| 18 | +# |
| 19 | +# This program is distributed in the hope that it will be useful, |
| 20 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | +# GNU General Public License for more details. |
| 23 | +# |
| 24 | +# You should have received a copy of the GNU General Public License |
| 25 | +# along with this program; if not, write to the Free Software |
| 26 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 27 | +# |
| 28 | +# See COPYRIGHT and LICENSE files for more details. |
| 29 | +# ++ |
| 30 | + |
| 31 | +require "spec_helper" |
| 32 | + |
| 33 | +RSpec.describe "Workflow edit with multiple roles", :js do |
| 34 | + include Toasts::Expectations |
| 35 | + include Workflows::EditHelpers |
| 36 | + |
| 37 | + let(:role) { create(:project_role) } |
| 38 | + let(:role2) { create(:project_role) } |
| 39 | + let(:type) { create(:type) } |
| 40 | + let(:admin) { create(:admin) } |
| 41 | + let(:statuses) { (1..3).map { create(:status) } } |
| 42 | + |
| 43 | + # workflow for 0 -> 1 for 'role' |
| 44 | + let!(:role_workflow) do |
| 45 | + create(:workflow, role_id: role.id, type_id: type.id, |
| 46 | + old_status_id: statuses[0].id, new_status_id: statuses[1].id, |
| 47 | + author: false, assignee: false) |
| 48 | + end |
| 49 | + |
| 50 | + current_user { admin } |
| 51 | + |
| 52 | + context "when displaying checkboxes" do |
| 53 | + context "when all selected roles have a transition" do |
| 54 | + let!(:role2_workflow) do |
| 55 | + create(:workflow, role_id: role2.id, type_id: type.id, |
| 56 | + old_status_id: statuses[0].id, new_status_id: statuses[1].id, |
| 57 | + author: false, assignee: false) |
| 58 | + end |
| 59 | + |
| 60 | + before { visit_workflow_edit(roles: [role, role2]) } |
| 61 | + |
| 62 | + it "shows the checkbox as checked" do |
| 63 | + expect(page).to have_field workflow_checkbox(0, 1), checked: true |
| 64 | + expect(indeterminate?(workflow_checkbox(0, 1))).to be false |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + context "when no selected roles have a transition" do |
| 69 | + before { visit_workflow_edit(roles: [role, role2]) } |
| 70 | + |
| 71 | + it "shows the checkbox as unchecked" do |
| 72 | + expect(page).to have_field workflow_checkbox(1, 0), checked: false |
| 73 | + expect(indeterminate?(workflow_checkbox(1, 0))).to be false |
| 74 | + end |
| 75 | + end |
| 76 | + |
| 77 | + context "when only some selected roles have a transition" do |
| 78 | + before { visit_workflow_edit(roles: [role, role2]) } |
| 79 | + |
| 80 | + it "shows the checkbox as indeterminate" do |
| 81 | + expect(page).to have_field workflow_checkbox(0, 1), checked: false |
| 82 | + expect(indeterminate?(workflow_checkbox(0, 1))).to be true |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + context "when roles have different statuses in their workflows" do |
| 87 | + let!(:role2_workflow) do |
| 88 | + create(:workflow, role_id: role2.id, type_id: type.id, |
| 89 | + old_status_id: statuses[1].id, new_status_id: statuses[2].id, |
| 90 | + author: false, assignee: false) |
| 91 | + end |
| 92 | + |
| 93 | + before { visit_workflow_edit(roles: [role, role2]) } |
| 94 | + |
| 95 | + it "shows the union of statuses from all selected roles" do |
| 96 | + expect(page).to have_field workflow_checkbox(0, 2) |
| 97 | + expect(page).to have_field workflow_checkbox(1, 2) |
| 98 | + end |
| 99 | + end |
| 100 | + |
| 101 | + context "with a single role selected" do |
| 102 | + before { visit_workflow_edit(roles: [role]) } |
| 103 | + |
| 104 | + it "does not show indeterminate checkboxes" do |
| 105 | + expect(page).to have_field workflow_checkbox(0, 1), checked: true |
| 106 | + expect(indeterminate?(workflow_checkbox(0, 1))).to be false |
| 107 | + end |
| 108 | + end |
| 109 | + end |
| 110 | + |
| 111 | + context "when saving" do |
| 112 | + before { visit_workflow_edit(roles: [role, role2]) } |
| 113 | + |
| 114 | + it "adds the transition for all roles when checking an unchecked checkbox" do |
| 115 | + expect_transition(role, 1, 0, exist: false) |
| 116 | + expect_transition(role2, 1, 0, exist: false) |
| 117 | + |
| 118 | + check workflow_checkbox(1, 0) |
| 119 | + click_button "Save" |
| 120 | + expect_flash(message: "Successful update.") |
| 121 | + |
| 122 | + expect_transition(role, 1, 0, exist: true) |
| 123 | + expect_transition(role2, 1, 0, exist: true) |
| 124 | + end |
| 125 | + |
| 126 | + it "preserves state for each role when saving an untouched indeterminate checkbox" do |
| 127 | + expect_transition(role, 0, 1, exist: true) |
| 128 | + expect_transition(role2, 0, 1, exist: false) |
| 129 | + |
| 130 | + expect(page).to have_field workflow_checkbox(0, 1), checked: false |
| 131 | + expect(indeterminate?(workflow_checkbox(0, 1))).to be true |
| 132 | + |
| 133 | + click_button "Save" |
| 134 | + expect_flash(message: "Successful update.") |
| 135 | + |
| 136 | + expect_transition(role, 0, 1, exist: true) |
| 137 | + expect_transition(role2, 0, 1, exist: false) |
| 138 | + |
| 139 | + expect(indeterminate?(workflow_checkbox(0, 1))).to be true |
| 140 | + end |
| 141 | + |
| 142 | + it "adds the transition for all roles when checking an indeterminate checkbox" do |
| 143 | + expect_transition(role, 0, 1, exist: true) |
| 144 | + expect_transition(role2, 0, 1, exist: false) |
| 145 | + |
| 146 | + expect(page).to have_field workflow_checkbox(0, 1), checked: false |
| 147 | + expect(indeterminate?(workflow_checkbox(0, 1))).to be true |
| 148 | + |
| 149 | + check workflow_checkbox(0, 1) |
| 150 | + click_button "Save" |
| 151 | + expect_flash(message: "Successful update.") |
| 152 | + |
| 153 | + expect_transition(role, 0, 1, exist: true) |
| 154 | + expect_transition(role2, 0, 1, exist: true) |
| 155 | + |
| 156 | + expect(indeterminate?(workflow_checkbox(0, 1))).to be false |
| 157 | + end |
| 158 | + |
| 159 | + it "removes the transition from all roles when unchecking an indeterminate checkbox" do |
| 160 | + expect_transition(role, 0, 1, exist: true) |
| 161 | + expect_transition(role2, 0, 1, exist: false) |
| 162 | + |
| 163 | + expect(page).to have_field workflow_checkbox(0, 1), checked: false |
| 164 | + expect(indeterminate?(workflow_checkbox(0, 1))).to be true |
| 165 | + |
| 166 | + check workflow_checkbox(0, 1) |
| 167 | + uncheck workflow_checkbox(0, 1) |
| 168 | + click_button "Save" |
| 169 | + expect_flash(message: "Successful update.") |
| 170 | + |
| 171 | + expect_transition(role, 0, 1, exist: false) |
| 172 | + expect_transition(role2, 0, 1, exist: false) |
| 173 | + |
| 174 | + expect(indeterminate?(workflow_checkbox(0, 1))).to be false |
| 175 | + end |
| 176 | + |
| 177 | + context "when all roles have the transition" do |
| 178 | + let!(:role2_workflow) do |
| 179 | + create(:workflow, role_id: role2.id, type_id: type.id, |
| 180 | + old_status_id: statuses[0].id, new_status_id: statuses[1].id, |
| 181 | + author: false, assignee: false) |
| 182 | + end |
| 183 | + |
| 184 | + before { visit_workflow_edit(roles: [role, role2]) } |
| 185 | + |
| 186 | + it "removes the transition from all roles when unchecking a fully checked checkbox" do |
| 187 | + expect_transition(role, 0, 1, exist: true) |
| 188 | + expect_transition(role2, 0, 1, exist: true) |
| 189 | + |
| 190 | + uncheck workflow_checkbox(0, 1) |
| 191 | + click_button "Save" |
| 192 | + expect_flash(message: "Successful update.") |
| 193 | + |
| 194 | + expect_transition(role, 0, 1, exist: false) |
| 195 | + expect_transition(role2, 0, 1, exist: false) |
| 196 | + end |
| 197 | + end |
| 198 | + |
| 199 | + context "with multiple indeterminate checkboxes" do |
| 200 | + let!(:role_workflow2) do |
| 201 | + create(:workflow, role_id: role.id, type_id: type.id, |
| 202 | + old_status_id: statuses[0].id, new_status_id: statuses[2].id, |
| 203 | + author: false, assignee: false) |
| 204 | + end |
| 205 | + |
| 206 | + before { visit_workflow_edit(roles: [role, role2]) } |
| 207 | + |
| 208 | + it "handles touched and untouched indeterminate checkboxes independently" do |
| 209 | + # Both 0 -> 1 and 0 -> 2 are indeterminate |
| 210 | + expect_transition(role, 0, 1, exist: true) |
| 211 | + expect_transition(role2, 0, 1, exist: false) |
| 212 | + expect_transition(role, 0, 2, exist: true) |
| 213 | + expect_transition(role2, 0, 2, exist: false) |
| 214 | + |
| 215 | + check workflow_checkbox(0, 1) # explicitly check for all roles |
| 216 | + |
| 217 | + click_button "Save" |
| 218 | + expect_flash(message: "Successful update.") |
| 219 | + |
| 220 | + # role2 now has this workflow |
| 221 | + expect_transition(role2, 0, 1, exist: true) |
| 222 | + |
| 223 | + # 0 -> 2 stays indeterminate |
| 224 | + expect_transition(role, 0, 2, exist: true) |
| 225 | + expect_transition(role2, 0, 2, exist: false) |
| 226 | + end |
| 227 | + end |
| 228 | + |
| 229 | + it "marks the form dirty when interacting with an indeterminate checkbox" do |
| 230 | + expect(page).to have_field workflow_checkbox(0, 1), checked: false |
| 231 | + expect(indeterminate?(workflow_checkbox(0, 1))).to be true |
| 232 | + |
| 233 | + check workflow_checkbox(0, 1) |
| 234 | + |
| 235 | + click_link "User is author" |
| 236 | + expect(page).to have_dialog("Save changes before continuing?") |
| 237 | + end |
| 238 | + |
| 239 | + it "succeeds when saving with no changes to indeterminate checkboxes" do |
| 240 | + expect(page).to have_field workflow_checkbox(0, 1), checked: false |
| 241 | + expect(indeterminate?(workflow_checkbox(0, 1))).to be true |
| 242 | + |
| 243 | + click_button "Save" |
| 244 | + expect_flash(message: "Successful update.") |
| 245 | + end |
| 246 | + end |
| 247 | +end |
0 commit comments