Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-4719 Refactor work search tests #2615

Merged
merged 6 commits into from Nov 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions features/step_definitions/work_steps.rb
Expand Up @@ -93,6 +93,18 @@

### GIVEN

Given(/^I have the Battle set loaded$/) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative would have been to use a Background section in the Cucumber scenario, which would then make it clearer what has been loaded before each test for users who only read the feature file (if we ever get any "business" "stakeholders" to do that!). But as the Cucumber documentation recommends not having Backgrounds longer than 4 lines, and nobody who isn't a coder looks at them, I think this is probably the right approach here.

step %{I have loaded the fixtures}
step %{I have Battle 12 prompt meme fully set up}
step %{everyone has signed up for Battle 12}
step %{mod fulfills claim}
step %{I reveal the "Battle 12" challenge}
step %{I am logged in as "myname4"}
step %{I have flushed Redis}
step %{the statistics_tasks rake task is run}
step %{the work indexes are updated}
end

Given /^I have no works or comments$/ do
Work.delete_all
Comment.delete_all
Expand Down Expand Up @@ -517,3 +529,4 @@
assert !Work.where(title: work).exists?
end


68 changes: 36 additions & 32 deletions features/works/work_search.feature
Expand Up @@ -6,33 +6,28 @@ Feature: Search Works

# do everything that doesn't modify the works in one scenario
# so you only have to load the fixtures and update the sphinx indexes once
Scenario: Search works
Given I have loaded the fixtures
And I have Battle 12 prompt meme fully set up
And everyone has signed up for Battle 12
When mod fulfills claim
When I reveal the "Battle 12" challenge
When I am logged in as "myname4"
And I have flushed Redis
And the statistics_tasks rake task is run
And the work indexes are updated
Scenario: anon work doesn't show up in searches
Given I have the Battle set loaded

# anon work doesn't show up in searches
When I search for works containing "mod"
Then I should see "No results found"
When I search for works by mod
Then I should see "No results found"
When I search for works containing "mod"
Then I should see "No results found"
When I search for works by mod
Then I should see "No results found"

# reveal works
Scenario: reveal works doesn't show up in searches
Given I have the Battle set loaded

When I reveal the authors of the "Battle 12" challenge
When all search indexes are updated
When I am logged in as "myname4"
When I search for works containing "mod"
And all search indexes are updated
And I am logged in as "myname4"
And I search for works containing "mod"
Then I should see "No results found"
When I search for works by mod
Then I should see "No results found"

# do some valid searches
Scenario: do some valid searches
Given I have the Battle set loaded

When I search for a simple term from the search box
Then I should see "3 Found"
When I follow "Edit Your Search"
Expand All @@ -43,21 +38,27 @@ Feature: Search Works
And I press "Search" within "form#new_work_search"
Then I should see "1 Found"

# search by language
Scenario: search by language
Given I have the Battle set loaded

When I am on the search works page
And I select "Deutsch" from "Language"
And I press "Search" within "form#new_work_search"
Then I should see "1 Found"

# search by range of hits
Scenario: search by range of hits
Given I have the Battle set loaded

When I am on the search works page
And I fill in "Hits" with "10000-20000"
And I press "Search" within "form#new_work_search"
Then I should see "1 Found"

# search by date and then by word count AND date
Scenario: search by date and then by word count AND date
Given I have the Battle set loaded

When I am on the search works page
When I fill in "Date" with "> 2 years ago"
And I fill in "Date" with "> 2 years ago"
And I press "Search" within "form#new_work_search"
Then I should see "6 Found"
When I follow "Edit Your Search"
Expand All @@ -66,7 +67,9 @@ Feature: Search Works
And I press "Search" within "form#new_work_search"
Then I should see "No results found"

# search by > hits
Scenario: search by > hits
Given I have the Battle set loaded

When I am on the search works page
And I fill in "Hits" with "> 100"
And I press "Search" within "form#new_work_search"
Expand All @@ -75,7 +78,9 @@ Feature: Search Works
And I should see "third work"
And I should see "You searched for: hits: > 100"

# search with the header search field and then refine it using the author/artist field
Scenario: search with the header search field and then refine it using the author/artist field
Given I have the Battle set loaded

When I am on the homepage.
And I fill in "site_search" with "testuser2"
And I press "Search"
Expand All @@ -87,7 +92,9 @@ Feature: Search Works
And I press "Search" within "form#new_work_search"
Then I should see "3 Found"

# search by number of kudos
Scenario: search by number of kudos
Given I have the Battle set loaded

When I am on the search works page
And I fill in "Kudos" with ">0"
And I press "Search" within "form#new_work_search"
Expand All @@ -107,12 +114,9 @@ Feature: Search Works
And I fill in "Kudos" with "<2"
And I press "Search" within "form#new_work_search"
Then I should see "You searched for: kudos count: <2"
Then I should see "6 Found"

# search for complete works with few kudos
And I should see "6 Found"
When I follow "Edit Your Search"
And I check "Complete"
And I press "Search" within "form#new_work_search"
Then I should see "You searched for: Complete kudos count: <2"
Then I should see "4 Found"

And I should see "4 Found"
2 changes: 1 addition & 1 deletion spec/support/login_macros.rb
Expand Up @@ -14,4 +14,4 @@ def fake_login_known_user(user)
allow(controller).to receive(:current_user).and_return(@current_user)
allow(controller).to receive(:logout_if_not_user_credentials).and_return(nil)
end
end
end