|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "test_helper" |
| 4 | + |
| 5 | +class AriaLabelIsWellFormatted < LinterTestCase |
| 6 | + def linter_class |
| 7 | + ERBLint::Linters::GitHub::Accessibility::AriaLabelIsWellFormatted |
| 8 | + end |
| 9 | + |
| 10 | + def test_warns_when_aria_label_starts_with_downcase |
| 11 | + @file = <<~HTML |
| 12 | + <button aria-label="submit" ></button> |
| 13 | + <button aria-label="check-box-1" ></button> |
| 14 | + <button aria-label="ok" ></button> |
| 15 | + <button aria-label="no" ></button> |
| 16 | + HTML |
| 17 | + @linter.run(processed_source) |
| 18 | + |
| 19 | + assert_equal 4, @linter.offenses.count |
| 20 | + end |
| 21 | + |
| 22 | + def test_does_not_warn_when_aria_labelledby_starts_with_downcase |
| 23 | + @file = "<button aria-labelledby='some-element-1'</button>" |
| 24 | + @linter.run(processed_source) |
| 25 | + |
| 26 | + assert_empty @linter.offenses |
| 27 | + end |
| 28 | + |
| 29 | + def test_does_not_warn_when_aria_label_starts_with_anything_other_than_downcase |
| 30 | + @file = <<~HTML |
| 31 | + <button aria-label="Submit" ></button> |
| 32 | + <button aria-label="Close" ></button> |
| 33 | + <button aria-label="11 open" ></button> |
| 34 | + HTML |
| 35 | + @linter.run(processed_source) |
| 36 | + |
| 37 | + assert_empty @linter.offenses |
| 38 | + end |
| 39 | + |
| 40 | + def test_does_not_warn_when_aria_label_is_excepted_in_config |
| 41 | + @file = <<~HTML |
| 42 | + <button aria-label="Submit" ></button> |
| 43 | + <button aria-label="Close" ></button> |
| 44 | + <button aria-label="11 open" ></button> |
| 45 | + HTML |
| 46 | + @linter.run(processed_source) |
| 47 | + |
| 48 | + assert_empty @linter.offenses |
| 49 | + end |
| 50 | + |
| 51 | + |
| 52 | + def test_does_not_warn_if_aria_label_is_in_excepted_list |
| 53 | + @file = <<~HTML |
| 54 | + <button aria-label="hello" ></button> |
| 55 | + <button aria-label="hello world" ></button> |
| 56 | + HTML |
| 57 | + @linter.config.exceptions = ["hello"] |
| 58 | + @linter.run(processed_source) |
| 59 | + |
| 60 | + assert_equal 1, @linter.offenses.count |
| 61 | + end |
| 62 | +end |
0 commit comments