summaryrefslogtreecommitdiff
path: root/features/steps/dashboard/todos.rb
blob: eb906a55a831a20125797e06fa5ec0f89c4aedd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
class Spinach::Features::DashboardTodos < Spinach::FeatureSteps
  include SharedAuthentication
  include SharedPaths
  include SharedProject
  include SharedUser

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

  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

  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)
    note = create(:note, author: john_doe, noteable: issue, note: "#{current_user.to_reference} Wdyt?", project: project)
    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)
  end

  step 'I should see todos assigned to me' do
    merge_request_reference = merge_request.to_reference(full: true)
    issue_reference = issue.to_reference(full: true)

    page.within('.todos-pending-count') { expect(page).to have_content '4' }
    expect(page).to have_content 'To do 4'
    expect(page).to have_content 'Done 0'

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

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

    page.within('.todos-pending-count') { expect(page).to have_content '3' }
    expect(page).to have_content 'To do 3'
    expect(page).to have_content 'Done 1'
    should_see_todo(1, "John Doe assigned you merge request #{merge_request.to_reference(full: true)}", merge_request.title, state: :done_reversible)
  end

  step 'I mark all todos as done' do
    merge_request_reference = merge_request.to_reference(full: true)
    issue_reference = issue.to_reference(full: true)

    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).to have_content "You're all done!"
    expect('.prepend-top-default').not_to have_link project.name_with_namespace
    should_not_see_todo "John Doe assigned you merge request #{merge_request_reference}"
    should_not_see_todo "John Doe mentioned you on issue #{issue_reference}"
    should_not_see_todo "John Doe assigned you issue #{issue_reference}"
    should_not_see_todo "Mary Jane mentioned you on issue #{issue_reference}"
  end

  step 'I should see the todo marked as done' do
    click_link 'Done 1'

    expect(page).to have_link project.name_with_namespace
    should_see_todo(1, "John Doe assigned you merge request #{merge_request.to_reference(full: true)}", merge_request.title, state: :done_irreversible)
  end

  step 'I should see all todos marked as done' do
    merge_request_reference = merge_request.to_reference(full: true)
    issue_reference = issue.to_reference(full: true)

    click_link 'Done 4'

    expect(page).to have_link project.name_with_namespace
    should_see_todo(1, "John Doe assigned you merge request #{merge_request_reference}", merge_request.title, state: :done_irreversible)
    should_see_todo(2, "John Doe mentioned you on issue #{issue_reference}", "#{current_user.to_reference} Wdyt?", state: :done_irreversible)
    should_see_todo(3, "John Doe assigned you issue #{issue_reference}", issue.title, state: :done_irreversible)
    should_see_todo(4, "Mary Jane mentioned you on issue #{issue_reference}", issue.title, state: :done_irreversible)
  end

  step 'I filter by "Enterprise"' do
    click_button 'Project'
    page.within '.dropdown-menu-project' do
      click_link enterprise.name_with_namespace
    end
  end

  step 'I filter by "John Doe"' do
    click_button 'Author'
    page.within '.dropdown-menu-author' do
      click_link john_doe.username
    end
  end

  step 'I filter by "Issue"' do
    click_button 'Type'
    page.within '.dropdown-menu-type' do
      click_link 'Issue'
    end
  end

  step 'I filter by "Mentioned"' do
    click_button 'Action'
    page.within '.dropdown-menu-action' do
      click_link 'Mentioned'
    end
  end

  step 'I should not see todos' do
    expect(page).to have_content "You're all done!"
  end

  step 'I should not see todos related to "Mary Jane" in the list' do
    should_not_see_todo "Mary Jane mentioned you on issue #{issue.to_reference(full: true)}"
  end

  step 'I should not see todos related to "Merge Requests" in the list' do
    should_not_see_todo "John Doe assigned you merge request #{merge_request.to_reference(full: true)}"
  end

  step 'I should not see todos related to "Assignments" in the list' do
    should_not_see_todo "John Doe assigned you merge request #{merge_request.to_reference(full: true)}"
    should_not_see_todo "John Doe assigned you issue #{issue.to_reference(full: true)}"
  end

  step 'I click on the todo' do
    find('.todo:nth-child(1)').click
  end

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

  def should_see_todo(position, title, body, state: :pending)
    page.within(".todo:nth-child(#{position})") do
      expect(page).to have_content title
      expect(page).to have_content body

      if state == :pending
        expect(page).to have_link 'Done'
      elsif state == :done_reversible
        expect(page).to have_link 'Undo'
      elsif state == :done_irreversible
        expect(page).not_to have_link 'Undo'
        expect(page).not_to have_link 'Done'
      else
        raise 'Invalid state given, valid states: :pending, :done_reversible, :done_irreversible'
      end
    end
  end

  def should_not_see_todo(title)
    expect(page).not_to have_content title
  end

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

  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)
  end
end