Skip to content

Commit

Permalink
Merge pull request #1057 from alphagov/fix-intermittently-failing-test
Browse files Browse the repository at this point in the history
Fix intermittent failing tests
  • Loading branch information
andrewgarner authored Aug 17, 2018
2 parents 1ef4036 + 1d735b7 commit 3c7fcd5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 53 deletions.
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Application < Rails::Application
# Do not swallow errors in after_commit/after_rollback callbacks.
# config.active_record.raise_in_transactional_callbacks = true

# Load links out configuration for taxonomy navigation
config.taxonomy_navigation_links_out = config_for(:taxonomy_navigation_links_out)
end
end
79 changes: 27 additions & 52 deletions test/integration/links_out_config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,41 @@
class LinksOutConfigTest < ActionDispatch::IntegrationTest
include ContentPagesNavTestHelper
include GdsApi::TestHelpers::Rummager
include Capybara::Minitest::Assertions

def schema_type
"guide"
end
Rails.configuration.taxonomy_navigation_links_out.each do |name, group|
group.each do |level, rules|
test "links out configuration for #{name} #{level}" do
stub_rummager
setup_variant_b

def setup_variant_b
ContentItemsController.any_instance.stubs(:show_new_navigation?).returns(true)
end
content_example = get_example_guide_with_single_taxon
content_example[name] = level

def setup_and_visit_content_item_with_taxonomy_grouping(name, taxonomy_grouping)
taxonomy_grouping = default_taxonomy_grouping.merge(taxonomy_grouping)
@content_item = get_content_example(name).tap do |item|
item["links"]["taxons"] = SINGLE_TAXON
item["content_purpose_supergroup"] = taxonomy_grouping["content_purpose_supergroup"]
item["content_purpose_subgroup"] = taxonomy_grouping["content_purpose_subgroup"]
item["document_type"] = taxonomy_grouping["document_type"]
content_store_has_item(item["base_path"], item.to_json)
visit_with_cachebust(item["base_path"])
end
end
content_store_has_item content_example['base_path'], content_example.to_json
visit_with_cachebust content_example['base_path']

def default_taxonomy_grouping
{
"content_purpose_supergroup" => "guidance_and_regulation",
"content_purpose_subgroup" => "guidance",
"document_type" => "guide"
}
end

def taxon_config
Rails.configuration.taxonomy_navigation_links_out || YAML.safe_load(File.read("config/taxonomy_navigation_links_out.yml"))["default"]
end

def expected_supergroups(rule_level)
rule_level.map { |rules| rules["supergroup"].humanize }
end

def assert_has_supergroup_navigation(expected_supergroups)
within('.taxonomy-navigation') do
expected_supergroups.each do |supergroup|
assert page.has_css?('.gem-c-heading', text: supergroup)
if rules.empty?
refute_css '.taxonomy-navigation'
else
rules.each do |rule|
assert_css '.taxonomy-navigation .gem-c-heading', text: rule['supergroup'].humanize
end
end
end
end
end

test "links out configuration causes no errors and correct supergroups are displayed for each ruleset" do
stub_rummager
setup_variant_b
using_wait_time 10 do
taxon_config.each_key do |taxonomy_rule_level|
taxon_config[taxonomy_rule_level].each_key do |rules_for_taxon|
setup_and_visit_content_item_with_taxonomy_grouping("guide", taxonomy_rule_level => rules_for_taxon)
expected_supergroups = expected_supergroups(taxon_config[taxonomy_rule_level][rules_for_taxon])
if expected_supergroups.any?
assert_has_supergroup_navigation(expected_supergroups)
else
refute page.has_css?('taxonomy-navigation')
end
end
end
def get_example_guide_with_single_taxon
get_content_example_by_schema_and_name('guide', 'guide').tap do |item|
item['content_purpose_subgroup'] = 'guidance'
item['content_purpose_supergroup'] = 'guidance_and_regulation'
item['document_type'] = 'guide'
item['links']['taxons'] = SINGLE_TAXON
end
end

def setup_variant_b
ContentItemsController.any_instance.stubs(:show_new_navigation?).returns(true)
end
end
2 changes: 1 addition & 1 deletion test/presenters/content_item/links_out_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def other_rules
end

def stub_load_rules(rules)
Rails.configuration.taxonomy_navigation_links_out = rules
Rails.configuration.stubs(:taxonomy_navigation_links_out).returns(rules)
end

def assert_has_supergroup_rule(rule_set)
Expand Down

0 comments on commit 3c7fcd5

Please sign in to comment.