summaryrefslogtreecommitdiff
path: root/spec/features/snippets/search_snippets_spec.rb
blob: c137b0bcd968fd6a7fd6b3b8332b9f98c93adaea (plain)
1
2
3
4
5
6
7
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
require 'rails_helper'

describe 'Search Snippets' do
  it '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')

    sign_in 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

  it '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
          )

    sign_in 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