/
hierarchy_spec.rb
265 lines (215 loc) · 8.81 KB
/
hierarchy_spec.rb
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
require 'spec_helper'
describe 'Work Package table hierarchy', js: true do
let(:user) { FactoryGirl.create :admin }
let(:project) { FactoryGirl.create(:project) }
let(:wp_table) { Pages::WorkPackagesTable.new(project) }
let(:hierarchy) { ::Components::WorkPackages::Hierarchies.new }
before do
login_as(user)
end
describe 'hierarchies in same project' do
let(:category) { FactoryGirl.create :category, project: project, name: 'Foo' }
let!(:wp_root) { FactoryGirl.create(:work_package, project: project) }
let!(:wp_inter) { FactoryGirl.create(:work_package, project: project, parent: wp_root) }
let!(:wp_leaf) { FactoryGirl.create(:work_package, project: project, category: category, parent: wp_inter) }
let!(:wp_other) { FactoryGirl.create(:work_package, project: project) }
let!(:query) do
query = FactoryGirl.build(:query, user: user, project: project)
query.column_names = ['subject', 'category']
query.filters.clear
query.add_filter('category_id', '=', [category.id])
query.show_hierarchies = true
query.save!
query
end
it 'shows hierarchy correctly' do
wp_table.visit!
wp_table.expect_work_package_listed(wp_root, wp_inter, wp_leaf, wp_other)
# Hierarchy mode is enabled by default
hierarchy.expect_hierarchy_at(wp_root, wp_inter)
hierarchy.expect_leaf_at(wp_leaf, wp_other)
# Toggling hierarchies hides the inner children
hierarchy.toggle_row(wp_root)
# Root, other showing
wp_table.expect_work_package_listed(wp_root, wp_other)
# Inter, Leaf hidden
hierarchy.expect_hidden(wp_inter, wp_leaf)
# Show all again
hierarchy.toggle_row(wp_root)
wp_table.expect_work_package_listed(wp_root, wp_other, wp_inter, wp_leaf)
# Disable hierarchies
hierarchy.disable_hierarchy
hierarchy.expect_no_hierarchies
# Editing is possible while retaining hierarchy
hierarchy.enable_hierarchy
subject = wp_table.edit_field wp_inter, :subject
subject.update 'New subject'
wp_table.expect_notification message: 'Successful update.'
wp_table.dismiss_notification!
hierarchy.expect_hierarchy_at(wp_root, wp_inter)
hierarchy.expect_leaf_at(wp_leaf, wp_other)
# Disable hierarchy again
hierarchy.disable_hierarchy
hierarchy.expect_no_hierarchies
# Now visiting the query for category
wp_table.visit_query(query)
# Should only list the matching leaf
wp_table.expect_work_package_listed(wp_leaf)
hierarchy.expect_hierarchy_at(wp_root, wp_inter)
hierarchy.toggle_row(wp_root)
wp_table.expect_work_package_listed(wp_root, wp_inter, wp_leaf)
# Disabling hierarchy hides them again
hierarchy.disable_hierarchy
expect(page).to have_no_selector(".wp-row-#{wp_root.id}")
expect(page).to have_no_selector(".wp-row-#{wp_inter.id}")
end
end
describe 'with a cross project hierarchy' do
let(:project2) { FactoryGirl.create(:project) }
let!(:wp_root) { FactoryGirl.create(:work_package, project: project) }
let!(:wp_inter) { FactoryGirl.create(:work_package, project: project2, parent: wp_root) }
let(:global_table) { Pages::WorkPackagesTable.new }
it 'shows the hierarchy indicator only when the rows are both shown' do
wp_table.visit!
wp_table.expect_work_package_listed(wp_root)
wp_table.expect_work_package_not_listed(wp_inter)
hierarchy.expect_leaf_at(wp_root)
# Visit global table
global_table.visit!
wp_table.expect_work_package_listed(wp_root, wp_inter)
hierarchy.expect_hierarchy_at(wp_root)
hierarchy.expect_leaf_at(wp_inter)
end
end
describe 'flat table such that the parent appears below the child' do
let!(:wp_root) { FactoryGirl.create(:work_package, project: project) }
let!(:wp_inter) { FactoryGirl.create(:work_package, project: project, parent: wp_root) }
let!(:wp_leaf) { FactoryGirl.create(:work_package, project: project, parent: wp_inter) }
let!(:query) do
query = FactoryGirl.build(:query, user: user, project: project)
query.column_names = ['subject', 'category']
query.filters.clear
query.show_hierarchies = false
query.save!
query
end
it 'removes the parent from the flow in hierarchy mode, moving it above' do
# Hierarchy disabled, expect wp_inter before wp_root
wp_table.visit_query query
wp_table.expect_work_package_listed(wp_inter, wp_root, wp_leaf)
wp_table.expect_work_package_order(wp_inter.id, wp_root.id, wp_leaf.id)
hierarchy.expect_no_hierarchies
# Enable hierarchy mode, should move it above now
hierarchy.enable_hierarchy
# Should not be marked as additional row (grey)
expect(page).to have_no_selector('.wp-table--hierarchy-aditional-row')
hierarchy.expect_hierarchy_at(wp_root, wp_inter)
hierarchy.expect_leaf_at(wp_leaf)
wp_table.expect_work_package_listed(wp_inter, wp_root, wp_leaf)
wp_table.expect_work_package_order(wp_root.id, wp_inter.id, wp_leaf.id)
# Toggling hierarchies hides the inner children
hierarchy.toggle_row(wp_root)
# Root showing
wp_table.expect_work_package_listed(wp_root)
# Inter hidden
hierarchy.expect_hidden(wp_inter, wp_leaf)
end
end
describe 'sorting by assignee' do
include_context 'work package table helpers'
let!(:root_assigned) do
FactoryGirl.create(:work_package, subject: 'root_assigned', project: project, assigned_to: user)
end
let!(:inter_assigned) do
FactoryGirl.create(:work_package, subject: 'inter_assigned', project: project, assigned_to: user, parent: root_assigned)
end
let!(:inter) do
FactoryGirl.create(:work_package, subject: 'inter', project: project, parent: root_assigned)
end
let!(:leaf_assigned) do
FactoryGirl.create(:work_package, subject: 'leaf_assigned', project: project, assigned_to: user, parent: inter)
end
let!(:leaf) do
FactoryGirl.create(:work_package, subject: 'leaf', project: project, parent: inter)
end
let!(:root) do
FactoryGirl.create(:work_package, project: project)
end
let(:user) do
FactoryGirl.create :user,
member_in_project: project,
member_through_role: role
end
let(:permissions) { %i(view_work_packages add_work_packages) }
let(:role) { FactoryGirl.create :role, permissions: permissions }
let!(:query) do
query = FactoryGirl.build(:query, user: user, project: project)
query.column_names = ['subject', 'assigned_to']
query.filters.clear
query.sort_criteria = [['assigned_to', 'asc']]
query.show_hierarchies = false
query.save!
query
end
it 'shows the respective order' do
wp_table.visit_query query
wp_table.expect_work_package_listed(leaf, inter, root)
wp_table.expect_work_package_listed(leaf_assigned, inter_assigned, root_assigned)
wp_table.expect_work_package_order(
leaf_assigned.id, inter_assigned.id, root_assigned.id,
leaf.id, inter.id, root.id
)
# Hierarchy should be disabled
hierarchy.expect_no_hierarchies
# Enable hierarchy mode, should sort according to spec above
hierarchy.enable_hierarchy
hierarchy.expect_hierarchy_at(root_assigned, inter)
hierarchy.expect_leaf_at(root, leaf, leaf_assigned, inter_assigned)
# When ascending, order should be:
# ├──root_assigned
# | ├─ inter_assigned
# | ├─ inter
# | | ├─ leaf_assigned
# | | ├─ leaf
# ├──root
wp_table.expect_work_package_order(
root_assigned.id,
inter_assigned.id,
inter.id,
leaf_assigned.id,
leaf.id,
root.id
)
# Test collapsing of rows
hierarchy.toggle_row(root_assigned)
wp_table.expect_work_package_listed(root, root_assigned)
hierarchy.expect_hidden(inter, inter_assigned, leaf, leaf_assigned)
hierarchy.toggle_row(root_assigned)
# Sort descending
sort_wp_table_by 'Assignee', order: :desc
loading_indicator_saveguard
wp_table.expect_work_package_listed(root, root_assigned)
# When descending, order should be:
# ├──root
# ├──root
# | ├─ inter
# | | ├─ leaf
# | | ├─ leaf_assigned
# | ├─ inter_assigned
wp_table.expect_work_package_order(
root.id,
root_assigned.id,
inter.id,
inter_assigned.id,
leaf.id,
leaf_assigned.id
)
# Disable hierarchy mode
hierarchy.disable_hierarchy
wp_table.expect_work_package_order(
leaf.id, inter.id, root.id,
leaf_assigned.id, inter_assigned.id, root_assigned.id
)
end
end
end