summaryrefslogtreecommitdiff
path: root/spec/features/issues/update_issues_spec.rb
blob: fd8629ae50404ae3252dc1c64a2f1d32794b8fb9 (plain)
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
require 'rails_helper'

describe 'Multiple issue updating from issues#index', :js do
  let!(:project)   { create(:project) }
  let!(:issue)     { create(:issue, project: project) }
  let!(:user)      { create(:user)}

  before do
    project.add_maintainer(user)
    sign_in(user)
  end

  context 'status' do
    it 'sets to closed' do
      visit project_issues_path(project)

      click_button 'Edit issues'
      find('#check-all-issues').click
      find('.js-issue-status').click

      find('.dropdown-menu-status a', text: 'Closed').click
      click_update_issues_button
      expect(page).to have_selector('.issue', count: 0)
    end

    it 'sets to open' do
      create_closed
      visit project_issues_path(project, state: 'closed')

      click_button 'Edit issues'
      find('#check-all-issues').click
      find('.js-issue-status').click

      find('.dropdown-menu-status a', text: 'Open').click
      click_update_issues_button
      expect(page).to have_selector('.issue', count: 0)
    end
  end

  context 'assignee' do
    it 'updates to current user' do
      visit project_issues_path(project)

      click_button 'Edit issues'
      find('#check-all-issues').click
      click_update_assignee_button

      find('.dropdown-menu-user-link', text: user.username).click
      click_update_issues_button

      page.within('.issue .controls') do
        expect(find('.author-link')["title"]).to have_content(user.name)
      end
    end

    it 'updates to unassigned' do
      create_assigned
      visit project_issues_path(project)

      click_button 'Edit issues'
      find('#check-all-issues').click
      click_update_assignee_button

      click_link 'Unassigned'
      click_update_issues_button
      expect(find('.issue:first-child .controls')).not_to have_css('.author-link')
    end
  end

  context 'milestone' do
    let!(:milestone) { create(:milestone, project: project) }

    it 'updates milestone' do
      visit project_issues_path(project)

      click_button 'Edit issues'
      find('#check-all-issues').click
      find('.issues-bulk-update .js-milestone-select').click

      find('.dropdown-menu-milestone a', text: milestone.title).click
      click_update_issues_button

      expect(find('.issue')).to have_content milestone.title
    end

    it 'sets to no milestone' do
      create_with_milestone
      visit project_issues_path(project)

      expect(first('.issue')).to have_content milestone.title

      click_button 'Edit issues'
      find('#check-all-issues').click
      find('.issues-bulk-update .js-milestone-select').click

      find('.dropdown-menu-milestone a', text: "No Milestone").click
      click_update_issues_button

      expect(find('.issue:first-child')).not_to have_content milestone.title
    end
  end

  def create_closed
    create(:issue, project: project, state: :closed)
  end

  def create_assigned
    create(:issue, project: project, assignees: [user])
  end

  def create_with_milestone
    create(:issue, project: project, milestone: milestone)
  end

  def click_update_assignee_button
    find('.js-update-assignee').click
    wait_for_requests
  end

  def click_update_issues_button
    find('.update-selected-issues').click
    wait_for_requests
  end
end