Commit a7ccf27d authored by Alexander Randa's avatar Alexander Randa

Replaces 'dashboard/merge_requests' spinach with rspec

parent 245be4ce
---
title: Replace 'dashboard/merge_requests' spinach with rspec
merge_request: 12440
author: Alexander Randa (@randaalex)
@dashboard
Feature: Dashboard Merge Requests
Background:
Given I sign in as a user
And I have authored merge requests
And I have assigned merge requests
And I have other merge requests
And I visit dashboard merge requests page
Scenario: I should see assigned merge_requests
Then I should see merge requests assigned to me
@javascript
Scenario: I should see authored merge_requests
When I click "Authored by me" link
Then I should see merge requests authored by me
@javascript
Scenario: I should see all merge_requests
When I click "All" link
Then I should see all merge requests
class Spinach::Features::DashboardMergeRequests < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
include Select2Helper
step 'I should see merge requests assigned to me' do
should_see(assigned_merge_request)
should_see(assigned_merge_request_from_fork)
should_not_see(authored_merge_request)
should_not_see(authored_merge_request_from_fork)
should_not_see(other_merge_request)
end
step 'I should see merge requests authored by me' do
should_see(authored_merge_request)
should_see(authored_merge_request_from_fork)
should_not_see(assigned_merge_request)
should_not_see(assigned_merge_request_from_fork)
should_not_see(other_merge_request)
end
step 'I should see all merge requests' do
should_see(authored_merge_request)
should_see(assigned_merge_request)
should_see(other_merge_request)
end
step 'I have authored merge requests' do
authored_merge_request
authored_merge_request_from_fork
end
step 'I have assigned merge requests' do
assigned_merge_request
assigned_merge_request_from_fork
end
step 'I have other merge requests' do
other_merge_request
end
step 'I click "Authored by me" link' do
find("#assignee_id").set("")
find(".js-author-search", match: :first).click
find(".dropdown-menu-author li a", match: :first, text: current_user.to_reference).click
end
step 'I click "All" link' do
find(".js-author-search").click
expect(page).to have_selector(".dropdown-menu-author li a")
find(".dropdown-menu-author li a", match: :first).click
expect(page).not_to have_selector(".dropdown-menu-author li a")
find(".js-assignee-search").click
expect(page).to have_selector(".dropdown-menu-assignee li a")
find(".dropdown-menu-assignee li a", match: :first).click
expect(page).not_to have_selector(".dropdown-menu-assignee li a")
end
def should_see(merge_request)
expect(page).to have_content(merge_request.title[0..10])
end
def should_not_see(merge_request)
expect(page).not_to have_content(merge_request.title[0..10])
end
def assigned_merge_request
@assigned_merge_request ||= create :merge_request,
assignee: current_user,
target_project: project,
source_project: project
end
def authored_merge_request
@authored_merge_request ||= create :merge_request,
source_branch: 'markdown',
author: current_user,
target_project: project,
source_project: project
end
def other_merge_request
@other_merge_request ||= create :merge_request,
source_branch: 'fix',
target_project: project,
source_project: project
end
def authored_merge_request_from_fork
@authored_merge_request_from_fork ||= create :merge_request,
source_branch: 'feature_conflict',
author: current_user,
target_project: public_project,
source_project: forked_project
end
def assigned_merge_request_from_fork
@assigned_merge_request_from_fork ||= create :merge_request,
source_branch: 'markdown',
assignee: current_user,
target_project: public_project,
source_project: forked_project
end
def project
@project ||= begin
project = create(:project, :repository)
project.team << [current_user, :master]
project
end
end
def public_project
@public_project ||= create(:project, :public, :repository)
end
def forked_project
@forked_project ||= Projects::ForkService.new(public_project, current_user).execute
end
end
require 'spec_helper'
describe 'Dashboard Merge Requests' do
feature 'Dashboard Merge Requests' do
include FilterItemSelectHelper
let(:current_user) { create :user }
let(:project) { create(:empty_project) }
let(:project_with_merge_requests_disabled) { create(:empty_project, :merge_requests_disabled) }
before do
[project, project_with_merge_requests_disabled].each { |project| project.team << [current_user, :master] }
let(:public_project) { create(:empty_project, :public, :repository) }
let(:forked_project) { Projects::ForkService.new(public_project, current_user).execute }
gitlab_sign_in(current_user)
before do
project.add_master(current_user)
sign_in(current_user)
end
describe 'new merge request dropdown' do
context 'new merge request dropdown' do
let(:project_with_disabled_merge_requests) { create(:empty_project, :merge_requests_disabled) }
before do
project_with_disabled_merge_requests.add_master(current_user)
visit merge_requests_dashboard_path
end
......@@ -21,26 +27,87 @@ describe 'Dashboard Merge Requests' do
page.within('.select2-results') do
expect(page).to have_content(project.name_with_namespace)
expect(page).not_to have_content(project_with_merge_requests_disabled.name_with_namespace)
expect(page).not_to have_content(project_with_disabled_merge_requests.name_with_namespace)
end
end
end
it 'should show an empty state' do
visit merge_requests_dashboard_path(assignee_id: current_user.id)
context 'no merge requests exist' do
it 'shows an empty state' do
visit merge_requests_dashboard_path(assignee_id: current_user.id)
expect(page).to have_selector('.empty-state')
expect(page).to have_selector('.empty-state')
end
end
context 'if there are merge requests' do
before do
create(:merge_request, assignee: current_user, source_project: project)
context 'merge requests exist' do
let!(:assigned_merge_request) do
create(:merge_request, assignee: current_user, target_project: project, source_project: project)
end
let!(:assigned_merge_request_from_fork) do
create(:merge_request,
source_branch: 'markdown', assignee: current_user,
target_project: public_project, source_project: forked_project
)
end
let!(:authored_merge_request) do
create(:merge_request,
source_branch: 'markdown', author: current_user,
target_project: project, source_project: project
)
end
let!(:authored_merge_request_from_fork) do
create(:merge_request,
source_branch: 'feature_conflict',
author: current_user,
target_project: public_project, source_project: forked_project
)
end
let!(:other_merge_request) do
create(:merge_request,
source_branch: 'fix',
target_project: project, source_project: project
)
end
before do
visit merge_requests_dashboard_path(assignee_id: current_user.id)
end
it 'should not show an empty state' do
expect(page).not_to have_selector('.empty-state')
it 'shows assigned merge requests' do
expect(page).to have_content(assigned_merge_request.title)
expect(page).to have_content(assigned_merge_request_from_fork.title)
expect(page).not_to have_content(authored_merge_request.title)
expect(page).not_to have_content(authored_merge_request_from_fork.title)
expect(page).not_to have_content(other_merge_request.title)
end
it 'shows authored merge requests', js: true do
filter_item_select('Any Assignee', '.js-assignee-search')
filter_item_select(current_user.to_reference, '.js-author-search')
expect(page).to have_content(authored_merge_request.title)
expect(page).to have_content(authored_merge_request_from_fork.title)
expect(page).not_to have_content(assigned_merge_request.title)
expect(page).not_to have_content(assigned_merge_request_from_fork.title)
expect(page).not_to have_content(other_merge_request.title)
end
it 'shows all merge requests', js: true do
filter_item_select('Any Assignee', '.js-assignee-search')
filter_item_select('Any Author', '.js-author-search')
expect(page).to have_content(authored_merge_request.title)
expect(page).to have_content(authored_merge_request_from_fork.title)
expect(page).to have_content(assigned_merge_request.title)
expect(page).to have_content(assigned_merge_request_from_fork.title)
expect(page).to have_content(other_merge_request.title)
end
end
end
require 'spec_helper'
describe 'Dashboard > milestone filter', :feature, :js do
feature 'Dashboard > milestone filter', :feature, :js do
include FilterItemSelectHelper
let(:user) { create(:user) }
let(:project) { create(:project, name: 'test', namespace: user.namespace) }
let(:milestone) { create(:milestone, title: "v1.0", project: project) }
let(:milestone2) { create(:milestone, title: "v2.0", project: project) }
let(:milestone) { create(:milestone, title: 'v1.0', project: project) }
let(:milestone2) { create(:milestone, title: 'v2.0', project: project) }
let!(:issue) { create :issue, author: user, project: project, milestone: milestone }
let!(:issue2) { create :issue, author: user, project: project, milestone: milestone2 }
......@@ -22,17 +24,11 @@ describe 'Dashboard > milestone filter', :feature, :js do
end
context 'filtering by milestone' do
milestone_select = '.js-milestone-select'
milestone_select_selector = '.js-milestone-select'
before do
find(milestone_select).click
wait_for_requests
page.within('.dropdown-content') do
click_link 'v1.0'
end
find(milestone_select).click
filter_item_select('v1.0', milestone_select_selector)
find(milestone_select_selector).click
wait_for_requests
end
......@@ -49,7 +45,7 @@ describe 'Dashboard > milestone filter', :feature, :js do
expect(find('.milestone-filter')).not_to have_selector('.dropdown.open')
find(milestone_select).click
find(milestone_select_selector).click
expect(find('.dropdown-content')).to have_selector('a.is-active', count: 1)
expect(find('.dropdown-content a.is-active')).to have_content('v1.0')
......
# Helper allows you to select value from filter-items
#
# Params
# value - value for select
# selector - css selector of item
#
# Usage:
#
# filter_item_select('Any Author', '.js-author-search')
#
module FilterItemSelectHelper
def filter_item_select(value, selector)
find(selector).click
wait_for_requests
page.within('.dropdown-content') do
click_link value
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment