BigW Consortium Gitlab

issuable.rb 5.69 KB
Newer Older
1 2 3 4
module SharedIssuable
  include Spinach::DSL

  def edit_issuable
Phil Hughes committed
5
    find('.issuable-edit', visible: true).click
6 7
  end

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
  step 'project "Community" has "Community issue" open issue' do
    create_issuable_for_project(
      project_name: 'Community',
      title: 'Community issue'
    )
  end

  step 'project "Community" has "Community fix" open merge request' do
    create_issuable_for_project(
      project_name: 'Community',
      type: :merge_request,
      title: 'Community fix'
    )
  end

  step 'project "Enterprise" has "Enterprise issue" open issue' do
    create_issuable_for_project(
      project_name: 'Enterprise',
      title: 'Enterprise issue'
    )
  end

  step 'project "Enterprise" has "Enterprise fix" open merge request' do
    create_issuable_for_project(
      project_name: 'Enterprise',
      type: :merge_request,
      title: 'Enterprise fix'
    )
  end

  step 'I leave a comment referencing issue "Community issue"' do
    leave_reference_comment(
      issuable: Issue.find_by(title: 'Community issue'),
      from_project_name: 'Enterprise'
    )
  end

  step 'I leave a comment referencing issue "Community fix"' do
    leave_reference_comment(
      issuable: MergeRequest.find_by(title: 'Community fix'),
      from_project_name: 'Enterprise'
    )
  end

  step 'I visit issue page "Enterprise issue"' do
    issue = Issue.find_by(title: 'Enterprise issue')
    visit namespace_project_issue_path(issue.project.namespace, issue.project, issue)
  end

  step 'I visit merge request page "Enterprise fix"' do
    mr = MergeRequest.find_by(title: 'Enterprise fix')
    visit namespace_project_merge_request_path(mr.target_project.namespace, mr.target_project, mr)
  end

  step 'I visit issue page "Community issue"' do
    issue = Issue.find_by(title: 'Community issue')
    visit namespace_project_issue_path(issue.project.namespace, issue.project, issue)
  end

  step 'I visit issue page "Community fix"' do
    mr = MergeRequest.find_by(title: 'Community fix')
    visit namespace_project_merge_request_path(mr.target_project.namespace, mr.target_project, mr)
  end

  step 'I should not see any related merge requests' do
    page.within '.issue-details' do
74
      expect(page).not_to have_content('#merge-requests .merge-requests-title')
75 76 77 78
    end
  end

  step 'I should see the "Enterprise fix" related merge request' do
79
    page.within '#merge-requests .merge-requests-title' do
80
      expect(page).to have_content('1 Related Merge Request')
81 82 83
    end

    page.within '#merge-requests ul' do
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
      expect(page).to have_content('Enterprise fix')
    end
  end

  step 'I should see a note linking to "Enterprise fix" merge request' do
    visible_note(
      issuable: MergeRequest.find_by(title: 'Enterprise fix'),
      from_project_name: 'Community',
      user_name: 'Mary Jane'
    )
  end

  step 'I should see a note linking to "Enterprise issue" issue' do
    visible_note(
      issuable: Issue.find_by(title: 'Enterprise issue'),
      from_project_name: 'Community',
      user_name: 'Mary Jane'
    )
  end

104 105 106 107 108 109 110
  step 'I click link "Edit" for the merge request' do
    edit_issuable
  end

  step 'I click link "Edit" for the issue' do
    edit_issuable
  end
111

112 113
  step 'I sort the list by "Oldest updated"' do
    find('button.dropdown-toggle.btn').click
114
    page.within('.content ul.dropdown-menu.dropdown-menu-align-right li') do
115 116 117 118
      click_link "Oldest updated"
    end
  end

119 120 121
  step 'I sort the list by "Least popular"' do
    find('button.dropdown-toggle.btn').click

122
    page.within('.content ul.dropdown-menu.dropdown-menu-align-right li') do
123 124 125 126 127 128 129
      click_link 'Least popular'
    end
  end

  step 'I sort the list by "Most popular"' do
    find('button.dropdown-toggle.btn').click

130
    page.within('.content ul.dropdown-menu.dropdown-menu-align-right li') do
131 132 133 134
      click_link 'Most popular'
    end
  end

135
  step 'The list should be sorted by "Oldest updated"' do
136
    page.within('.content div.dropdown.inline.prepend-left-10') do
137 138 139 140
      expect(page.find('button.dropdown-toggle.btn')).to have_content('Oldest updated')
    end
  end

141 142 143 144 145 146 147 148 149 150 151 152
  step 'I should see "1 of 1" in the sidebar' do
    expect_sidebar_content('1 of 1')
  end

  step 'I should see "1 of 2" in the sidebar' do
    expect_sidebar_content('1 of 2')
  end

  step 'I should see "2 of 2" in the sidebar' do
    expect_sidebar_content('2 of 2')
  end

153 154 155 156
  step 'I should see "3 of 3" in the sidebar' do
    expect_sidebar_content('3 of 3')
  end

157 158 159 160 161 162
  step 'I click link "Next" in the sidebar' do
    page.within '.issuable-sidebar' do
      click_link 'Next'
    end
  end

163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
  def create_issuable_for_project(project_name:, title:, type: :issue)
    project = Project.find_by(name: project_name)

    attrs = {
      title: title,
      author: project.users.first,
      description: '# Description header'
    }

    case type
    when :issue
      attrs.merge!(project: project)
    when :merge_request
      attrs.merge!(
        source_project: project,
        target_project: project,
        source_branch: 'fix',
        target_branch: 'master'
      )
    end

    create(type, attrs)
  end

  def leave_reference_comment(issuable:, from_project_name:)
    project = Project.find_by(name: from_project_name)

    page.within('.js-main-target-form') do
      fill_in 'note[note]', with: "##{issuable.to_reference(project)}"
Phil Hughes committed
192
      click_button 'Comment'
193 194 195 196 197 198 199 200 201 202
    end
  end

  def visible_note(issuable:, from_project_name:, user_name:)
    project = Project.find_by(name: from_project_name)

    expect(page).to have_content(user_name)
    expect(page).to have_content("mentioned in #{issuable.class.to_s.titleize.downcase} #{issuable.to_reference(project)}")
  end

203 204 205 206 207 208
  def expect_sidebar_content(content)
    page.within '.issuable-sidebar' do
      expect(page).to have_content content
    end
  end

209
end