|
| 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 "rails_helper" |
| 32 | + |
| 33 | +RSpec.describe WorkPackageRelationsTab::RelationComponent, type: :component do |
| 34 | + shared_let(:user) { create(:admin) } |
| 35 | + shared_let(:work_package) { create(:work_package) } |
| 36 | + |
| 37 | + current_user { user } |
| 38 | + |
| 39 | + shared_let_work_packages(<<~TABLE) |
| 40 | + hierarchy | MTWTFSS | scheduling mode | predecessors |
| 41 | + predecessor | XXX | manual | |
| 42 | + work_package | X | automatic | predecessor with lag 2 |
| 43 | + child | | automatic | |
| 44 | + TABLE |
| 45 | + |
| 46 | + def render_component(**params) |
| 47 | + render_inline(described_class.new(work_package:, **params)) |
| 48 | + end |
| 49 | + |
| 50 | + context "with child relations" do |
| 51 | + context "when visible" do |
| 52 | + it "renders a title link" do |
| 53 | + expect(render_component(relation: nil, child: child, visibility: :visible)) |
| 54 | + .to have_link "child" |
| 55 | + end |
| 56 | + |
| 57 | + context "when editable" do |
| 58 | + it "renders an action menu" do |
| 59 | + component = render_component(relation: nil, child: child, visibility: :visible, editable: true) |
| 60 | + expect(component).to have_menu # FIXME: aria-labelledby does not resolve here "Relation actions" |
| 61 | + expect(component).to have_selector :menuitem, "Delete relation" |
| 62 | + end |
| 63 | + end |
| 64 | + end |
| 65 | + |
| 66 | + context "when ghost" do |
| 67 | + it "does not render a title link" do |
| 68 | + expect(render_component(relation: nil, child: child, visibility: :ghost)) |
| 69 | + .to have_no_link "child" |
| 70 | + end |
| 71 | + |
| 72 | + it "renders a title and message without details" do |
| 73 | + expect(render_component(relation: nil, child: child, visibility: :ghost)) |
| 74 | + .to have_text "Related work package" |
| 75 | + expect(render_component(relation: nil, child: child, visibility: :ghost)) |
| 76 | + .to have_text "This is not visible to you due to permissions." |
| 77 | + end |
| 78 | + |
| 79 | + it "does not render an action menu" do |
| 80 | + expect(render_component(relation: nil, child: child, visibility: :ghost)) |
| 81 | + .to have_no_menu |
| 82 | + end |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + context "with follows relations" do |
| 87 | + context "when visible" do |
| 88 | + it "renders a title link" do |
| 89 | + expect(render_component(relation: _table.relation(predecessor: predecessor), visibility: :visible)) |
| 90 | + .to have_link "predecessor" |
| 91 | + end |
| 92 | + |
| 93 | + it "renders the lag" do |
| 94 | + expect(render_component(relation: _table.relation(predecessor: predecessor), visibility: :visible)) |
| 95 | + .to have_text "Lag: 2 days" |
| 96 | + end |
| 97 | + |
| 98 | + context "when editable" do |
| 99 | + it "renders a action menu" do |
| 100 | + component = render_component(relation: _table.relation(predecessor: predecessor), visibility: :visible, editable: true) |
| 101 | + expect(component).to have_menu # FIXME: aria-labelledby does not resolve here "Relation actions" |
| 102 | + expect(component).to have_selector :menuitem, "Edit relation" |
| 103 | + expect(component).to have_selector :menuitem, "Delete relation" |
| 104 | + end |
| 105 | + end |
| 106 | + end |
| 107 | + |
| 108 | + context "when ghost" do |
| 109 | + it "does not render a title link" do |
| 110 | + expect(render_component(relation: _table.relation(predecessor: predecessor), visibility: :ghost)) |
| 111 | + .to have_no_link "child" |
| 112 | + end |
| 113 | + |
| 114 | + it "renders a title and message without details" do |
| 115 | + expect(render_component(relation: _table.relation(predecessor: predecessor), visibility: :ghost)) |
| 116 | + .to have_text "Related work package" |
| 117 | + expect(render_component(relation: _table.relation(predecessor: predecessor), visibility: :ghost)) |
| 118 | + .to have_text "This is not visible to you due to permissions." |
| 119 | + end |
| 120 | + |
| 121 | + it "does not render an action menu" do |
| 122 | + expect(render_component(relation: _table.relation(predecessor: predecessor), visibility: :ghost)) |
| 123 | + .to have_no_menu |
| 124 | + end |
| 125 | + end |
| 126 | + |
| 127 | + context "when closest" do |
| 128 | + it "always renders a closest label" do |
| 129 | + expect(render_component(relation: _table.relation(predecessor: predecessor), visibility: :visible, closest: true)) |
| 130 | + .to have_primer_label "Closest", scheme: :primary |
| 131 | + expect(render_component(relation: _table.relation(predecessor: predecessor), visibility: :ghost, closest: true)) |
| 132 | + .to have_primer_label "Closest", scheme: :primary |
| 133 | + end |
| 134 | + end |
| 135 | + end |
| 136 | +end |
0 commit comments