Skip to content

Commit

Permalink
Add search feature specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mercyoseni committed Jul 29, 2019
1 parent 941cdeb commit a6fc4c7
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions spec/features/search_mushroom_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require 'rails_helper'

RSpec.describe 'Search Mushroom', :js, type: :feature do
let!(:edible_mushroom) { create(:mushroom, :edible) }
let!(:poisonous_mushroom) { create(:mushroom, :poisonous) }

before { visit root_path }

scenario "search by 'edible'" do
fill_in 'search_query', with: 'edible'

click_on 'Search'

within 'table' do
expect(page).to have_content('edible')
end
end

scenario "search by 'poisonous'" do
fill_in 'search_query', with: 'poisonous'

click_on 'Search'

within 'table' do
expect(page).to have_content('poisonous')
end
end

scenario "search by 'edible, poisonous'" do
fill_in 'search_query', with: 'edible, poisonous'

click_on 'Search'

within 'table' do
expect(page).to have_content('edible')
expect(page).to have_content('poisonous')
end
end

scenario "search by 'edi, onous'" do
fill_in 'search_query', with: 'edi, onous'

click_on 'Search'

within 'table' do
expect(page).to have_content('edible')
expect(page).to have_content('poisonous')
end
end

scenario 'search by empty string' do
click_on 'Search'

expect(
page.find('#search_query').native.attribute('validationMessage')
).to have_content('Please fill out this field')

# Remove required attribute on search input
page.execute_script("$('#search_query').removeAttr('required')")

fill_in 'search_query', with: ''

click_on 'Search'

expect(page).to have_content(
'No results found. Try another filter or search.'
)
end
end

0 comments on commit a6fc4c7

Please sign in to comment.