-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathsprint_menu_component_spec.rb
More file actions
122 lines (98 loc) · 4.12 KB
/
sprint_menu_component_spec.rb
File metadata and controls
122 lines (98 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# frozen_string_literal: true
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
#++
require "rails_helper"
RSpec.describe Backlogs::SprintMenuComponent, type: :component do
shared_let(:type_feature) { create(:type_feature) }
shared_let(:type_task) { create(:type_task) }
let(:project) { create(:project, types: [type_feature, type_task]) }
let(:sprint) { create(:agile_sprint, project:, name: "Sprint 1", start_date: Date.yesterday, finish_date: Date.tomorrow) }
let(:stories) { [] }
let(:user) { create(:user) }
let(:permissions) { [] }
before do
allow(Setting)
.to receive(:plugin_openproject_backlogs)
.and_return("story_types" => [type_feature.id.to_s], "task_type" => type_task.id.to_s)
# Set up user with specific permissions
create(:member,
project:,
principal: user,
roles: [create(:project_role, permissions:)])
login_as(user)
end
def render_component
render_inline(described_class.new(sprint:, project:, current_user: user))
end
describe "permission-based items" do
context "with :manage_sprint_items permission" do
let(:permissions) { %i[view_sprints manage_sprint_items] }
it "shows Add new story item with compose icon" do
render_component
expect(page).to have_text(I18n.t(:"backlogs.backlog_menu_component.action_menu.new_story"))
expect(page).to have_octicon(:compose)
end
end
context "without :manage_sprint_items permission" do
let(:permissions) { [:view_sprints] }
it "does not show Add new story item" do
render_component
expect(page).to have_no_text(I18n.t(:"backlogs.backlog_menu_component.action_menu.new_story"))
end
end
context "with :create_sprints permission" do
let(:permissions) { %i[view_sprints create_sprints] }
it "shows Edit item with pencil icon" do
render_component
expect(page).to have_css("action-menu")
expect(page).to have_text(I18n.t("backlogs.backlog_menu_component.action_menu.edit_sprint"))
expect(page).to have_octicon(:pencil)
end
end
context "without :create_sprints permission" do
let(:permissions) { [:view_sprints] }
it "does not show Edit item" do
render_component
expect(page).to have_no_text(I18n.t("backlogs.backlog_menu_component.action_menu.edit_sprint"))
end
end
end
describe "always-visible items" do
let(:permissions) { [:view_sprints] }
it "renders stable ids on the action menu and stories/tasks item" do
render_component
expect(page).to have_element(:button, id: /\Aagile_sprint_#{sprint.id}_menu-button\z/)
expect(page).to have_element(:ul, id: /\Aagile_sprint_#{sprint.id}_menu-list\z/)
expect(page).to have_element(:a, id: /\Aagile_sprint_#{sprint.id}_menu_stories_tasks\z/)
end
it "shows Stories/Tasks link" do
render_component
expect(page).to have_text(I18n.t(:"backlogs.backlog_menu_component.action_menu.stories_tasks"))
end
end
end