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
require 'spec_helper'
feature 'Prioritize labels' do
include DragTo
let(:user) { create(:user) }
let(:group) { create(:group) }
let(:project) { create(:project, :public, namespace: group) }
let!(:bug) { create(:label, project: project, title: 'bug') }
let!(:wontfix) { create(:label, project: project, title: 'wontfix') }
let!(:feature) { create(:group_label, group: group, title: 'feature') }
context 'when user belongs to project team' do
before do
project.team << [user, :developer]
sign_in user
end
scenario 'user can prioritize a group label', js: true do
visit project_labels_path(project)
expect(page).to have_content('Star labels to start sorting by priority')
page.within('.other-labels') do
all('.js-toggle-priority')[1].click
wait_for_requests
expect(page).not_to have_content('feature')
end
page.within('.prioritized-labels') do
expect(page).not_to have_content('Star labels to start sorting by priority')
expect(page).to have_content('feature')
end
end
scenario 'user can unprioritize a group label', js: true do
create(:label_priority, project: project, label: feature, priority: 1)
visit project_labels_path(project)
page.within('.prioritized-labels') do
expect(page).to have_content('feature')
first('.js-toggle-priority').click
wait_for_requests
expect(page).not_to have_content('bug')
end
page.within('.other-labels') do
expect(page).to have_content('feature')
end
end
scenario 'user can prioritize a project label', js: true do
visit project_labels_path(project)
expect(page).to have_content('Star labels to start sorting by priority')
page.within('.other-labels') do
first('.js-toggle-priority').click
wait_for_requests
expect(page).not_to have_content('bug')
end
page.within('.prioritized-labels') do
expect(page).not_to have_content('Star labels to start sorting by priority')
expect(page).to have_content('bug')
end
end
scenario 'user can unprioritize a project label', js: true do
create(:label_priority, project: project, label: bug, priority: 1)
visit project_labels_path(project)
page.within('.prioritized-labels') do
expect(page).to have_content('bug')
first('.js-toggle-priority').click
wait_for_requests
expect(page).not_to have_content('bug')
end
page.within('.other-labels') do
expect(page).to have_content('bug')
expect(page).to have_content('wontfix')
end
end
scenario 'user can sort prioritized labels and persist across reloads', js: true do
create(:label_priority, project: project, label: bug, priority: 1)
create(:label_priority, project: project, label: feature, priority: 2)
visit project_labels_path(project)
expect(page).to have_content 'bug'
expect(page).to have_content 'feature'
expect(page).to have_content 'wontfix'
# Sort labels
drag_to(selector: '.js-prioritized-labels', from_index: 1, to_index: 2)
page.within('.prioritized-labels') do
expect(first('li')).to have_content('feature')
expect(page.all('li').last).to have_content('bug')
end
refresh
wait_for_requests
page.within('.prioritized-labels') do
expect(first('li')).to have_content('feature')
expect(page.all('li').last).to have_content('bug')
end
end
it 'shows a help message about prioritized labels' do
visit project_labels_path(project)
expect(page).to have_content 'Star a label'
end
end
context 'as a guest' do
it 'does not prioritize labels' do
guest = create(:user)
sign_in guest
visit project_labels_path(project)
expect(page).to have_content 'bug'
expect(page).to have_content 'wontfix'
expect(page).to have_content 'feature'
expect(page).not_to have_css('.prioritized-labels')
expect(page).not_to have_content 'Star a label'
end
end
context 'as a non signed in user' do
it 'does not prioritize labels' do
visit project_labels_path(project)
expect(page).to have_content 'bug'
expect(page).to have_content 'wontfix'
expect(page).to have_content 'feature'
expect(page).not_to have_css('.prioritized-labels')
expect(page).not_to have_content 'Star a label'
end
end
end