Commit 6bf87395 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'move-snippet-search-spinach-test-to-rspec' into 'master'

Move 'Search Snippets' Spinach feature to Rspec

## What does this MR do?
Moves the Spinach feature `features/snippet_search.feature` to an RSpec feature `spec/features/snippets/search_snippets_spec.rb`.

## Are there points in the code the reviewer needs to double check?

The search results page URL was being visited directly in the original Spinach test, using an encoded search query and specific parameters to trigger the snippet searches. I have changed the RSpect feature to fill in the search box on the snippets dashboard page to retrieve results to cover the missing test coverage on the search box and to avoid the feature test from relying on the implementation details of the search URL structure.

## Why was this MR needed?

As part of deprecating the Spinach test suite.

## Screenshots (if relevant)

## Does this MR meet the acceptance criteria?

- [-] [Changelog entry](https://docs.gitlab.com/ce/development/changelog.html) added
- [-] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- [-] API support added
- Tests
  - [x] Added for this feature/bug
  - [x] All builds are passing
- [x] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [x] Branch has no merge conflicts with `master` (if it does - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

## What are the relevant issue numbers?

#23036

See merge request !7494
parents b7aae9a6 dbf5c8ab
@dashboard
Feature: Snippet Search
Background:
Given I sign in as a user
And I have public "Personal snippet one" snippet
And I have private "Personal snippet private" snippet
And I have a public many lined snippet
Scenario: I should see my public and private snippets
When I search for "snippet" in snippet titles
Then I should see "Personal snippet one" in results
And I should see "Personal snippet private" in results
Scenario: I should see three surrounding lines on either side of a matching snippet line
When I search for "line seven" in snippet contents
Then I should see "line four" in results
And I should see "line seven" in results
And I should see "line ten" in results
And I should not see "line three" in results
And I should not see "line eleven" in results
module SharedSearch
include Spinach::DSL
def search_snippet_contents(query)
visit "/search?search=#{URI::encode(query)}&snippets=true&scope=snippet_blobs"
end
def search_snippet_titles(query)
visit "/search?search=#{URI::encode(query)}&snippets=true&scope=snippet_titles"
end
end
class Spinach::Features::SnippetSearch < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
include SharedSnippet
include SharedUser
include SharedSearch
step 'I search for "snippet" in snippet titles' do
search_snippet_titles 'snippet'
end
step 'I search for "snippet private" in snippet titles' do
search_snippet_titles 'snippet private'
end
step 'I search for "line seven" in snippet contents' do
search_snippet_contents 'line seven'
end
step 'I should see "line seven" in results' do
expect(page).to have_content 'line seven'
end
step 'I should see "line four" in results' do
expect(page).to have_content 'line four'
end
step 'I should see "line ten" in results' do
expect(page).to have_content 'line ten'
end
step 'I should not see "line eleven" in results' do
expect(page).not_to have_content 'line eleven'
end
step 'I should not see "line three" in results' do
expect(page).not_to have_content 'line three'
end
step 'I should see "Personal snippet one" in results' do
expect(page).to have_content 'Personal snippet one'
end
step 'I should see "Personal snippet private" in results' do
expect(page).to have_content 'Personal snippet private'
end
step 'I should not see "Personal snippet one" in results' do
expect(page).not_to have_content 'Personal snippet one'
end
step 'I should not see "Personal snippet private" in results' do
expect(page).not_to have_content 'Personal snippet private'
end
end
require 'rails_helper'
feature 'Search Snippets', feature: true do
scenario 'User searches for snippets by title' do
public_snippet = create(:personal_snippet, :public, title: 'Beginning and Middle')
private_snippet = create(:personal_snippet, :private, title: 'Middle and End')
login_as private_snippet.author
visit dashboard_snippets_path
page.within '.search' do
fill_in 'search', with: 'Middle'
click_button 'Go'
end
click_link 'Titles and Filenames'
expect(page).to have_link(public_snippet.title)
expect(page).to have_link(private_snippet.title)
end
scenario 'User searches for snippet contents' do
create(:personal_snippet,
:public,
title: 'Many lined snippet',
content: <<-CONTENT.strip_heredoc
|line one
|line two
|line three
|line four
|line five
|line six
|line seven
|line eight
|line nine
|line ten
|line eleven
|line twelve
|line thirteen
|line fourteen
CONTENT
)
login_as create(:user)
visit dashboard_snippets_path
page.within '.search' do
fill_in 'search', with: 'line seven'
click_button 'Go'
end
expect(page).to have_content('line seven')
# 3 lines before the matched line should be visible
expect(page).to have_content('line six')
expect(page).to have_content('line five')
expect(page).to have_content('line four')
expect(page).not_to have_content('line three')
# 3 lines after the matched line should be visible
expect(page).to have_content('line eight')
expect(page).to have_content('line nine')
expect(page).to have_content('line ten')
expect(page).not_to have_content('line eleven')
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