Replace the 'search.feature' spinach test with an rspec analog

parent 20295b3d
---
title: Replace the 'search.feature' spinach test with an rspec analog
merge_request: 14248
author: Vitaliy @blackst0ne Klachkov
type: other
@dashboard
Feature: Search
Background:
Given I sign in as a user
And I own project "Shop"
And I visit dashboard search page
Scenario: I should see project I am looking for
Given I search for "Sho"
Then I should see "Shop" project link
@javascript
Scenario: I should see issues I am looking for
And project has issues
When I search for "Foo"
And I click "Issues" link
Then I should see "Foo" link in the search results
And I should not see "Bar" link in the search results
@javascript
Scenario: I should see merge requests I am looking for
And project has merge requests
When I search for "Foo"
When I click "Merge requests" link
Then I should see "Foo" link in the search results
And I should not see "Bar" link in the search results
@javascript
Scenario: I should see milestones I am looking for
And project has milestones
When I search for "Foo"
When I click "Milestones" link
Then I should see "Foo" link in the search results
And I should not see "Bar" link in the search results
@javascript
Scenario: I should see project code I am looking for
When I click project "Shop" link
And I search for "rspec"
Then I should see code results for project "Shop"
@javascript
Scenario: I should see project issues
And project has issues
When I click project "Shop" link
And I search for "Foo"
And I click "Issues" link
Then I should see "Foo" link in the search results
And I should not see "Bar" link in the search results
@javascript
Scenario: I should see project merge requests
And project has merge requests
When I click project "Shop" link
And I search for "Foo"
And I click "Merge requests" link
Then I should see "Foo" link in the search results
And I should not see "Bar" link in the search results
@javascript
Scenario: I should see project milestones
And project has milestones
When I click project "Shop" link
And I search for "Foo"
And I click "Milestones" link
Then I should see "Foo" link in the search results
And I should not see "Bar" link in the search results
@javascript
Scenario: I should see Wiki blobs
And project has Wiki content
When I click project "Shop" link
And I search for "Wiki content"
And I click "Wiki" link
Then I should see "test_wiki" link in the search results
Scenario: I logout and should see project I am looking for
Given project "Shop" is public
And I logout directly
And I visit dashboard search page
And I search for "Sho"
Then I should see "Shop" project link
@javascript
Scenario: I logout and should see issues I am looking for
Given project "Shop" is public
And I logout directly
And I visit dashboard search page
And project has issues
When I search for "Foo"
And I click "Issues" link
Then I should see "Foo" link in the search results
And I should not see "Bar" link in the search results
Scenario: I logout and should see project code I am looking for
Given project "Shop" is public
And I logout directly
When I visit project "Shop" page
And I search for "rspec" on project page
Then I should see code results for project "Shop"
class Spinach::Features::Search < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
include SharedProject
step 'I search for "Sho"' do
fill_in "dashboard_search", with: "Sho"
click_button "Search"
end
step 'I search for "Foo"' do
fill_in "dashboard_search", with: "Foo"
find('.btn-search').trigger('click')
end
step 'I search for "rspec"' do
fill_in "dashboard_search", with: "rspec"
find('.btn-search').trigger('click')
end
step 'I search for "rspec" on project page' do
fill_in "search", with: "rspec"
click_button "Go"
end
step 'I search for "Wiki content"' do
fill_in "dashboard_search", with: "content"
find('.btn-search').trigger('click')
end
step 'I click "Issues" link' do
page.within '.search-filter' do
click_link 'Issues'
end
end
step 'I click project "Shop" link' do
find('.js-search-project-dropdown').trigger('click')
page.within '.project-filter' do
click_link project.name_with_namespace
end
end
step 'I click "Merge requests" link' do
page.within '.search-filter' do
click_link 'Merge requests'
end
end
step 'I click "Milestones" link' do
page.within '.search-filter' do
click_link 'Milestones'
end
end
step 'I click "Wiki" link' do
page.within '.search-filter' do
click_link 'Wiki'
end
end
step 'I should see "Shop" project link' do
expect(page).to have_link "Shop"
end
step 'I should see code results for project "Shop"' do
page.within('.results') do
page.should have_content 'Update capybara, rspec-rails, poltergeist to recent versions'
end
end
step 'I search for "Contibuting"' do
fill_in "dashboard_search", with: "Contibuting"
click_button "Search"
end
step 'project has issues' do
create(:issue, title: "Foo", project: project)
create(:issue, title: "Bar", project: project)
end
step 'project has merge requests' do
create(:merge_request, title: "Foo", source_project: project, target_project: project)
create(:merge_request, :simple, title: "Bar", source_project: project, target_project: project)
end
step 'project has milestones' do
create(:milestone, title: "Foo", project: project)
create(:milestone, title: "Bar", project: project)
end
step 'I should see "Foo" link in the search results' do
page.within('.results') do
find(:css, '.search-results').should have_link 'Foo'
end
end
step 'I should not see "Bar" link in the search results' do
expect(find(:css, '.search-results')).not_to have_link 'Bar'
end
step 'I should see "test_wiki" link in the search results' do
page.within('.results') do
expect(find(:css, '.search-results')).to have_link 'test_wiki'
end
end
step 'project has Wiki content' do
@wiki = ::ProjectWiki.new(project, current_user)
@wiki.create_page("test_wiki", "Some Wiki content", :markdown, "first commit")
end
step 'project "Shop" is public' do
project.update_attributes(visibility_level: Project::PUBLIC)
end
end
require 'spec_helper'
describe 'User searches for code' do
let(:user) { create(:user) }
let(:project) { create(:project, :repository, namespace: user.namespace) }
context 'when signed in' do
before do
project.add_master(user)
sign_in(user)
end
it 'finds a file' do
visit(project_path(project))
page.within('.search') do
fill_in('search', with: 'application.js')
click_button('Go')
end
click_link('Code')
expect(page).to have_selector('.file-content .code')
expect(page).to have_selector("span.line[lang='javascript']")
end
context 'when on a project page', :js do
before do
visit(search_path)
end
include_examples 'top right search form'
it 'finds code' do
find('.js-search-project-dropdown').trigger('click')
page.within('.project-filter') do
click_link(project.name_with_namespace)
end
fill_in('dashboard_search', with: 'rspec')
find('.btn-search').trigger('click')
page.within('.results') do
expect(find(:css, '.search-results')).to have_content('Update capybara, rspec-rails, poltergeist to recent versions')
end
end
end
end
context 'when signed out' do
let(:project) { create(:project, :public, :repository) }
before do
visit(project_path(project))
end
it 'finds code' do
fill_in('search', with: 'rspec')
click_button('Go')
page.within('.results') do
expect(find(:css, '.search-results')).to have_content('Update capybara, rspec-rails, poltergeist to recent versions')
end
end
end
end
require 'spec_helper'
describe 'User searches for comments' do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
before do
project.add_reporter(user)
sign_in(user)
visit(project_path(project))
end
context 'when a comment is in commits' do
context 'when comment belongs to an invalid commit' do
let(:comment) { create(:note_on_commit, author: user, project: project, commit_id: 12345678, note: 'Bug here') }
it 'finds a commit' do
page.within('.search') do
fill_in('search', with: comment.note)
click_button('Go')
end
click_link('Comments')
expect(page).to have_text('Commit deleted')
expect(page).to have_text('12345678')
end
end
end
context 'when a comment is in a snippet' do
let(:snippet) { create(:project_snippet, :private, project: project, author: user, title: 'Some title') }
let(:comment) { create(:note, noteable: snippet, author: user, note: 'Supercalifragilisticexpialidocious', project: project) }
it 'finds a snippet' do
page.within('.search') do
fill_in('search', with: comment.note)
click_button('Go')
end
click_link('Comments')
expect(page).to have_link(snippet.title)
end
end
end
require 'spec_helper'
describe 'User searches for commits' do
let(:project) { create(:project, :repository) }
let(:sha) { '6d394385cf567f80a8fd85055db1ab4c5295806f' }
let(:user) { create(:user) }
before do
project.add_reporter(user)
sign_in(user)
visit(search_path(project_id: project.id))
end
context 'when searching by SHA' do
it 'finds a commit and redirects to its page' do
fill_in('search', with: sha)
click_button('Search')
expect(page).to have_current_path(project_commit_path(project, sha))
end
it 'finds a commit in uppercase and redirects to its page' do
fill_in('search', with: sha.upcase)
click_button('Search')
expect(page).to have_current_path(project_commit_path(project, sha))
end
end
context 'when searching by message' do
it 'finds a commit and holds on /search page' do
create_commit('Message referencing another sha: "deadbeef"', project, user, 'master')
fill_in('search', with: 'deadbeef')
click_button('Search')
expect(page).to have_current_path('/search', only_path: true)
end
it 'finds multiple commits' do
fill_in('search', with: 'See merge request')
click_button('Search')
click_link('Commits')
expect(page).to have_selector('.commit-row-description', count: 9)
end
end
end
require 'spec_helper'
describe 'User searches for issues', :js do
let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) }
let!(:issue1) { create(:issue, title: 'Foo', project: project) }
let!(:issue2) { create(:issue, title: 'Bar', project: project) }
context 'when signed in' do
before do
project.add_master(user)
sign_in(user)
visit(search_path)
end
include_examples 'top right search form'
it 'finds an issue' do
fill_in('dashboard_search', with: issue1.title)
find('.btn-search').trigger('click')
page.within('.search-filter') do
click_link('Issues')
end
page.within('.results') do
expect(find(:css, '.search-results')).to have_link(issue1.title).and have_no_link(issue2.title)
end
end
context 'when on a project page' do
it 'finds an issue' do
find('.js-search-project-dropdown').trigger('click')
page.within('.project-filter') do
click_link(project.name_with_namespace)
end
fill_in('dashboard_search', with: issue1.title)
find('.btn-search').trigger('click')
page.within('.search-filter') do
click_link('Issues')
end
page.within('.results') do
expect(find(:css, '.search-results')).to have_link(issue1.title).and have_no_link(issue2.title)
end
end
end
end
context 'when signed out' do
let(:project) { create(:project, :public) }
before do
visit(search_path)
end
include_examples 'top right search form'
it 'finds an issue' do
fill_in('dashboard_search', with: issue1.title)
find('.btn-search').trigger('click')
page.within('.search-filter') do
click_link('Issues')
end
page.within('.results') do
expect(find(:css, '.search-results')).to have_link(issue1.title).and have_no_link(issue2.title)
end
end
end
end
require 'spec_helper'
describe 'User searches for merge requests', :js do
let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) }
let!(:merge_request1) { create(:merge_request, title: 'Foo', source_project: project, target_project: project) }
let!(:merge_request2) { create(:merge_request, :simple, title: 'Bar', source_project: project, target_project: project) }
before do
project.add_master(user)
sign_in(user)
visit(search_path)
end
include_examples 'top right search form'
it 'finds a merge request' do
fill_in('dashboard_search', with: merge_request1.title)
find('.btn-search').trigger('click')
page.within('.search-filter') do
click_link('Merge requests')
end
page.within('.results') do
expect(find(:css, '.search-results')).to have_link(merge_request1.title).and have_no_link(merge_request2.title)
end
end
context 'when on a project page' do
it 'finds a merge request' do
find('.js-search-project-dropdown').trigger('click')
page.within('.project-filter') do
click_link(project.name_with_namespace)
end
fill_in('dashboard_search', with: merge_request1.title)
find('.btn-search').trigger('click')
page.within('.search-filter') do
click_link('Merge requests')
end
page.within('.results') do
expect(find(:css, '.search-results')).to have_link(merge_request1.title).and have_no_link(merge_request2.title)
end
end
end
end
require 'spec_helper'
describe 'User searches for milestones', :js do
let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) }
let!(:milestone1) { create(:milestone, title: 'Foo', project: project) }
let!(:milestone2) { create(:milestone, title: 'Bar', project: project) }
before do
project.add_master(user)
sign_in(user)
visit(search_path)
end
include_examples 'top right search form'
it 'finds a milestone' do
fill_in('dashboard_search', with: milestone1.title)
find('.btn-search').trigger('click')
page.within('.search-filter') do
click_link('Milestones')
end
page.within('.results') do
expect(find(:css, '.search-results')).to have_link(milestone1.title).and have_no_link(milestone2.title)
end
end
context 'when on a project page' do
it 'finds a milestone' do
find('.js-search-project-dropdown').trigger('click')
page.within('.project-filter') do
click_link(project.name_with_namespace)
end
fill_in('dashboard_search', with: milestone1.title)
find('.btn-search').trigger('click')
page.within('.search-filter') do
click_link('Milestones')
end
page.within('.results') do
expect(find(:css, '.search-results')).to have_link(milestone1.title).and have_no_link(milestone2.title)
end
end
end
end
require 'spec_helper'
describe 'User searches for projects' do
let!(:project) { create(:project, :public, name: 'Shop') }
context 'when signed out' do
include_examples 'top right search form'
it 'finds a project' do
visit(search_path)
fill_in('dashboard_search', with: project.name[0..3])
click_button('Search')
expect(page).to have_link(project.name)
end
it 'preserves the group being searched in' do
visit(search_path(group_id: project.namespace.id))
fill_in('search', with: 'foo')
click_button('Search')
expect(find('#group_id', visible: false).value).to eq(project.namespace.id.to_s)
end
it 'preserves the project being searched in' do
visit(search_path(project_id: project.id))
fill_in('search', with: 'foo')
click_button('Search')
expect(find('#project_id', visible: false).value).to eq(project.id.to_s)
end
end
end
require 'spec_helper'
describe 'User searches for wiki pages', :js do
let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) }
let!(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: { title: 'test_wiki', content: 'Some Wiki content' }) }
before do
project.add_master(user)
sign_in(user)
visit(search_path)
end
include_examples 'top right search form'
it 'finds a page' do
find('.js-search-project-dropdown').trigger('click')
page.within('.project-filter') do
click_link(project.name_with_namespace)
end
fill_in('dashboard_search', with: 'content')
find('.btn-search').trigger('click')
page.within('.search-filter') do
click_link('Wiki')
end
page.within('.results') do
expect(find(:css, '.search-results')).to have_link(wiki_page.title)
end
end
end
require 'spec_helper'
describe 'User uses header search field' do
include FilteredSearchHelpers
let(:project) { create(:project) }
let(:user) { create(:user) }
before do
project.add_reporter(user)
sign_in(user)
visit(project_path(project))
end
it 'starts searching by pressing the enter key', :js do
fill_in('search', with: 'gitlab')
find('#search').native.send_keys(:enter)
page.within('.breadcrumbs-sub-title') do
expect(page).to have_content('Search')
end
end
it 'contains location badge' do
expect(page).to have_selector('.has-location-badge')
end
context 'when clicking the search field', :js do
before do
page.find('#search').click
end
it 'shows category search dropdown' do
expect(page).to have_selector('.dropdown-header', text: /#{project.name}/i)
end
context 'when clicking issues' do
let!(:issue) { create(:issue, project: project, author: user, assignees: [user]) }
it 'shows assigned issues' do
find('.dropdown-menu').click_link('Issues assigned to me')
expect(page).to have_selector('.filtered-search')
expect_tokens([assignee_token(user.name)])
expect_filtered_search_input_empty
end
it 'shows created issues' do
find('.dropdown-menu').click_link("Issues I've created")
expect(page).to have_selector('.filtered-search')
expect_tokens([author_token(user.name)])
expect_filtered_search_input_empty
end
end