user_uses_slash_commands_spec.rb 8.52 KB
Newer Older
1 2
require 'rails_helper'

3
feature 'Issues > User uses quick actions', js: true do
4
  include QuickActionsHelpers
5

6
  it_behaves_like 'issuable record that supports quick actions in its description and notes', :issue do
7 8 9 10 11
    let(:issuable) { create(:issue, project: project) }
  end

  describe 'issue-only commands' do
    let(:user) { create(:user) }
12
    let(:project) { create(:project, :public) }
13 14 15

    before do
      project.team << [user, :master]
16
      sign_in(user)
17
      visit project_issue_path(project, issue)
18 19
    end

20
    after do
21
      wait_for_requests
22 23
    end

24 25 26 27 28 29 30 31 32 33
    describe 'time tracking' do
      let(:issue) { create(:issue, project: project) }

      before do
        visit project_issue_path(project, issue)
      end

      it_behaves_like 'issuable time tracker'
    end

34 35 36
    describe 'adding a due date from note' do
      let(:issue) { create(:issue, project: project) }

37 38 39
      context 'when the current user can update the due date' do
        it 'does not create a note, and sets the due date accordingly' do
          write_note("/due 2016-08-28")
40

41
          expect(page).not_to have_content '/due 2016-08-28'
42
          expect(page).to have_content 'Commands applied'
43

44
          issue.reload
45

46 47 48 49 50 51 52 53
          expect(issue.due_date).to eq Date.new(2016, 8, 28)
        end
      end

      context 'when the current user cannot update the due date' do
        let(:guest) { create(:user) }
        before do
          project.team << [guest, :guest]
54
          gitlab_sign_out
55
          sign_in(guest)
56
          visit project_issue_path(project, issue)
57 58 59 60 61 62
        end

        it 'does not create a note, and sets the due date accordingly' do
          write_note("/due 2016-08-28")

          expect(page).to have_content '/due 2016-08-28'
63
          expect(page).not_to have_content 'Commands applied'
64 65 66 67 68

          issue.reload

          expect(issue.due_date).to be_nil
        end
69 70 71 72 73 74
      end
    end

    describe 'removing a due date from note' do
      let(:issue) { create(:issue, project: project, due_date: Date.new(2016, 8, 28)) }

75 76 77 78 79 80 81
      context 'when the current user can update the due date' do
        it 'does not create a note, and removes the due date accordingly' do
          expect(issue.due_date).to eq Date.new(2016, 8, 28)

          write_note("/remove_due_date")

          expect(page).not_to have_content '/remove_due_date'
82
          expect(page).to have_content 'Commands applied'
83 84 85 86 87 88 89 90 91 92 93

          issue.reload

          expect(issue.due_date).to be_nil
        end
      end

      context 'when the current user cannot update the due date' do
        let(:guest) { create(:user) }
        before do
          project.team << [guest, :guest]
94
          gitlab_sign_out
95
          sign_in(guest)
96
          visit project_issue_path(project, issue)
97
        end
98

99 100
        it 'does not create a note, and sets the due date accordingly' do
          write_note("/remove_due_date")
101

102
          expect(page).to have_content '/remove_due_date'
103
          expect(page).not_to have_content 'Commands applied'
104

105
          issue.reload
106

107 108
          expect(issue.due_date).to eq Date.new(2016, 8, 28)
        end
109 110
      end
    end
111 112 113 114 115 116 117 118 119 120

    describe 'toggling the WIP prefix from the title from note' do
      let(:issue) { create(:issue, project: project) }

      it 'does not recognize the command nor create a note' do
        write_note("/wip")

        expect(page).not_to have_content '/wip'
      end
    end
121 122 123 124 125 126 127 128 129 130 131 132 133

    describe 'mark issue as duplicate' do
      let(:issue) { create(:issue, project: project) }
      let(:original_issue) { create(:issue, project: project) }

      context 'when the current user can update issues' do
        it 'does not create a note, and marks the issue as a duplicate' do
          write_note("/duplicate ##{original_issue.to_reference}")

          expect(page).not_to have_content "/duplicate #{original_issue.to_reference}"
          expect(page).to have_content 'Commands applied'
          expect(page).to have_content "marked this issue as a duplicate of #{original_issue.to_reference}"

Ryan Scott's avatar
Ryan Scott committed
134
          expect(issue.reload).to be_closed
135 136 137 138 139 140 141
        end
      end

      context 'when the current user cannot update the issue' do
        let(:guest) { create(:user) }
        before do
          project.team << [guest, :guest]
Sean McGivern's avatar
Sean McGivern committed
142 143 144
          gitlab_sign_out
          sign_in(guest)
          visit project_issue_path(project, issue)
145 146 147 148 149 150 151 152 153
        end

        it 'does not create a note, and does not mark the issue as a duplicate' do
          write_note("/duplicate ##{original_issue.to_reference}")

          expect(page).to have_content "/duplicate ##{original_issue.to_reference}"
          expect(page).not_to have_content 'Commands applied'
          expect(page).not_to have_content "marked this issue as a duplicate of #{original_issue.to_reference}"

Ryan Scott's avatar
Ryan Scott committed
154
          expect(issue.reload).to be_open
155 156 157
        end
      end
    end
158 159 160 161

    describe 'move the issue to another project' do
      let(:issue) { create(:issue, project: project) }

162
      context 'when the project is valid' do
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
        let(:target_project) { create(:project, :public) }

        before do
          target_project.team << [user, :master]
          sign_in(user)
          visit project_issue_path(project, issue)
        end

        it 'moves the issue' do
          write_note("/move #{target_project.full_path}")

          expect(page).to have_content 'Commands applied'
          expect(issue.reload).to be_closed

          visit project_issue_path(target_project, issue)

          expect(page).to have_content 'Issues 1'
        end
      end

183
      context 'when the project is valid but the user not authorized' do
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
        let(:project_unauthorized) {create(:project, :public)}

        before do
          sign_in(user)
          visit project_issue_path(project, issue)
        end

        it 'does not move the issue' do
          write_note("/move #{project_unauthorized.full_path}")

          expect(page).not_to have_content 'Commands applied'
          expect(issue.reload).to be_open
        end
      end

199
      context 'when the project is invalid' do
200 201 202 203 204 205 206 207 208 209 210 211 212
        before do
          sign_in(user)
          visit project_issue_path(project, issue)
        end

        it 'does not move the issue' do
          write_note("/move not/valid")

          expect(page).not_to have_content 'Commands applied'
          expect(issue.reload).to be_open
        end
      end

213
      context 'when the user issues multiple commands' do
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 266
        let(:target_project) { create(:project, :public) }
        let(:milestone) { create(:milestone, title: '1.0', project: project) }
        let(:target_milestone) { create(:milestone, title: '1.0', project: target_project) }
        let(:bug)      { create(:label, project: project, title: 'bug') }
        let(:wontfix)  { create(:label, project: project, title: 'wontfix') }
        let(:bug_target)      { create(:label, project: target_project, title: 'bug') }
        let(:wontfix_target)  { create(:label, project: target_project, title: 'wontfix') }

        before do
          target_project.team << [user, :master]
          sign_in(user)
          visit project_issue_path(project, issue)
        end

        it 'applies the commands to both issues and moves the issue' do
          write_note("/label ~#{bug.title} ~#{wontfix.title}\n/milestone %\"#{milestone.title}\"\n/move #{target_project.full_path}")

          expect(page).to have_content 'Commands applied'
          expect(issue.reload).to be_closed

          visit project_issue_path(target_project, issue)

          expect(page).to have_content 'bug'
          expect(page).to have_content 'wontfix'
          expect(page).to have_content '1.0'

          visit project_issue_path(project, issue)
          expect(page).to have_content 'Closed'
          expect(page).to have_content 'bug'
          expect(page).to have_content 'wontfix'
          expect(page).to have_content '1.0'
        end

        it 'moves the issue and applies the commands to both issues' do
          write_note("/move #{target_project.full_path}\n/label ~#{bug.title} ~#{wontfix.title}\n/milestone %\"#{milestone.title}\"")

          expect(page).to have_content 'Commands applied'
          expect(issue.reload).to be_closed

          visit project_issue_path(target_project, issue)

          expect(page).to have_content 'bug'
          expect(page).to have_content 'wontfix'
          expect(page).to have_content '1.0'

          visit project_issue_path(project, issue)
          expect(page).to have_content 'Closed'
          expect(page).to have_content 'bug'
          expect(page).to have_content 'wontfix'
          expect(page).to have_content '1.0'
        end
      end
    end
267 268
  end
end