Skip to content

Commit 1968894

Browse files
committed
Combine multiple tests to one
1 parent 1c3a867 commit 1968894

File tree

1 file changed

+6
-39
lines changed

1 file changed

+6
-39
lines changed

test/linters/accessibility/avoid_generic_link_text_counter_test.rb

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_does_not_flag_when_aria_label_includes_visible_link_text
7676
assert_empty @linter.offenses
7777
end
7878

79-
def test_ignores_when_aria_labelledby_is_set_on_link_tag
79+
def test_ignores_when_aria_labelledby_is_set_on_link_tag_since_cannot_be_evaluated_accurately_by_erb_linter
8080
@file = "<a aria-labelledby='someElement'>Click here</a>"
8181
@linter.run(processed_source)
8282

@@ -99,61 +99,28 @@ def test_warns_when_link_rails_helper_text_is_banned_text_with_aria_description
9999
refute_empty @linter.offenses
100100
end
101101

102-
def test_ignores_when_link_rails_helper_text_is_banned_text_with_aria_labelled_by
103-
@file = "<%= link_to('learn more', redirect_url, 'aria-labelledby': 'element1234', id: 'redirect') %>"
104-
@linter.run(processed_source)
105-
106-
assert_empty @linter.offenses
107-
end
108-
109-
def test_ignores_when_link_rails_helper_text_is_banned_text_with_aria_label_that_cannot_be_parsed_by_linter
102+
def test_ignores_when_link_rails_helper_text_is_banned_text_with_any_aria_label_attributes_since_cannot_be_evaluated_accurately_by_erb_linter
110103
@file = <<~ERB
104+
<%= link_to('learn more', redirect_url, 'aria-labelledby': 'element1234', id: 'redirect') %>
111105
<%= link_to('learn more', redirect_url, 'aria-label': some_variable, id: 'redirect') %>
112-
ERB
113-
@linter.run(processed_source)
114-
115-
assert_empty @linter.offenses
116-
end
117-
118-
def test_ignores_when_link_rails_helper_text_is_banned_text_with_aria_label_since_cannot_be_parsed_accurately_by_linter
119-
@file = <<~ERB
120106
<%= link_to('learn more', redirect_url, 'aria-label': "Learn #{@variable}", id: 'redirect') %>
107+
<%= link_to('learn more', redirect_url, 'aria-label': 'learn more about GitHub', id: 'redirect') %>
108+
<%= link_to('learn more', redirect_url, aria: { label: 'learn more about GitHub' }, id: 'redirect') %>
121109
ERB
122110
@linter.run(processed_source)
123111

124112
assert_empty @linter.offenses
125113
end
126114

127-
def test_ignores_when_link_rails_helper_text_is_banned_text_with_aria_label
128-
@file = "<%= link_to('learn more', redirect_url, 'aria-label': 'learn more about GitHub', id: 'redirect') %>"
129-
@linter.run(processed_source)
130-
131-
assert_empty @linter.offenses
132-
end
133-
134-
def test_ignores_when_link_rails_helper_text_is_banned_text_with_aria_label_hash
135-
@file = "<%= link_to('learn more', redirect_url, aria: { label: 'learn more about GitHub' }, id: 'redirect') %>"
136-
@linter.run(processed_source)
137-
138-
assert_empty @linter.offenses
139-
end
140-
141-
def test_does_not_warn_when_generic_text_is_link_rails_helper_sub_text
142-
@file = "<%= link_to('click here to learn about github', redirect_url, id: 'redirect') %>"
143-
@linter.run(processed_source)
144-
145-
assert_empty @linter.offenses
146-
end
147-
148115
def test_handles_files_with_various_links
149116
@file = <<~ERB
150117
<p>
151118
<a href="github.com" aria-label='Click here to learn more'>Click here</a>
119+
<%= link_to "learn more", billing_path, "aria-label": "something" %>
152120
<a href="github.com" aria-label='Some totally different text'>Click here</a>
153121
<a href="github.com" aria-labelledby='someElement'>Click here</a>
154122
</p>
155123
<p>
156-
<%= link_to "learn more", billing_path, "aria-label": "something" %>
157124
<%= link_to "learn more", billing_path, aria: { label: "something" } %>
158125
<%= link_to "learn more", billing_path, aria: { describedby: "element123" } %>
159126
<%= link_to "learn more", billing_path, "aria-describedby": "element123" %>

0 commit comments

Comments
 (0)