BigW Consortium Gitlab

user_uses_slash_commands_spec.rb 4.56 KB
Newer Older
1 2 3
require 'rails_helper'

feature 'Issues > User uses slash commands', feature: true, js: true do
4
  include SlashCommandsHelpers
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
  include WaitForAjax

  it_behaves_like 'issuable record that supports slash commands in its description and notes', :issue do
    let(:issuable) { create(:issue, project: project) }
  end

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

    before do
      project.team << [user, :master]
      login_with(user)
      visit namespace_project_issue_path(project.namespace, project, issue)
    end

21 22 23 24
    after do
      wait_for_ajax
    end

25 26 27
    describe 'adding a due date from note' do
      let(:issue) { create(:issue, project: project) }

28 29 30
      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")
31

32
          expect(page).not_to have_content '/due 2016-08-28'
33
          expect(page).to have_content 'Commands applied'
34

35
          issue.reload
36

37 38 39 40 41 42 43 44 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]
          logout
          login_with(guest)
          visit namespace_project_issue_path(project.namespace, project, issue)
        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'
54
          expect(page).not_to have_content 'Commands applied'
55 56 57 58 59

          issue.reload

          expect(issue.due_date).to be_nil
        end
60 61 62 63 64 65
      end
    end

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

66 67 68 69 70 71 72
      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'
73
          expect(page).to have_content 'Commands applied'
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

          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]
          logout
          login_with(guest)
          visit namespace_project_issue_path(project.namespace, project, issue)
        end
89

90 91
        it 'does not create a note, and sets the due date accordingly' do
          write_note("/remove_due_date")
92

93
          expect(page).to have_content '/remove_due_date'
94
          expect(page).not_to have_content 'Commands applied'
95

96
          issue.reload
97

98 99
          expect(issue.due_date).to eq Date.new(2016, 8, 28)
        end
100 101
      end
    end
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
    describe 'Issuable time tracking' do
      let(:issue) { create(:issue, project: project) }

      before do
        project.team << [user, :developer]
      end

      context 'Issue' do
        before do
          visit namespace_project_issue_path(project.namespace, project, issue)
        end

        it_behaves_like 'issuable time tracker'
      end

      context 'Merge Request' do
        let(:merge_request) { create(:merge_request, source_project: project) }

        before do
          visit namespace_project_merge_request_path(project.namespace, project, merge_request)
        end

        it_behaves_like 'issuable time tracker'
      end
    end

129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    describe 'Issuable time tracking' do
      let(:issue) { create(:issue, project: project) }

      before do
        project.team << [user, :developer]
      end

      context 'Issue' do
        before do
          visit namespace_project_issue_path(project.namespace, project, issue)
        end

        it_behaves_like 'issuable time tracker'
      end

      context 'Merge Request' do
        let(:merge_request) { create(:merge_request, source_project: project) }

        before do
          visit namespace_project_merge_request_path(project.namespace, project, merge_request)
        end

        it_behaves_like 'issuable time tracker'
      end
    end

155 156 157 158 159 160 161 162 163
    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
164 165
  end
end