Module: Ariadne::Accessibility

Defined in:
lib/ariadne/accessibility.rb

Overview

:nodoc:

Constant Summary collapse

IGNORED_PREVIEWS =

Skip axe checks for components that should be tested as part of a larger component. Do not add to this list for any other reason!

[].freeze
AXE_RULES_TO_SKIP =

Skip ‘:region` which relates to preview page structure rather than individual component.

{
  # these will be skipped in CI
  will_fix: {
    global: [],

    per_component: {},
  },

  # these will always be skipped
  wont_fix: {
    global: [
      :region,
    ],

    per_component: {},
  },
}.freeze

Class Method Summary collapse

Class Method Details

.axe_rules_to_skip(component: nil, scenario_name: nil, flatten: false) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ariadne/accessibility.rb', line 35

def axe_rules_to_skip(component: nil, scenario_name: nil, flatten: false)
  to_skip = {
    wont_fix: Set.new(AXE_RULES_TO_SKIP.dig(:wont_fix, :global) || []),
    will_fix: Set.new(AXE_RULES_TO_SKIP.dig(:will_fix, :global) || []),
  }

  if component
    to_skip[:wont_fix].merge(AXE_RULES_TO_SKIP.dig(:wont_fix, :per_component, component, :all_scenarios) || [])
    to_skip[:will_fix].merge(AXE_RULES_TO_SKIP.dig(:will_fix, :per_component, component, :all_scenarios) || [])

    if scenario_name
      to_skip[:wont_fix].merge(AXE_RULES_TO_SKIP.dig(:wont_fix, :per_component, component, scenario_name) || [])
      to_skip[:will_fix].merge(AXE_RULES_TO_SKIP.dig(:will_fix, :per_component, component, scenario_name) || [])
    end
  end

  if flatten
    flattened = to_skip.each_with_object(Set.new) do |(_, rule_set), memo|
      memo.merge(rule_set)
    end

    return flattened.to_a
  end

  to_skip.transform_values(&:to_a)
end

.ignore_preview?(preview_class) ⇒ Boolean



31
32
33
# File 'lib/ariadne/accessibility.rb', line 31

def ignore_preview?(preview_class)
  IGNORED_PREVIEWS.include?(preview_class)
end