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 5 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)}

Choose a reason for hiding this comment

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

Space between { and | missing.
Space missing inside }.

Choose a reason for hiding this comment

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

Space between { and | missing.
Space missing inside }.

Rails.cache.write('/v1/autocomplete_hack/last_result', output ) if ENV["RAILS_ENV"] == "test"

Choose a reason for hiding this comment

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

Space inside parentheses detected.

Choose a reason for hiding this comment

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

Space inside parentheses detected.

render_output output
end
public
# these are all basically duplicates but make our calls to autocomplete more readable
Expand Down
23 changes: 23 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|

Choose a reason for hiding this comment

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

Space missing after comma.

Choose a reason for hiding this comment

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

Space missing after comma.

Rails.cache.delete('/v1/autocomplete_hack/last_result')

Choose a reason for hiding this comment

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

Use 2 (not 1) spaces for indentation.

Choose a reason for hiding this comment

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

Use 2 (not 1) spaces for indentation.

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 /^(?:|I )should see JSON:$/ do |expected_json|
require 'json'
expected = JSON.pretty_generate(JSON.parse(expected_json))
Expand Down Expand Up @@ -298,6 +320,7 @@ def with_scope(locator)
sleep 120
end


Choose a reason for hiding this comment

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

Extra blank line detected.

Choose a reason for hiding this comment

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

Extra blank line detected.

Then /^show me the network traffic$/ do
puts page.driver.network_traffic.to_yaml
end
3 changes: 2 additions & 1 deletion features/support/paths.rb
Expand Up @@ -205,7 +205,8 @@ def path_to(page_name)
tag_wranglers_path
when /^the unassigned fandoms page $/i
unassigned_fandoms_path

when /^the "(.*)" tag page$/i
tag_path(Tag.find_by_name($1))
# Here is an example that pulls values out of the Regexp:
#
# when /^(.*)'s profile page$/i
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