milestone_spec.rb 2.83 KB
Newer Older
1 2
require 'spec_helper'

3 4 5 6 7 8 9 10 11
feature 'Project milestone', :feature do
  let(:user) { create(:user) }
  let(:project) { create(:empty_project, name: 'test', namespace: user.namespace) }
  let(:milestone) { create(:milestone, project: project) }

  before do
    login_as(user)
  end

12 13
  context 'when project has enabled issues' do
    before do
14
      visit namespace_project_milestone_path(project.namespace, project, milestone)
15 16 17 18 19 20 21 22 23 24 25
    end

    it 'shows issues tab' do
      within('#content-body') do
        expect(page).to have_link 'Issues', href: '#tab-issues'
        expect(page).to have_selector '.nav-links li.active', count: 1
        expect(find('.nav-links li.active')).to have_content 'Issues'
      end
    end

    it 'shows issues stats' do
26
      expect(find('.milestone-sidebar')).to have_content 'Issues 0'
27 28
    end

29 30 31 32 33
    it 'shows link to browse and add issues' do
      within('.milestone-sidebar') do
        expect(page).to have_link 'New issue'
        expect(page).to have_link 'Open: 0'
        expect(page).to have_link 'Closed: 0'
34 35 36 37 38 39 40
      end
    end
  end

  context 'when project has disabled issues' do
    before do
      project.project_feature.update_attribute(:issues_access_level, ProjectFeature::DISABLED)
41
      visit namespace_project_milestone_path(project.namespace, project, milestone)
42 43 44 45 46 47 48 49 50 51 52
    end

    it 'hides issues tab' do
      within('#content-body') do
        expect(page).not_to have_link 'Issues', href: '#tab-issues'
        expect(page).to have_selector '.nav-links li.active', count: 1
        expect(find('.nav-links li.active')).to have_content 'Merge Requests'
      end
    end

    it 'hides issues stats' do
53
      expect(find('.milestone-sidebar')).not_to have_content 'Issues 0'
54 55
    end

56 57 58
    it 'hides new issue button' do
      within('.milestone-sidebar') do
        expect(page).not_to have_link 'New issue'
59 60 61 62 63
      end
    end

    it 'does not show an informative message' do
      expect(page).not_to have_content('Assign some issues to this milestone.')
64 65
    end
  end
66

67 68 69 70
  # EE-only
  context 'milestone summary' do
    it 'shows the total weight when sum is greater than zero' do
      create(:issue, project: project, milestone: milestone, weight: 3)
71
      create(:issue, project: project, milestone: milestone, weight: 1)
72 73 74

      visit milestone_path

75 76
      within '.milestone-sidebar' do
        expect(page).to have_content 'Total issue weight 4'
77 78 79 80 81
      end
    end

    it 'hides the total weight when sum is equal to zero' do
      create(:issue, project: project, milestone: milestone, weight: nil)
82
      create(:issue, project: project, milestone: milestone, weight: nil)
83 84 85

      visit milestone_path

86 87
      within '.milestone-sidebar' do
        expect(page).to have_content 'Total issue weight None'
88 89 90 91 92
      end
    end
  end
  # EE-only

93
  def milestone_path
94
    namespace_project_milestone_path(project.namespace, project, milestone)
95
  end
96
end