Skip to content

Commit

Permalink
AO3-4897 Extend tag set tests to better cover the edit page (#2788)
Browse files Browse the repository at this point in the history
* AO3-4897 Tests for tag set owner adding and removing each type of tag, also split the tag_set feature into parts by heading

* AO3-4897 Put the tests back in one file because I need another change

* AO3-4897 Add test for adding/removing associations from the edit page because it's broken on the strong params branch

* AO3-4897 Relocate a step from tag_set to tag

* AO3-4897 Style tweaks for code

* AO3-4897 Fix a damn spacing error that makes everything fail

* AO3-4897 The last of the code prettying

* AO3-4897 Make the steps dryer
  • Loading branch information
sarken authored and zz9pzza committed Mar 12, 2017
1 parent 4e9eb61 commit 37ea644
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 42 deletions.
83 changes: 60 additions & 23 deletions features/step_definitions/tag_set_steps.rb
@@ -1,36 +1,63 @@
# encoding: utf-8

When /^I follow the add new tag ?set link$/ do
step %{I follow "New Tag Set"}
end

# This takes strings like:
# ...the fandom tags "x, y, z"
# ...the category tags "a, b, c"
# If you want ratings, warnings, or categories, first load basic or default tags for those types
When /^I add (.*) to the tag ?set$/ do |tags|
tags.scan(/the (\w+) tags "([^\"]*)"/).each do |type, scanned_tags|
if type == "category" || type == "rating" || type == "warning"
tags = scanned_tags.split(/, ?/)
tags.each { |tag| check(tag) }
else
fill_in("owned_tag_set_tag_set_attributes_#{type}_tagnames_to_add", with: scanned_tags)
end
end
end

# This takes strings like:
# ...with a visible tag list
# ...with the fandom tags "x, y, z" and the character tags "a, b, c"
# ...with an invisible tag list and the freeform tags "m, n, o"
When /^I set up the tag ?set "([^\"]*)" with(?: (?:an? )(visible|invisible) tag list and)? (.*)$/ do |title, visibility, tags|
unless OwnedTagSet.find_by_title("#{title}").present?
step %{I go to the new tag set page}
fill_in("owned_tag_set_title", :with => title)
fill_in("owned_tag_set_description", :with => "Here's my tagset")
visibility ||= "invisible"
check("owned_tag_set_visible") if visibility == "visible"
uncheck("owned_tag_set_visible") if visibility == "invisible"
tags.scan(/the (\w+) tags "([^\"]*)"/).each do |type, tags|
fill_in("owned_tag_set_tag_set_attributes_#{type}_tagnames_to_add", :with => tags)
end
unless OwnedTagSet.find_by_title(title).present?
visit new_tag_set_path
fill_in("owned_tag_set_title", with: title)
fill_in("owned_tag_set_description", with: "Here's my tagset")
visibility ||= "invisible"
check("owned_tag_set_visible") if visibility == "visible"
uncheck("owned_tag_set_visible") if visibility == "invisible"
step %{I add #{tags} to the tag set}
step %{I submit}
step %{I should see a create confirmation message}
end
end

# Takes things like When I add the fandom tags "Bandom" to the tag set "MoreJoyDay". Don't forget the extra s, even if it's singular.
# Takes things like When I add the fandom tags "Bandom" to the tag set "MoreJoyDay".
# Don't forget the extra s, even if it's singular.
When /^I add (.*) to the tag ?set "([^\"]*)"$/ do |tags, title|
step %{I go to the "#{title}" tag set edit page}
tags.scan(/the (\w+) tags "([^\"]*)"/).each do |type, scannedtags|
fill_in("owned_tag_set_tag_set_attributes_#{type}_tagnames_to_add", :with => scannedtags)
step %{I add #{tags} to the tag set}
step %{I submit}
step %{I should see an update confirmation message}
end

# Takes things like When I remove the fandom tags "Bandom" to the tag set "MoreJoyDay".
# Don't forget the extra s, even if it's singular.
When /^I remove (.*) from the tag ?set "([^\"]*)"$/ do |tags, title|
step %{I go to the "#{title}" tag set edit page}
tags.scan(/the (\w+) tags "([^\"]*)"/).each do |type, scanned_tags|
tags = scanned_tags.split(/, ?/)
if type == "category" || type == "rating" || type == "warning"
tags.each { |tag| uncheck(tag) }
else
tags.each { |tag| check(tag) }
end
step %{I submit}
end
step %{I submit}
step %{I should see an update confirmation message}
end

Expand All @@ -52,9 +79,9 @@
step %{I go to the "#{title}" tag set page}
step %{I follow "Nominate"}
1.upto(fandom_count.to_i) do |i|
fill_in("Fandom #{i}", :with => "Blah #{i}")
fill_in("Fandom #{i}", with: "Blah #{i}")
0.upto(char_count.to_i - 1) do |j|
fill_in("tag_set_nomination_fandom_nominations_attributes_#{i-1}_character_nominations_attributes_#{j}_tagname", :with => "Foobar #{i} #{j}")
fill_in("tag_set_nomination_fandom_nominations_attributes_#{i - 1}_character_nominations_attributes_#{j}_tagname", with: "Foobar #{i} #{j}")
end
end
end
Expand All @@ -76,9 +103,9 @@
char_index = 0
chars_per_fandom = @chars.size/@fandoms.size
1.upto(@fandoms.size) do |i|
fill_in("Fandom #{i}", :with => @fandoms[i-1])
fill_in("Fandom #{i}", with: @fandoms[i - 1])
0.upto(chars_per_fandom - 1) do |j|
fill_in("tag_set_nomination_fandom_nominations_attributes_#{i-1}_character_nominations_attributes_#{j}_tagname", :with => @chars[char_index])
fill_in("tag_set_nomination_fandom_nominations_attributes_#{i - 1}_character_nominations_attributes_#{j}_tagname", with: @chars[char_index])
char_index += 1
end
end
Expand Down Expand Up @@ -126,7 +153,7 @@
step %{I go to the "#{title}" tag set page}
step %{I follow "Nominate"}
tags.each_with_index do |tag, i|
fill_in("Fandom #{i+1}", :with => tag)
fill_in("Fandom #{i + 1}", with: tag)
end
step %{I submit}
step %{I should see a success message}
Expand All @@ -150,8 +177,18 @@
visit tag_set_path(tagset)
end

When(/^I flush the wrangling sidebar caches$/) do
[Fandom, Character, Relationship, Freeform].each do |klass|
Rails.cache.delete("/wrangler/counts/sidebar/#{klass}")
When /^I expand the unassociated characters and relationships$/ do
within('span[action_target="#list_for_unassociated_char_and_rel"]') do
click_link("↓")
end
end

Then /^"([^\"]*)" should be associated with the "([^\"]*)" fandom "([^\"]*)"$/ do |tag, fandom_type, fandom_name|
name = fandom_name.tr(" ", "_")
type = fandom_type.tr(" ", "_")
step %{I should see "#{tag}" within "ol#list_for_fandom_#{name}_in_#{type}_Fandoms li"}
end

Then /^"([^\"]*)" should be an unassociated tag$/ do |tag|
step %{I should see "#{tag}" within "ol#list_for_unassociated_char_and_rel"}
end
34 changes: 19 additions & 15 deletions features/step_definitions/tag_steps.rb
Expand Up @@ -6,6 +6,13 @@
end

Given /^basic tags$/ do
step %{the default ratings exist}
step %{the basic warnings exist}
Fandom.find_or_create_by_name_and_canonical("No Fandom", true)
step %{the basic categories exist}
end

Given /^the default ratings exist$/ do
ratings = [ArchiveConfig.RATING_DEFAULT_TAG_NAME,
ArchiveConfig.RATING_GENERAL_TAG_NAME,
ArchiveConfig.RATING_TEEN_TAG_NAME,
Expand All @@ -14,25 +21,16 @@
ratings.each do |rating|
Rating.find_or_create_by_name_and_canonical(rating, true)
end
end

Given /^the basic warnings exist$/ do
Warning.find_or_create_by_name_and_canonical("No Archive Warnings Apply", true)
Warning.find_or_create_by_name_and_canonical("Choose Not To Use Archive Warnings", true)
Fandom.find_or_create_by_name_and_canonical("No Fandom", true)
Category.find_or_create_by_name_and_canonical("Gen", true)
Category.find_or_create_by_name_and_canonical("Other", true)
Category.find_or_create_by_name_and_canonical("F/F", true)
Category.find_or_create_by_name_and_canonical("Multi", true)
Category.find_or_create_by_name_and_canonical("F/M", true)
Category.find_or_create_by_name_and_canonical("M/M", true)
end

Given /^the default ratings exist$/ do
ratings = [ArchiveConfig.RATING_DEFAULT_TAG_NAME,
ArchiveConfig.RATING_GENERAL_TAG_NAME,
ArchiveConfig.RATING_TEEN_TAG_NAME,
ArchiveConfig.RATING_MATURE_TAG_NAME,
ArchiveConfig.RATING_EXPLICIT_TAG_NAME]
ratings.each do |rating|
Rating.find_or_create_by_name_and_canonical(rating, true)
Given /^the basic categories exist$/ do
%w(Gen Other F/F Multi F/M M/M).each do |category|
Category.find_or_create_by_name_and_canonical(category, true)
end
end

Expand Down Expand Up @@ -271,6 +269,12 @@
end
end

When /^I flush the wrangling sidebar caches$/ do
[Fandom, Character, Relationship, Freeform].each do |klass|
Rails.cache.delete("/wrangler/counts/sidebar/#{klass}")
end
end

### THEN

Then /^I should see the tag wrangler listed as an editor of the tag$/ do
Expand Down
114 changes: 110 additions & 4 deletions features/tags_and_wrangling/tag_set.feature
Expand Up @@ -21,11 +21,93 @@ Feature: creating and editing tag sets
Scenario: A user should be able to add additional tags to an existing set
Given I am logged in as "tagsetter"
And I set up the tag set "Noncanonical Tags" with the fandom tags "Ywerwe, Blah di blah, Foooo"
When I follow "Edit"
And I add the character tags "Bababa, Lalala" and the freeform tags "wheee, gloopy" to the tag set "Noncanonical Tags"
When I add the character tags "Bababa, Lalala" and the freeform tags "wheee, gloopy" to the tag set "Noncanonical Tags"
Then I should see an update confirmation message
And I should see "wheee"

Scenario: A user should be able to add and remove fandom tags for a tag set they own
Given I am logged in
And I set up the tag set "Fandoms" with the fandom tags "One, Two"
When I add the fandom tags "Three, Four" to the tag set "Fandoms"
Then I should see "One"
And I should see "Two"
And I should see "Three"
And I should see "Four"
When I remove the fandom tags "One, Three" from the tag set "Fandoms"
Then I should see "Two"
And I should see "Four"
And I should not see "One"
And I should not see "Three"

Scenario: A user should be able to add and remove character tags for a tag set they own
Given I am logged in
And I set up the tag set "Characters" with the character tags "Character 1, Character 2"
When I add the character tags "Character 3, Character 4" to the tag set "Characters"
Then I should see "Character 1"
And I should see "Character 2"
And I should see "Character 3"
And I should see "Character 4"
When I remove the character tags "Character 2, Character 4" from the tag set "Characters"
Then I should see "Character 1"
And I should see "Character 3"
And I should not see "Character 2"
And I should not see "Character 4"

Scenario: A user should be able to add and remove relationship tags for a tag set they own
Given I am logged in
And I set up the tag set "Relationships" with the relationship tags "One/Two, 1 & 2"
When I add the relationship tags "3/4, Three & Four" to the tag set "Relationships"
Then I should see "One/Two"
And I should see "1 & 2"
And I should see "3/4"
And I should see "Three & Four"
When I remove the relationship tags "One/Two, Three & Four" from the tag set "Relationships"
Then I should see "1 & 2"
And I should see "3/4"
And I should not see "One/Two"
And I should not see "Three & Four"

Scenario: A user should be able to add and remove rating tags for a tag set they own
Given the default ratings exist
And I am logged in
And I set up the tag set "Ratings" with the rating tags "Explicit, Mature"
When I add the rating tags "Teen And Up Audiences, General Audiences" to the tag set "Ratings"
Then I should see "Explicit"
And I should see "Mature"
And I should see "Teen And Up Audiences"
And I should see "General Audiences"
When I remove the rating tags "Explicit, Teen And Up Audiences" from the tag set "Ratings"
Then I should see "Mature"
And I should see "General Audiences"
And I should not see "Explicit"
And I should not see "Teen And Up Audiences"

Scenario: A user should be able to add and remove category tags for a tag set they own
Given the basic categories exist
And I am logged in
And I set up the tag set "Categories" with the category tags "Other, F/M"
When I add the category tags "F/F, M/M" to the tag set "Categories"
Then I should see "Other"
And I should see "F/M"
And I should see "M/M"
And I should see "F/F"
When I remove the category tags "F/F, Other" from the tag set "Categories"
Then I should see "M/M"
And I should see "F/M"
And I should not see "F/F"
And I should not see "Other"

Scenario: A user should be able to add and remove warning tags for a tag set they own
Given the basic warnings exist
And I am logged in
And I set up the tag set "Warnings" with the warning tags "Choose Not To Use Archive Warnings"
When I add the warning tags "No Archive Warnings Apply" to the tag set "Warnings"
Then I should see "Choose Not To Use Archive Warnings"
And I should see "No Archive Warnings Apply"
When I remove the warning tags "Choose Not To Use Archive Warnings" from the tag set "Warnings"
Then I should see "No Archive Warnings Apply"
And I should not see "Choose Not To Use Archive Warnings"

Scenario: If a tag set does not have a visible tag list, only a moderator should be able to see the tags in the set, but everyone should be able to see the tag set
Given I am logged in as "tagsetter"
And I set up the tag set "Tag Set with Non-visible Tag List" with an invisible tag list and the fandom tags "Dallas, Knots Landing, Models Inc"
Expand Down Expand Up @@ -55,8 +137,32 @@ Feature: creating and editing tag sets
And I should see "Knots Landing"
And I should see "Models Inc"

Scenario: A moderator should be able to manually set up associations between tags in their set on the main tag set edit page

@javascript
Scenario: A moderator should be able to manually set up and remove associations between tags in their set on the main tag set edit page
Given I am logged in
And I set up the tag set "Associations" with the fandom tags "Major Crimes, The Closer" and the character tags "Brenda Leigh Johnson, Sharon Raydor"
When I go to the "Associations" tag set edit page
And I follow "Add Association"
And I select "Sharon Raydor" from "Tag"
And I select "The Closer" from "Parent tag"
And I press "Update"
Then I should see an update confirmation message
And I should see "Uncategorized Fandoms (2)"
And I should see "Unassociated Characters & Relationships (1)"
When I follow "Expand All"
Then I should see "The Closer (1)"
And I should see "Major Crimes (0)"
And "Sharon Raydor" should be associated with the "Uncategorized" fandom "The Closer"
When I go to the "Associations" tag set edit page
And I check "Sharon Raydor (The Closer)"
And I press "Update"
Then I should see an update confirmation message
And I should see "Unassociated Characters & Relationships (2)"
When I follow "Expand All"
Then I should see "The Closer (0)"
And I should see "Major Crimes (0)"
When I expand the unassociated characters and relationships
Then "Sharon Raydor" should be an unassociated tag

# NOMINATIONS
Scenario: A tag set should take nominations within the nomination limits
Expand Down

0 comments on commit 37ea644

Please sign in to comment.