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-4702 Test autocomplete #2601

Closed
wants to merge 7 commits into from
Closed
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
4 changes: 3 additions & 1 deletion app/controllers/autocomplete_controller.rb
Expand Up @@ -36,7 +36,9 @@ def pseud
private
def tag_output(search_param, tag_type)
tags = Tag.autocomplete_lookup(:search_param => search_param, :autocomplete_prefix => "autocomplete_tag_#{tag_type}")
render_output tags.map {|r| Tag.name_from_autocomplete(r)}
output = tags.map { |r| Tag.name_from_autocomplete(r) }
Rails.cache.write('/v1/autocomplete_hack/last_result', output) if ENV["RAILS_ENV"] == "test"
render_output output
end
public
# these are all basically duplicates but make our calls to autocomplete more readable
Expand Down
22 changes: 22 additions & 0 deletions features/step_definitions/web_steps.rb
Expand Up @@ -33,6 +33,11 @@ def with_scope(locator)
page.driver.browser.url_whitelist = ['http://127.0.0.1']
end

When /^I type in "([^"]*)" with "([^"]*)"$/ do |selector, contents|
Rails.cache.delete('/v1/autocomplete_hack/last_result')
find(selector).native.send_keys(contents)
end

When /^I clear the network traffic$/ do
page.driver.clear_network_traffic
end
Expand Down Expand Up @@ -120,6 +125,23 @@ def with_scope(locator)
}.to raise_error
end

Then(/^I should see "([^"]*)" in autocomplete hack$/) do |answer|
# This breaks the rule https://github.com/cucumber/cucumber/wiki/Given-When-Then
# While it might be tempting to implement Then steps to just look in the database
# resist the temptation. You should only verify outcome that is observable for
# the user (or external system) and databases usually are not.
result = false
(1..20).each do

Choose a reason for hiding this comment

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

Use Integer#times for a simple loop which iterates a fixed number of times.

Choose a reason for hiding this comment

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

Use Integer#times for a simple loop which iterates a fixed number of times.

next unless Rails.cache.read('/v1/autocomplete_hack/last_result').nil?
sleep 1
end
assert !Rails.cache.read('/v1/autocomplete_hack/last_result').nil?
Rails.cache.read('/v1/autocomplete_hack/last_result').each do |autocomplete|
result = true if autocomplete == answer
end
assert result
end

Then /^visiting "([^"]*)" should fail with "([^"]*)"$/ do |path, flash_error|
visit path
step %{I should see "#{flash_error}" within ".flash"}
Expand Down
23 changes: 22 additions & 1 deletion features/tags_and_wrangling/tag_wrangling_fandoms.feature
Expand Up @@ -2,7 +2,7 @@

Feature: Tag Wrangling - Fandoms

Scenario: fandoms wrangling - syns, mergers, autocompletes, metatags
Scenario: fandoms wrangling - syns, mergers, metatags

Given the following activated tag wrangler exists
| login | password |
Expand Down Expand Up @@ -211,3 +211,24 @@ Scenario: fandoms wrangling - syns, mergers, autocompletes, metatags
And I should see "Be a second B fandom" within "#letter-B .tags"
And I should see "Be another thing" within "#letter-B .tags"

@javascript
Scenario: fandoms wrangling - autocompletes

Given the following activated tag wrangler exists
| login | password |
| Enigel | wrangulate! |
And basic tags
And the following typed tags exists
| name | type | canonical |
| Steven Universe | Fandom | true |
| Ruby (Pokemon) | Character | true |
| Ruby (Firefly) | Character | true |
| Ruby (Steven Universe) | Character | true |
| Ruby (SU) | Character | false |
And I am logged in as "Enigel" with password "wrangulate!"
When I go to the "Ruby (SU)" tag page
And I follow "Edit"
And I type in "ul.autocomplete input" with "Ruby"
Then I should see "Ruby (Pokemon)" in autocomplete hack
And I should see "Ruby (Firefly)" in autocomplete hack
And I should see "Ruby (Steven Universe)" in autocomplete hack