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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Group empty states' do
let(:group) { create(:group) }
let(:user) { create(:group_member, :developer, user: create(:user), group: group ).user }
before do
sign_in(user)
end
[:issue, :merge_request].each do |issuable|
issuable_name = issuable.to_s.humanize.downcase
project_relation = issuable == :issue ? :project : :source_project
context "for #{issuable_name}s" do
let(:path) { public_send(:"#{issuable}s_group_path", group) }
context 'group has a project' do
let(:project) { create(:project, namespace: group) }
before do
project.add_maintainer(user)
end
context "the project has #{issuable_name}s" do
it 'does not display an empty state' do
create(issuable, project_relation => project)
visit path
expect(page).not_to have_selector('.empty-state')
end
it "displays link to create new #{issuable} when no open #{issuable} is found", :js do
create("closed_#{issuable}", project_relation => project)
issuable_link_fn = "project_#{issuable}s_path"
visit public_send(issuable_link_fn, project)
wait_for_all_requests
page.within(find('.empty-state')) do
expect(page).to have_content(/There are no open #{issuable.to_s.humanize.downcase}/)
new_issuable_path = issuable == :issue ? 'new_project_issue_path' : 'project_new_merge_request_path'
path = public_send(new_issuable_path, project)
expect(page.find('a')['href']).to have_content(path)
end
end
it 'displays link to create new issue when the current search gave no results', :js do
create(issuable, project_relation => project)
issuable_link_fn = "project_#{issuable}s_path"
visit public_send(issuable_link_fn, project, author_username: 'foo', scope: 'all', state: 'opened')
wait_for_all_requests
page.within(find('.empty-state')) do
expect(page).to have_content(/Sorry, your filter produced no results/)
new_issuable_path = issuable == :issue ? 'new_project_issue_path' : 'project_new_merge_request_path'
path = public_send(new_issuable_path, project)
expect(page.find('a')['href']).to have_content(path)
end
end
it "displays conditional text when no closed #{issuable} is found", :js do
create(issuable, project_relation => project)
issuable_link_fn = "project_#{issuable}s_path"
visit public_send(issuable_link_fn, project, state: 'closed')
wait_for_all_requests
page.within(find('.empty-state')) do
expect(page).to have_content(/There are no closed #{issuable.to_s.humanize.downcase}/)
end
end
end
context "the project has no #{issuable_name}s", :js do
before do
visit path
end
it 'displays an empty state' do
expect(page).to have_selector('.empty-state')
end
it "shows a new #{issuable_name} button" do
expect(page).to have_content("create #{issuable_name}")
end
it "the new #{issuable_name} button opens a project dropdown" do
click_button 'Toggle project select'
if issuable == :issue
expect(page).to have_button project.name
else
expect(page).to have_selector('.ajax-project-dropdown')
end
end
end
end
shared_examples "no projects" do
it 'displays an empty state', :js do
expect(page).to have_selector('.empty-state')
end
it "does not show a new #{issuable_name} button", :js do
within '.empty-state' do
expect(page).not_to have_link("create #{issuable_name}")
end
end
end
context 'group without a project' do
context 'group has a subgroup' do
let(:subgroup) { create(:group, parent: group) }
let(:subgroup_project) { create(:project, namespace: subgroup) }
context "the project has #{issuable_name}s" do
before do
create(issuable, project_relation => subgroup_project)
visit path
end
it 'does not display an empty state' do
expect(page).not_to have_selector('.empty-state')
end
end
context "the project has no #{issuable_name}s" do
before do
visit path
end
it 'displays an empty state', :js do
expect(page).to have_selector('.empty-state')
end
end
end
context 'group has no subgroups' do
before do
visit path
end
it_behaves_like "no projects"
end
end
context 'group has only a project with issues disabled' do
let(:project_with_issues_disabled) { create(:empty_project, :issues_disabled, group: group) }
before do
visit path
end
it_behaves_like "no projects"
end
end
end
end
|