todos.rb 5.66 KB
Newer Older
1
class Spinach::Features::DashboardTodos < Spinach::FeatureSteps
2 3 4 5
  include SharedAuthentication
  include SharedPaths
  include SharedProject
  include SharedUser
6
  include Select2Helper
7 8 9 10 11

  step '"John Doe" is a developer of project "Shop"' do
    project.team << [john_doe, :developer]
  end

12 13 14 15 16 17 18 19
  step 'I am a developer of project "Enterprise"' do
    enterprise.team << [current_user, :developer]
  end

  step '"Mary Jane" is a developer of project "Shop"' do
    project.team << [john_doe, :developer]
  end

20 21 22
  step 'I have todos' do
    create(:todo, user: current_user, project: project, author: mary_jane, target: issue, action: Todo::MENTIONED)
    create(:todo, user: current_user, project: project, author: john_doe, target: issue, action: Todo::ASSIGNED)
23
    note = create(:note, author: john_doe, noteable: issue, note: "#{current_user.to_reference} Wdyt?", project: project)
24 25
    create(:todo, user: current_user, project: project, author: john_doe, target: issue, action: Todo::MENTIONED, note: note)
    create(:todo, user: current_user, project: project, author: john_doe, target: merge_request, action: Todo::ASSIGNED)
26 27
  end

28
  step 'I should see todos assigned to me' do
29
    page.within('.todos-pending-count') { expect(page).to have_content '4' }
Douwe Maan's avatar
Douwe Maan committed
30
    expect(page).to have_content 'To do 4'
31 32 33
    expect(page).to have_content 'Done 0'

    expect(page).to have_link project.name_with_namespace
34
    should_see_todo(1, "John Doe assigned you merge request #{merge_request.to_reference}", merge_request.title)
35 36 37
    should_see_todo(2, "John Doe mentioned you on issue #{issue.to_reference}", "#{current_user.to_reference} Wdyt?")
    should_see_todo(3, "John Doe assigned you issue #{issue.to_reference}", issue.title)
    should_see_todo(4, "Mary Jane mentioned you on issue #{issue.to_reference}", issue.title)
38 39
  end

40 41
  step 'I mark the todo as done' do
    page.within('.todo:nth-child(1)') do
42 43
      click_link 'Done'
    end
44

45
    page.within('.todos-pending-count') { expect(page).to have_content '3' }
Douwe Maan's avatar
Douwe Maan committed
46
    expect(page).to have_content 'To do 3'
47
    expect(page).to have_content 'Done 1'
48
    should_not_see_todo "John Doe assigned you merge request #{merge_request.to_reference}"
49 50
  end

51 52 53 54 55 56 57 58 59 60 61 62 63 64
  step 'I mark all todos as done' do
    click_link 'Mark all as done'

    page.within('.todos-pending-count') { expect(page).to have_content '0' }
    expect(page).to have_content 'To do 0'
    expect(page).to have_content 'Done 4'
    expect(page).not_to have_link project.name_with_namespace
    should_not_see_todo "John Doe assigned you merge request #{merge_request.to_reference}"
    should_not_see_todo "John Doe mentioned you on issue #{issue.to_reference}"
    should_not_see_todo "John Doe assigned you issue #{issue.to_reference}"
    should_not_see_todo "Mary Jane mentioned you on issue #{issue.to_reference}"
  end

  step 'I should see the todo marked as done' do
65
    click_link 'Done 1'
66 67 68

    expect(page).to have_link project.name_with_namespace
    should_see_todo(1, "John Doe assigned you merge request #{merge_request.to_reference}", merge_request.title, false)
69 70
  end

71
  step 'I should see all todos marked as done' do
72 73
    click_link 'Done 4'

74
    expect(page).to have_link project.name_with_namespace
75
    should_see_todo(1, "John Doe assigned you merge request #{merge_request.to_reference}", merge_request.title, false)
76 77 78
    should_see_todo(2, "John Doe mentioned you on issue #{issue.to_reference}", "#{current_user.to_reference} Wdyt?", false)
    should_see_todo(3, "John Doe assigned you issue #{issue.to_reference}", issue.title, false)
    should_see_todo(4, "Mary Jane mentioned you on issue #{issue.to_reference}", issue.title, false)
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  end

  step 'I filter by "Enterprise"' do
    select2(enterprise.id, from: "#project_id")
  end

  step 'I filter by "John Doe"' do
    select2(john_doe.id, from: "#author_id")
  end

  step 'I filter by "Issue"' do
    select2('Issue', from: "#type")
  end

  step 'I filter by "Mentioned"' do
94
    select2("#{Todo::MENTIONED}", from: '#action_id')
95 96
  end

97
  step 'I should not see todos' do
Douwe Maan's avatar
Douwe Maan committed
98
    expect(page).to have_content "You're all done!"
99 100
  end

101
  step 'I should not see todos related to "Mary Jane" in the list' do
102
    should_not_see_todo "Mary Jane mentioned you on issue #{issue.to_reference}"
103 104
  end

105
  step 'I should not see todos related to "Merge Requests" in the list' do
106
    should_not_see_todo "John Doe assigned you merge request #{merge_request.to_reference}"
107 108
  end

109
  step 'I should not see todos related to "Assignments" in the list' do
110
    should_not_see_todo "John Doe assigned you merge request #{merge_request.to_reference}"
111
    should_not_see_todo "John Doe assigned you issue #{issue.to_reference}"
112 113
  end

114
  step 'I click on the todo' do
Annabel Dunstone's avatar
Annabel Dunstone committed
115
    find('.todo:nth-child(1)').click
116 117 118 119 120 121
  end

  step 'I should be directed to the corresponding page' do
    page.should have_css('.identifier', text: 'Merge Request !1')
  end

122 123
  def should_see_todo(position, title, body, pending = true)
    page.within(".todo:nth-child(#{position})") do
124 125 126 127 128 129
      expect(page).to have_content title
      expect(page).to have_content body

      if pending
        expect(page).to have_link 'Done'
      else
130
        expect(page).not_to have_link 'Done'
131
      end
132 133 134
    end
  end

135
  def should_not_see_todo(title)
136
    expect(page).not_to have_content title
137 138 139 140 141 142
  end

  def john_doe
    @john_doe ||= user_exists("John Doe", { username: "john_doe" })
  end

143 144 145 146 147 148 149 150 151 152 153 154 155 156
  def mary_jane
    @mary_jane ||= user_exists("Mary Jane", { username: "mary_jane" })
  end

  def enterprise
    @enterprise ||= Project.find_by(name: 'Enterprise')
  end

  def issue
    @issue ||= create(:issue, assignee: current_user, project: project)
  end

  def merge_request
    @merge_request ||= create(:merge_request, assignee: current_user, source_project: project)
157 158
  end
end