milestone_spec.rb 4.06 KB
Newer Older
1 2
require 'rails_helper'

3
describe 'Milestone' do
Felipe Artur's avatar
Felipe Artur committed
4
  let(:group) { create(:group, :public) }
5
  let(:project) { create(:project, :public, namespace: group) }
6 7 8
  let(:user)   { create(:user) }

  before do
Felipe Artur's avatar
Felipe Artur committed
9
    create(:group_member, group: group, user: user)
10
    project.add_maintainer(user)
11
    sign_in(user)
12 13
  end

14 15
  describe 'Create a milestone' do
    it 'shows an informative message for a new milestone' do
16
      visit new_project_milestone_path(project)
17

18 19
      page.within '.milestone-form' do
        fill_in "milestone_title", with: '8.7'
20 21
        fill_in "milestone_start_date", with: '2016-11-16'
        fill_in "milestone_due_date", with: '2016-12-16'
22
      end
23

24 25 26
      find('input[name="commit"]').click

      expect(find('.alert-success')).to have_content('Assign some issues to this milestone.')
Pedro Moreira da Silva's avatar
Pedro Moreira da Silva committed
27
      expect(page).to have_content('Nov 16, 2016–Dec 16, 2016')
28 29 30
    end
  end

31 32
  describe 'Open a milestone with closed issues' do
    it 'shows an informative message' do
33 34
      milestone = create(:milestone, project: project, title: 8.7)

35
      create(:issue, title: "Bugfix1", project: project, milestone: milestone, state: "closed")
36
      visit project_milestone_path(project, milestone)
37 38 39 40

      expect(find('.alert-success')).to have_content('All issues for this milestone are closed. You may close this milestone now.')
    end
  end
41

42 43
  describe 'Open a project milestone with an existing title' do
    it 'displays validation message when there is a project milestone with same title' do
44 45
      milestone = create(:milestone, project: project, title: 8.7)

46
      visit new_project_milestone_path(project)
47 48 49 50 51
      page.within '.milestone-form' do
        fill_in "milestone_title", with: milestone.title
      end
      find('input[name="commit"]').click

Felipe Artur's avatar
Felipe Artur committed
52 53 54
      expect(find('.alert-danger')).to have_content('already being used for another group or project milestone.')
    end

55
    it 'displays validation message when there is a group milestone with same title' do
Felipe Artur's avatar
Felipe Artur committed
56 57 58 59 60 61 62 63 64 65
      milestone = create(:milestone, project_id: nil, group: project.group, title: 8.7)

      visit new_group_milestone_path(project.group)

      page.within '.milestone-form' do
        fill_in "milestone_title", with: milestone.title
      end
      find('input[name="commit"]').click

      expect(find('.alert-danger')).to have_content('already being used for another group or project milestone.')
66 67
    end
  end
68

69 70
  describe 'Open a milestone', :js do
    it 'shows total issue time spent correctly when no time has been logged' do
71 72 73 74
      milestone = create(:milestone, project: project, title: 8.7)

      visit project_milestone_path(project, milestone)

75 76 77 78
      wait_for_requests

      page.within('.time-tracking-no-tracking-pane') do
        expect(page).to have_content 'No estimate or time spent'
79 80 81
      end
    end

82
    it 'shows total issue time spent' do
83 84 85
      milestone = create(:milestone, project: project, title: 8.7)
      issue1 = create(:issue, project: project, milestone: milestone)
      issue2 = create(:issue, project: project, milestone: milestone)
86
      issue1.spend_time(duration: 3600, user_id: user.id)
87
      issue1.save!
88
      issue2.spend_time(duration: 7200, user_id: user.id)
89 90 91 92
      issue2.save!

      visit project_milestone_path(project, milestone)

93 94 95 96
      wait_for_requests

      page.within('.time-tracking-spend-only-pane') do
        expect(page).to have_content 'Spent: 3h'
97 98 99
      end
    end
  end
100

101 102
  describe 'Deleting a milestone' do
    it "The delete milestone button does not show for unauthorized users" do
103 104 105 106 107 108 109 110
      create(:milestone, project: project, title: 8.7)
      sign_out(user)

      visit group_milestones_path(group)

      expect(page).to have_selector('.js-delete-milestone-button', count: 0)
    end
  end
111

112
  describe 'deprecation popover', :js do
113 114 115 116 117 118 119
    it 'opens deprecation popover' do
      milestone = create(:milestone, project: project)

      visit group_milestone_path(group, milestone, title: milestone.title)

      expect(page).to have_selector('.milestone-deprecation-message')

120
      find('.milestone-deprecation-message .js-popover-link').click
121

Clement Ho's avatar
Clement Ho committed
122
      expect(page).to have_selector('.popover')
123 124
    end
  end
125
end