sidebar_spec.rb 7.95 KB
Newer Older
Phil Hughes's avatar
Phil Hughes committed
1 2
require 'rails_helper'

3
describe 'Issue Boards', :js do
Simon Knox's avatar
Simon Knox committed
4 5
  include BoardHelpers

6
  let(:user)         { create(:user) }
7
  let(:user2)        { create(:user) }
8
  let(:project)      { create(:project, :public) }
9 10 11 12 13
  let!(:milestone)   { create(:milestone, project: project) }
  let!(:development) { create(:label, project: project, name: 'Development') }
  let!(:bug)         { create(:label, project: project, name: 'Bug') }
  let!(:regression)  { create(:label, project: project, name: 'Regression') }
  let!(:stretch)     { create(:label, project: project, name: 'Stretch') }
14
  let!(:issue1)      { create(:labeled_issue, project: project, assignees: [user], milestone: milestone, labels: [development], relative_position: 2) }
15
  let!(:issue2)      { create(:labeled_issue, project: project, labels: [development, stretch], relative_position: 1) }
16 17
  let(:board)        { create(:board, project: project) }
  let!(:list)        { create(:list, board: board, label: development, position: 0) }
Phil Hughes's avatar
Phil Hughes committed
18
  let(:card) { find('.board:nth-child(2)').first('.card') }
Phil Hughes's avatar
Phil Hughes committed
19

20 21 22 23
  around do |example|
    Timecop.freeze { example.run }
  end

Phil Hughes's avatar
Phil Hughes committed
24
  before do
25
    stub_licensed_features(multiple_issue_assignees: false)
26
    project.add_master(user)
Phil Hughes's avatar
Phil Hughes committed
27

28
    sign_in(user)
Phil Hughes's avatar
Phil Hughes committed
29

30
    visit project_board_path(project, board)
31
    wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
32 33 34
  end

  it 'shows sidebar when clicking issue' do
Phil Hughes's avatar
Phil Hughes committed
35
    click_card(card)
Phil Hughes's avatar
Phil Hughes committed
36 37 38 39 40

    expect(page).to have_selector('.issue-boards-sidebar')
  end

  it 'closes sidebar when clicking issue' do
Phil Hughes's avatar
Phil Hughes committed
41
    click_card(card)
Phil Hughes's avatar
Phil Hughes committed
42 43 44

    expect(page).to have_selector('.issue-boards-sidebar')

Phil Hughes's avatar
Phil Hughes committed
45
    click_card(card)
Phil Hughes's avatar
Phil Hughes committed
46 47 48 49 50

    expect(page).not_to have_selector('.issue-boards-sidebar')
  end

  it 'closes sidebar when clicking close button' do
Phil Hughes's avatar
Phil Hughes committed
51
    click_card(card)
Phil Hughes's avatar
Phil Hughes committed
52 53 54

    expect(page).to have_selector('.issue-boards-sidebar')

55
    find('.gutter-toggle').click
Phil Hughes's avatar
Phil Hughes committed
56 57 58 59 60

    expect(page).not_to have_selector('.issue-boards-sidebar')
  end

  it 'shows issue details when sidebar is open' do
Phil Hughes's avatar
Phil Hughes committed
61
    click_card(card)
Phil Hughes's avatar
Phil Hughes committed
62 63

    page.within('.issue-boards-sidebar') do
64 65
      expect(page).to have_content(issue2.title)
      expect(page).to have_content(issue2.to_reference)
Phil Hughes's avatar
Phil Hughes committed
66 67 68
    end
  end

Phil Hughes's avatar
Phil Hughes committed
69 70
  it 'removes card from board when clicking ' do
    click_card(card)
Phil Hughes's avatar
Phil Hughes committed
71 72 73 74 75

    page.within('.issue-boards-sidebar') do
      click_button 'Remove from board'
    end

76
    wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
77

Phil Hughes's avatar
Phil Hughes committed
78
    page.within(find('.board:nth-child(2)')) do
Phil Hughes's avatar
Phil Hughes committed
79 80 81 82
      expect(page).to have_selector('.card', count: 1)
    end
  end

83 84 85
  it 'does not show remove button for backlog or closed issues' do
    create(:issue, project: project)
    create(:issue, :closed, project: project)
Phil Hughes's avatar
Phil Hughes committed
86

87
    visit project_board_path(project, board)
88
    wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
89

90
    click_card(find('.board:nth-child(1)').first('.card'))
Phil Hughes's avatar
Phil Hughes committed
91

92
    expect(find('.issue-boards-sidebar')).not_to have_button 'Remove from board'
Phil Hughes's avatar
Phil Hughes committed
93

94
    click_card(find('.board:nth-child(3)').first('.card'))
Phil Hughes's avatar
Phil Hughes committed
95

96 97
    expect(find('.issue-boards-sidebar')).not_to have_button 'Remove from board'
  end
Phil Hughes's avatar
Phil Hughes committed
98 99 100

  context 'assignee' do
    it 'updates the issues assignee' do
101 102 103 104 105
      click_card(card)

      page.within('.assignee') do
        click_link 'Edit'

106
        wait_for_requests
107 108 109

        page.within('.dropdown-menu-user') do
          click_link user.name
Phil Hughes's avatar
Phil Hughes committed
110

111
          wait_for_requests
112 113 114 115 116
        end

        expect(page).to have_content(user.name)
      end

Phil Hughes's avatar
Phil Hughes committed
117
      expect(card).to have_selector('.avatar')
118 119
    end

Phil Hughes's avatar
Phil Hughes committed
120
    it 'removes the assignee' do
Phil Hughes's avatar
Phil Hughes committed
121
      card_two = find('.board:nth-child(2)').find('.card:nth-child(2)')
Phil Hughes's avatar
Phil Hughes committed
122
      click_card(card_two)
Phil Hughes's avatar
Phil Hughes committed
123 124 125 126

      page.within('.assignee') do
        click_link 'Edit'

127
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
128 129 130 131 132

        page.within('.dropdown-menu-user') do
          click_link 'Unassigned'
        end

133
        wait_for_requests
134

Phil Hughes's avatar
Phil Hughes committed
135 136 137
        expect(page).to have_content('No assignee')
      end

Phil Hughes's avatar
Phil Hughes committed
138
      expect(card_two).not_to have_selector('.avatar')
Phil Hughes's avatar
Phil Hughes committed
139 140 141
    end

    it 'assignees to current user' do
Phil Hughes's avatar
Phil Hughes committed
142
      click_card(card)
Phil Hughes's avatar
Phil Hughes committed
143

144 145 146
      page.within(find('.assignee')) do
        expect(page).to have_content('No assignee')

Clement Ho's avatar
Clement Ho committed
147
        click_button 'assign yourself'
Phil Hughes's avatar
Phil Hughes committed
148

149
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
150 151 152 153

        expect(page).to have_content(user.name)
      end

Phil Hughes's avatar
Phil Hughes committed
154
      expect(card).to have_selector('.avatar')
Phil Hughes's avatar
Phil Hughes committed
155
    end
156

Clement Ho's avatar
Clement Ho committed
157
    it 'updates assignee dropdown' do
Phil Hughes's avatar
Phil Hughes committed
158
      click_card(card)
159 160 161 162

      page.within('.assignee') do
        click_link 'Edit'

163
        wait_for_requests
164 165 166 167

        page.within('.dropdown-menu-user') do
          click_link user.name

168
          wait_for_requests
169 170 171 172 173
        end

        expect(page).to have_content(user.name)
      end

Phil Hughes's avatar
Phil Hughes committed
174
      page.within(find('.board:nth-child(2)')) do
175
        find('.card:nth-child(2)').click
176 177 178 179
      end

      page.within('.assignee') do
        click_link 'Edit'
180

181
        expect(find('.dropdown-menu')).to have_selector('.is-active')
182 183
      end
    end
Phil Hughes's avatar
Phil Hughes committed
184 185 186 187
  end

  context 'milestone' do
    it 'adds a milestone' do
Phil Hughes's avatar
Phil Hughes committed
188
      click_card(card)
Phil Hughes's avatar
Phil Hughes committed
189 190 191 192

      page.within('.milestone') do
        click_link 'Edit'

193
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
194 195 196

        click_link milestone.title

197
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
198 199 200 201 202 203 204 205

        page.within('.value') do
          expect(page).to have_content(milestone.title)
        end
      end
    end

    it 'removes a milestone' do
Phil Hughes's avatar
Phil Hughes committed
206
      click_card(card)
Phil Hughes's avatar
Phil Hughes committed
207 208 209 210

      page.within('.milestone') do
        click_link 'Edit'

211
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
212 213 214

        click_link "No Milestone"

215
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
216 217 218 219 220 221 222 223 224 225

        page.within('.value') do
          expect(page).not_to have_content(milestone.title)
        end
      end
    end
  end

  context 'due date' do
    it 'updates due date' do
Phil Hughes's avatar
Phil Hughes committed
226
      click_card(card)
Phil Hughes's avatar
Phil Hughes committed
227 228 229 230

      page.within('.due_date') do
        click_link 'Edit'

Phil Hughes's avatar
Phil Hughes committed
231
        click_button Date.today.day
Phil Hughes's avatar
Phil Hughes committed
232

233
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
234 235 236 237 238 239 240 241

        expect(page).to have_content(Date.today.to_s(:medium))
      end
    end
  end

  context 'labels' do
    it 'adds a single label' do
Phil Hughes's avatar
Phil Hughes committed
242
      click_card(card)
Phil Hughes's avatar
Phil Hughes committed
243 244 245 246

      page.within('.labels') do
        click_link 'Edit'

247
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
248

249
        click_link bug.title
Phil Hughes's avatar
Phil Hughes committed
250

251
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
252 253 254 255

        find('.dropdown-menu-close-icon').click

        page.within('.value') do
256 257
          expect(page).to have_selector('.label', count: 3)
          expect(page).to have_content(bug.title)
Phil Hughes's avatar
Phil Hughes committed
258 259 260
        end
      end

Regis Boudinot's avatar
Regis Boudinot committed
261
      expect(card).to have_selector('.label', count: 3)
Phil Hughes's avatar
Phil Hughes committed
262
      expect(card).to have_content(bug.title)
Phil Hughes's avatar
Phil Hughes committed
263 264 265
    end

    it 'adds a multiple labels' do
Phil Hughes's avatar
Phil Hughes committed
266
      click_card(card)
Phil Hughes's avatar
Phil Hughes committed
267 268 269 270

      page.within('.labels') do
        click_link 'Edit'

271
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
272

273 274
        click_link bug.title
        click_link regression.title
Phil Hughes's avatar
Phil Hughes committed
275

276
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
277 278 279 280

        find('.dropdown-menu-close-icon').click

        page.within('.value') do
281 282 283
          expect(page).to have_selector('.label', count: 4)
          expect(page).to have_content(bug.title)
          expect(page).to have_content(regression.title)
Phil Hughes's avatar
Phil Hughes committed
284 285 286
        end
      end

Regis Boudinot's avatar
Regis Boudinot committed
287
      expect(card).to have_selector('.label', count: 4)
Phil Hughes's avatar
Phil Hughes committed
288 289
      expect(card).to have_content(bug.title)
      expect(card).to have_content(regression.title)
Phil Hughes's avatar
Phil Hughes committed
290 291 292
    end

    it 'removes a label' do
Phil Hughes's avatar
Phil Hughes committed
293
      click_card(card)
Phil Hughes's avatar
Phil Hughes committed
294 295 296 297

      page.within('.labels') do
        click_link 'Edit'

298
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
299

300
        click_link stretch.title
Phil Hughes's avatar
Phil Hughes committed
301

302
        wait_for_requests
Phil Hughes's avatar
Phil Hughes committed
303 304 305 306

        find('.dropdown-menu-close-icon').click

        page.within('.value') do
307 308
          expect(page).to have_selector('.label', count: 1)
          expect(page).not_to have_content(stretch.title)
Phil Hughes's avatar
Phil Hughes committed
309 310 311
        end
      end

Regis Boudinot's avatar
Regis Boudinot committed
312
      expect(card).to have_selector('.label', count: 1)
Phil Hughes's avatar
Phil Hughes committed
313
      expect(card).not_to have_content(stretch.title)
Phil Hughes's avatar
Phil Hughes committed
314
    end
Simon Knox's avatar
Simon Knox committed
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329

    it 'creates new label' do
      click_card(card)

      page.within('.labels') do
        click_link 'Edit'
        click_link 'Create new label'
        fill_in 'new_label_name', with: 'test label'
        first('.suggest-colors-dropdown a').click
        click_button 'Create'
        wait_for_requests

        expect(page).to have_link 'test label'
      end
    end
Phil Hughes's avatar
Phil Hughes committed
330
  end
331 332 333

  context 'subscription' do
    it 'changes issue subscription' do
Phil Hughes's avatar
Phil Hughes committed
334
      click_card(card)
335 336 337

      page.within('.subscription') do
        click_button 'Subscribe'
338
        wait_for_requests
339
        expect(page).to have_content("Unsubscribe")
340 341 342
      end
    end
  end
Phil Hughes's avatar
Phil Hughes committed
343
end