BigW Consortium Gitlab

close_reopen_report_toggle_spec.rb 3.68 KB
Newer Older
Luke "Jared" Bennett committed
1 2
require 'spec_helper'

3
describe 'Issuables Close/Reopen/Report toggle' do
4
  let(:user) { create(:user) }
Luke "Jared" Bennett committed
5

6 7 8
  shared_examples 'an issuable close/reopen/report toggle' do
    let(:container) { find('.issuable-close-dropdown') }
    let(:human_model_name) { issuable.model_name.human.downcase }
Luke "Jared" Bennett committed
9

10 11 12 13
    it 'shows toggle' do
      expect(page).to have_link("Close #{human_model_name}")
      expect(page).to have_selector('.issuable-close-dropdown')
    end
Luke "Jared" Bennett committed
14

15 16 17 18 19 20 21 22 23 24 25 26
    it 'opens a dropdown when toggle is clicked' do
      container.find('.dropdown-toggle').click

      expect(container).to have_selector('.dropdown-menu')
      expect(container).to have_content("Close #{human_model_name}")
      expect(container).to have_content('Report abuse')
      expect(container).to have_content("Report #{human_model_name.pluralize} that are abusive, inappropriate or spam.")
      expect(container).to have_selector('.close-item.droplab-item-selected')
      expect(container).to have_selector('.report-item')
      expect(container).not_to have_selector('.report-item.droplab-item-selected')
      expect(container).not_to have_selector('.reopen-item')
    end
Luke "Jared" Bennett committed
27

28 29
    it 'changes the button when an item is selected' do
      button = container.find('.issuable-close-button')
Luke "Jared" Bennett committed
30

31 32
      container.find('.dropdown-toggle').click
      container.find('.report-item').click
Luke "Jared" Bennett committed
33

34 35
      expect(container).not_to have_selector('.dropdown-menu')
      expect(button).to have_content('Report abuse')
Luke "Jared" Bennett committed
36

37 38
      container.find('.dropdown-toggle').click
      container.find('.close-item').click
Luke "Jared" Bennett committed
39

40 41 42
      expect(button).to have_content("Close #{human_model_name}")
    end
  end
Luke "Jared" Bennett committed
43 44

  context 'on an issue' do
45
    let(:project) { create(:project) }
Luke "Jared" Bennett committed
46 47 48 49 50 51 52 53 54
    let(:issuable) { create(:issue, project: project) }

    before do
      project.add_master(user)
      login_as user
    end

    context 'when user has permission to update', :js do
      before do
55
        visit project_issue_path(project, issuable)
Luke "Jared" Bennett committed
56 57 58 59 60 61
      end

      it_behaves_like 'an issuable close/reopen/report toggle'
    end

    context 'when user doesnt have permission to update' do
62
      let(:cant_project) { create(:project) }
Luke "Jared" Bennett committed
63 64 65 66 67
      let(:cant_issuable) { create(:issue, project: cant_project) }

      before do
        cant_project.add_guest(user)

68
        visit project_issue_path(cant_project, cant_issuable)
Luke "Jared" Bennett committed
69 70 71 72 73 74 75 76 77 78 79 80 81
      end

      it 'only shows the `Report abuse` and `New issue` buttons' do
        expect(page).to have_link('Report abuse')
        expect(page).to have_link('New issue')
        expect(page).not_to have_link('Close issue')
        expect(page).not_to have_link('Reopen issue')
        expect(page).not_to have_link('Edit')
      end
    end
  end

  context 'on a merge request' do
82
    let(:project) { create(:project, :repository) }
Luke "Jared" Bennett committed
83 84 85 86 87 88 89 90 91
    let(:issuable) { create(:merge_request, source_project: project) }

    before do
      project.add_master(user)
      login_as user
    end

    context 'when user has permission to update', :js do
      before do
92
        visit project_merge_request_path(project, issuable)
Luke "Jared" Bennett committed
93 94 95 96 97 98
      end

      it_behaves_like 'an issuable close/reopen/report toggle'
    end

    context 'when user doesnt have permission to update' do
99
      let(:cant_project) { create(:project, :repository) }
Luke "Jared" Bennett committed
100 101 102 103 104
      let(:cant_issuable) { create(:merge_request, source_project: cant_project) }

      before do
        cant_project.add_reporter(user)

105
        visit project_merge_request_path(cant_project, cant_issuable)
Luke "Jared" Bennett committed
106 107 108 109 110 111 112 113 114 115 116
      end

      it 'only shows a `Report abuse` button' do
        expect(page).to have_link('Report abuse')
        expect(page).not_to have_link('Close merge request')
        expect(page).not_to have_link('Reopen merge request')
        expect(page).not_to have_link('Edit')
      end
    end
  end
end