2016-11-15 02:10:43 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
describe 'Search Snippets' do
|
|
|
|
it 'User searches for snippets by title' do
|
2016-11-15 02:10:43 -05:00
|
|
|
public_snippet = create(:personal_snippet, :public, title: 'Beginning and Middle')
|
|
|
|
private_snippet = create(:personal_snippet, :private, title: 'Middle and End')
|
|
|
|
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in private_snippet.author
|
2016-11-15 02:10:43 -05:00
|
|
|
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
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'User searches for snippet contents' do
|
2016-11-15 02:10:43 -05:00
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in create(:user)
|
2016-11-15 02:10:43 -05:00
|
|
|
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
|