sidebar_spec.rb 8.5 KB
Newer Older
P
Phil Hughes 已提交
1 2
require 'rails_helper'

3
describe 'Issue Boards', :js do
S
Simon Knox 已提交
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) }
P
Phil Hughes 已提交
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) }
P
Phil Hughes 已提交
18
  let(:card) { find('.board:nth-child(2)').first('.card') }
P
Phil Hughes 已提交
19

R
Rémy Coutable 已提交
20 21 22
  around do |example|
    Timecop.freeze { example.run }
  end
P
Phil Hughes 已提交
23

R
Rémy Coutable 已提交
24 25
  before do
    project.add_master(user)
P
Phil Hughes 已提交
26

27
    sign_in(user)
P
Phil Hughes 已提交
28

29
    visit project_board_path(project, board)
30
    wait_for_requests
P
Phil Hughes 已提交
31 32 33
  end

  it 'shows sidebar when clicking issue' do
P
Phil Hughes 已提交
34
    click_card(card)
P
Phil Hughes 已提交
35 36 37 38 39

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

  it 'closes sidebar when clicking issue' do
P
Phil Hughes 已提交
40
    click_card(card)
P
Phil Hughes 已提交
41 42 43

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

P
Phil Hughes 已提交
44
    click_card(card)
P
Phil Hughes 已提交
45 46 47 48 49

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

  it 'closes sidebar when clicking close button' do
P
Phil Hughes 已提交
50
    click_card(card)
P
Phil Hughes 已提交
51 52 53

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

54
    find('.gutter-toggle').click
P
Phil Hughes 已提交
55 56 57 58 59

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

  it 'shows issue details when sidebar is open' do
P
Phil Hughes 已提交
60
    click_card(card)
P
Phil Hughes 已提交
61 62

    page.within('.issue-boards-sidebar') do
63 64
      expect(page).to have_content(issue2.title)
      expect(page).to have_content(issue2.to_reference)
P
Phil Hughes 已提交
65 66 67
    end
  end

P
Phil Hughes 已提交
68 69
  it 'removes card from board when clicking ' do
    click_card(card)
P
Phil Hughes 已提交
70 71 72 73 74

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

75
    wait_for_requests
P
Phil Hughes 已提交
76

P
Phil Hughes 已提交
77
    page.within(find('.board:nth-child(2)')) do
P
Phil Hughes 已提交
78 79 80 81
      expect(page).to have_selector('.card', count: 1)
    end
  end

82 83 84 85
  it 'does not show remove button for backlog or closed issues' do
    create(:issue, project: project)
    create(:issue, :closed, project: project)

86
    visit project_board_path(project, board)
87 88 89 90 91 92 93 94 95 96
    wait_for_requests

    click_card(find('.board:nth-child(1)').first('.card'))

    expect(find('.issue-boards-sidebar')).not_to have_button 'Remove from board'

    click_card(find('.board:nth-child(3)').first('.card'))

    expect(find('.issue-boards-sidebar')).not_to have_button 'Remove from board'
  end
P
Phil Hughes 已提交
97

P
Phil Hughes 已提交
98 99
  context 'assignee' do
    it 'updates the issues assignee' do
P
Phil Hughes 已提交
100
      click_card(card)
P
Phil Hughes 已提交
101 102 103 104

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

105
        wait_for_requests
P
Phil Hughes 已提交
106 107 108 109

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

110
          wait_for_requests
P
Phil Hughes 已提交
111 112 113 114 115
        end

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

P
Phil Hughes 已提交
116
      expect(card).to have_selector('.avatar')
P
Phil Hughes 已提交
117 118 119
    end

    it 'removes the assignee' do
P
Phil Hughes 已提交
120
      card_two = find('.board:nth-child(2)').find('.card:nth-child(2)')
P
Phil Hughes 已提交
121
      click_card(card_two)
P
Phil Hughes 已提交
122 123 124 125

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

126
        wait_for_requests
P
Phil Hughes 已提交
127 128 129 130 131

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

132
        wait_for_requests
133

P
Phil Hughes 已提交
134 135 136
        expect(page).to have_content('No assignee')
      end

P
Phil Hughes 已提交
137
      expect(card_two).not_to have_selector('.avatar')
P
Phil Hughes 已提交
138 139 140
    end

    it 'assignees to current user' do
P
Phil Hughes 已提交
141
      click_card(card)
P
Phil Hughes 已提交
142

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

146
        click_button 'assign yourself'
P
Phil Hughes 已提交
147

148
        wait_for_requests
P
Phil Hughes 已提交
149 150 151 152

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

P
Phil Hughes 已提交
153
      expect(card).to have_selector('.avatar')
P
Phil Hughes 已提交
154
    end
155

156
    it 'updates assignee dropdown' do
P
Phil Hughes 已提交
157
      click_card(card)
158 159 160 161

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

162
        wait_for_requests
163 164 165 166

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

167
          wait_for_requests
168 169 170 171 172
        end

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

P
Phil Hughes 已提交
173
      page.within(find('.board:nth-child(2)')) do
174
        find('.card:nth-child(2)').click
175 176 177 178
      end

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

180
        expect(find('.dropdown-menu')).to have_selector('.is-active')
181 182
      end
    end
P
Phil Hughes 已提交
183 184 185 186
  end

  context 'milestone' do
    it 'adds a milestone' do
P
Phil Hughes 已提交
187
      click_card(card)
P
Phil Hughes 已提交
188 189 190 191

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

192
        wait_for_requests
P
Phil Hughes 已提交
193 194 195

        click_link milestone.title

196
        wait_for_requests
P
Phil Hughes 已提交
197 198 199 200 201 202 203 204

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

    it 'removes a milestone' do
P
Phil Hughes 已提交
205
      click_card(card)
P
Phil Hughes 已提交
206 207 208 209

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

210
        wait_for_requests
P
Phil Hughes 已提交
211 212 213

        click_link "No Milestone"

214
        wait_for_requests
P
Phil Hughes 已提交
215 216 217 218 219 220 221 222 223 224

        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
P
Phil Hughes 已提交
225
      click_card(card)
P
Phil Hughes 已提交
226 227 228 229

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

P
Phil Hughes 已提交
230
        click_button Date.today.day
P
Phil Hughes 已提交
231

232
        wait_for_requests
P
Phil Hughes 已提交
233 234 235 236 237 238 239 240

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

  context 'labels' do
    it 'adds a single label' do
P
Phil Hughes 已提交
241
      click_card(card)
P
Phil Hughes 已提交
242 243 244 245

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

246
        wait_for_requests
P
Phil Hughes 已提交
247

248
        click_link bug.title
P
Phil Hughes 已提交
249

250
        wait_for_requests
P
Phil Hughes 已提交
251 252 253 254

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

        page.within('.value') do
255 256
          expect(page).to have_selector('.label', count: 3)
          expect(page).to have_content(bug.title)
P
Phil Hughes 已提交
257 258 259
        end
      end

R
Regis Boudinot 已提交
260
      expect(card).to have_selector('.label', count: 3)
P
Phil Hughes 已提交
261
      expect(card).to have_content(bug.title)
P
Phil Hughes 已提交
262 263 264
    end

    it 'adds a multiple labels' do
P
Phil Hughes 已提交
265
      click_card(card)
P
Phil Hughes 已提交
266 267 268 269

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

270
        wait_for_requests
P
Phil Hughes 已提交
271

272 273
        click_link bug.title
        click_link regression.title
P
Phil Hughes 已提交
274

275
        wait_for_requests
P
Phil Hughes 已提交
276 277 278 279

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

        page.within('.value') do
280 281 282
          expect(page).to have_selector('.label', count: 4)
          expect(page).to have_content(bug.title)
          expect(page).to have_content(regression.title)
P
Phil Hughes 已提交
283 284 285
        end
      end

R
Regis Boudinot 已提交
286
      expect(card).to have_selector('.label', count: 4)
P
Phil Hughes 已提交
287 288
      expect(card).to have_content(bug.title)
      expect(card).to have_content(regression.title)
P
Phil Hughes 已提交
289 290 291
    end

    it 'removes a label' do
P
Phil Hughes 已提交
292
      click_card(card)
P
Phil Hughes 已提交
293 294 295 296

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

297
        wait_for_requests
P
Phil Hughes 已提交
298

299
        click_link stretch.title
P
Phil Hughes 已提交
300

301
        wait_for_requests
P
Phil Hughes 已提交
302 303 304 305

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

        page.within('.value') do
306 307
          expect(page).to have_selector('.label', count: 1)
          expect(page).not_to have_content(stretch.title)
P
Phil Hughes 已提交
308 309 310
        end
      end

R
Regis Boudinot 已提交
311
      expect(card).to have_selector('.label', count: 1)
P
Phil Hughes 已提交
312
      expect(card).not_to have_content(stretch.title)
P
Phil Hughes 已提交
313
    end
S
Simon Knox 已提交
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328

    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
P
Phil Hughes 已提交
329
  end
330 331 332

  context 'subscription' do
    it 'changes issue subscription' do
P
Phil Hughes 已提交
333
      click_card(card)
334
      wait_for_requests
335

336
      page.within('.subscriptions') do
337
        find('.js-issuable-subscribe-button button:not(.is-checked)').click
338
        wait_for_requests
339

340
        expect(page).to have_css('.js-issuable-subscribe-button button.is-checked')
341 342 343
      end
    end

344
    it 'has checked subscription toggle when already subscribed' do
345 346 347 348 349 350 351 352
      create(:subscription, user: user, project: project, subscribable: issue2, subscribed: true)
      visit project_board_path(project, board)
      wait_for_requests

      click_card(card)
      wait_for_requests

      page.within('.subscriptions') do
353
        find('.js-issuable-subscribe-button button.is-checked').click
354 355
        wait_for_requests

356
        expect(page).to have_css('.js-issuable-subscribe-button button:not(.is-checked)')
357 358 359
      end
    end
  end
P
Phil Hughes 已提交
360
end