BigW Consortium Gitlab

todos_sorting_spec.rb 3.97 KB
Newer Older
Felipe Artur committed
1 2
require 'spec_helper'

3
feature 'Dashboard > User sorts todos' do
Felipe Artur committed
4 5 6 7 8 9 10
  let(:user)    { create(:user) }
  let(:project) { create(:empty_project) }

  let(:label_1) { create(:label, title: 'label_1', project: project, priority: 1) }
  let(:label_2) { create(:label, title: 'label_2', project: project, priority: 2) }
  let(:label_3) { create(:label, title: 'label_3', project: project, priority: 3) }

11 12 13
  before do
    project.team << [user, :developer]
  end
Felipe Artur committed
14

15 16 17 18 19
  context 'sort options' do
    let(:issue_1) { create(:issue, title: 'issue_1', project: project) }
    let(:issue_2) { create(:issue, title: 'issue_2', project: project) }
    let(:issue_3) { create(:issue, title: 'issue_3', project: project) }
    let(:issue_4) { create(:issue, title: 'issue_4', project: project) }
Felipe Artur committed
20

21
    let!(:merge_request_1) { create(:merge_request, source_project: project, title: 'merge_request_1') }
22 23 24 25 26 27 28 29 30 31 32 33 34

    before do
      create(:todo, user: user, project: project, target: issue_4, created_at: 5.hours.ago)
      create(:todo, user: user, project: project, target: issue_2, created_at: 4.hours.ago)
      create(:todo, user: user, project: project, target: issue_3, created_at: 3.hours.ago)
      create(:todo, user: user, project: project, target: issue_1, created_at: 2.hours.ago)
      create(:todo, user: user, project: project, target: merge_request_1, created_at: 1.hour.ago)

      merge_request_1.labels << label_1
      issue_3.labels         << label_1
      issue_2.labels         << label_3
      issue_1.labels         << label_2

35
      sign_in(user)
36 37 38
      visit dashboard_todos_path
    end

39 40
    it 'sorts with oldest created todos first' do
      click_link 'Last created'
41 42

      results_list = page.find('.todos-list')
43 44 45 46 47
      expect(results_list.all('p')[0]).to have_content('merge_request_1')
      expect(results_list.all('p')[1]).to have_content('issue_1')
      expect(results_list.all('p')[2]).to have_content('issue_3')
      expect(results_list.all('p')[3]).to have_content('issue_2')
      expect(results_list.all('p')[4]).to have_content('issue_4')
48
    end
Felipe Artur committed
49

50 51
    it 'sorts with newest created todos first' do
      click_link 'Oldest created'
Felipe Artur committed
52

53
      results_list = page.find('.todos-list')
54 55 56 57 58
      expect(results_list.all('p')[0]).to have_content('issue_4')
      expect(results_list.all('p')[1]).to have_content('issue_2')
      expect(results_list.all('p')[2]).to have_content('issue_3')
      expect(results_list.all('p')[3]).to have_content('issue_1')
      expect(results_list.all('p')[4]).to have_content('merge_request_1')
59 60
    end

61 62
    it 'sorts by label priority' do
      click_link 'Label priority'
63 64

      results_list = page.find('.todos-list')
65 66 67 68 69
      expect(results_list.all('p')[0]).to have_content('issue_3')
      expect(results_list.all('p')[1]).to have_content('merge_request_1')
      expect(results_list.all('p')[2]).to have_content('issue_1')
      expect(results_list.all('p')[3]).to have_content('issue_2')
      expect(results_list.all('p')[4]).to have_content('issue_4')
70
    end
Felipe Artur committed
71 72
  end

73 74 75 76 77 78 79 80 81 82 83 84 85
  context 'issues and merge requests' do
    let(:issue_1) { create(:issue, id: 10000, title: 'issue_1', project: project) }
    let(:issue_2) { create(:issue, id: 10001, title: 'issue_2', project: project) }
    let(:merge_request_1) { create(:merge_request, id: 10000, title: 'merge_request_1', source_project: project) }

    before do
      issue_1.labels << label_1
      issue_2.labels << label_2

      create(:todo, user: user, project: project, target: issue_1)
      create(:todo, user: user, project: project, target: issue_2)
      create(:todo, user: user, project: project, target: merge_request_1)

86
      gitlab_sign_in(user)
87 88 89
      visit dashboard_todos_path
    end

90
    it "doesn't mix issues and merge requests label priorities" do
91
      click_link 'Label priority'
Felipe Artur committed
92

93
      results_list = page.find('.todos-list')
94 95 96
      expect(results_list.all('p')[0]).to have_content('issue_1')
      expect(results_list.all('p')[1]).to have_content('issue_2')
      expect(results_list.all('p')[2]).to have_content('merge_request_1')
97
    end
Felipe Artur committed
98 99
  end
end