-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
941cdeb
commit a6fc4c7
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |