Skip to content

Commit

Permalink
test: add tests to verify h4 headings (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeyyy committed Aug 21, 2019
1 parent 0ab2662 commit 1f856ce
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 34 deletions.
47 changes: 47 additions & 0 deletions _rules/__tests__/headings.js
Expand Up @@ -22,6 +22,14 @@ const getAllHeadingsFromMarkdownBody = body => {
}, [])
}

const extractNumberFromGivenString = (str) => {
return str.match(/\d+/)[0]
}

const arrayHasDuplicates = (array) => {
return (new Set(array)).size !== array.length;
}

/**
* Get `text` of headings of given depth
* @param {Array<Object>} headings list of headings
Expand Down Expand Up @@ -53,4 +61,43 @@ describeRule('headings', ruleData => {
test.each(requiredH3)('has required `h2` - `%s`', heading => {
expect(h3Headings).toContain(heading)
})

/**
* Check all `h4` headings
*/

/**
* Test if headings have expected string
*/
const h4Headings = getHeadingOfDepth(headings, 4)
const h4PassedHeadings = h4Headings.filter(heading => heading.includes('Pass'))
const h4FailedHeadings = h4Headings.filter(heading => heading.includes('Fail'))
const h4InapplicableHeadings = h4Headings.filter(heading => heading.includes('Inapplicable'))

test.each(h4PassedHeadings)('has keyword "Passed Example" - %s', heading => {
expect(heading.includes('Passed Example')).toBe(true)
})
test.each(h4FailedHeadings)('has keyword "Failed Example" - %s', heading => {
expect(heading.includes('Failed Example')).toBe(true)
})
test.each(h4InapplicableHeadings)('has keyword "Inapplicable Example" - %s', heading => {
expect(heading.includes('Inapplicable Example')).toBe(true)
})

/**
* Test if heading indices are not duplicated
*/
const h4PassedHeadingsIndices = h4PassedHeadings.map(extractNumberFromGivenString)
const h4FailedHeadingsIndices = h4FailedHeadings.map(extractNumberFromGivenString)
const h4InapplicableHeadingsIndices = h4InapplicableHeadings.map(extractNumberFromGivenString)

test('has no duplicate "Passed" testcase example headings', () => {
expect(arrayHasDuplicates(h4PassedHeadingsIndices)).toBe(false)
})
test('has no duplicate "Failed" testcase example headings', () => {
expect(arrayHasDuplicates(h4FailedHeadingsIndices)).toBe(false)
})
test('has no duplicate "Inapplicable" testcase example headings', () => {
expect(arrayHasDuplicates(h4InapplicableHeadingsIndices)).toBe(false)
})
})
10 changes: 5 additions & 5 deletions _rules/autocomplete-valid-73f2c2.md
Expand Up @@ -124,23 +124,23 @@ Full length autocomplete terms.
<input autocomplete="section-primary shipping work email" />
```

#### Passed example 8
#### Passed Example 8

The `input` element does not have a semantic role that is a widget role, but still participates in sequential focus navigation, and has a single autocomplete term.

```html
<input role="none" autocomplete="username" />
```

#### Passed example 9
#### Passed Example 9

The `input` element does not participates in sequential focus navigation, but still has a semantic role that is a widget role, and has a single autocomplete term.

```html
<input tabindex="-1" autocomplete="username" />
```

#### Passed example 8
#### Passed Example 10

The `input` element does not have a semantic role that is a widget role, but still participates in sequential focus navigation since the [`tabindex` attribute](https://www.w3.org/TR/html/editing.html#the-tabindex-attribute) value is not a [valid integer](https://www.w3.org/TR/html/infrastructure.html#valid-integer), and has a single autocomplete term.

Expand Down Expand Up @@ -190,7 +190,7 @@ Autocomplete is inappropriate for the type of field.
<input type="number" autocomplete="email" />
```

#### Failed example 6
#### Failed Example 6

Autocomplete is not empty, but does not have any terms specified.

Expand Down Expand Up @@ -272,7 +272,7 @@ Non-widget element that does not participate in sequential focus navigation.
<input type="button" role="none" tabindex="-1" autocomplete="username" />
```

#### Inapplicable example 10
#### Inapplicable Example 10

Non-widget element that does not participate in sequential focus navigation.

Expand Down
6 changes: 3 additions & 3 deletions _rules/button-has-name-97a4e1.md
Expand Up @@ -113,15 +113,15 @@ Off screen elements should be tested.
</html>
```

#### Passed example 8
#### Passed Example 8

Button has accessible name that is not only whitespace.

```html
<button>:-)</button>
```

#### Passed example 9
#### Passed Example 9

Input button has an accessible name that comes from the default "reset" text.

Expand Down Expand Up @@ -166,7 +166,7 @@ Off screen element without an accessible name.
</html>
```

#### Failed example 4
#### Failed Example 4

Button has an accessible name that is only whitespace.

Expand Down
4 changes: 2 additions & 2 deletions _rules/form-field-has-name-e086e5.md
Expand Up @@ -97,7 +97,7 @@ Certain assistive technologies can be set up to ignore the title attribute, whic
<div aria-label="country" role="combobox" aria-disabled="true">England</div>
```

#### Passed example 6
#### Passed Example 6

The accessible name is not only whitespace.

Expand Down Expand Up @@ -162,7 +162,7 @@ The explicit label is not supported on `div` elements.
<div role="textbox" id="lastname"></div>
```

#### Failed example 7
#### Failed Example 7

The accessible name is only whitespace.

Expand Down
6 changes: 3 additions & 3 deletions _rules/html-has-lang-b5c3f8.md
Expand Up @@ -102,23 +102,23 @@ The `xml:lang` attribute specifies a value that is not empty (""). The rule does
<html xml:lang="xyz"></html>
```

#### Passed example 8
#### Passed Example 8

The `xml:lang` attribute specifies a value that is not empty (""). The rule does not verify the validity of the value specified and checks only for presence of a value.

```html
<html xml:lang="123"></html>
```

#### Passed example 9
#### Passed Example 9

The `xml:lang` attribute specifies a value that is not empty (""). The rule does not verify the validity of the value specified and checks only for presence of a value.

```html
<html xml:lang="#!"></html>
```

#### Passed example 9
#### Passed Example 10

The `xml:lang` attribute specifies a value that is not empty (""). The rule does not verify the validity of the value specified and checks only for presence of a value.

Expand Down
4 changes: 2 additions & 2 deletions _rules/iframe-has-name-cae760.md
Expand Up @@ -72,7 +72,7 @@ Usage of `aria-labelledby` attribute to describe the `iframe` content.
<iframe aria-labelledby="frame-title-helper" src="../test-assets/SC4-1-2-frame-doc.html"> </iframe>
```

#### Passed example 4
#### Passed Example 4

Accessible name is not only whitespace.

Expand Down Expand Up @@ -130,7 +130,7 @@ Usage of `alt` attribute to describe content is not valid.
<iframe alt="List of Contributors" src="../test-assets/SC4-1-2-frame-doc.html"> </iframe>
```

#### Failed example 7
#### Failed Example 7

Accessible name is only whitespace.

Expand Down
6 changes: 3 additions & 3 deletions _rules/image-button-has-name-59796f.md
Expand Up @@ -81,15 +81,15 @@ Image button element with accessible name through `aria-labelledby`
<div id="id1">Submit</div>
```

#### Passed example 5
#### Passed Example 5

Accessible name is not only whitespace.

```html
<input type="image" name="submit" src="button.gif" alt=":-)" />
```

#### Passed example 6
#### Passed Example 6

Image button element with accessible name through `alt` attribute

Expand Down Expand Up @@ -123,7 +123,7 @@ Image button with aria-labelledby that does not reference an id that exists in t
<input type="image" name="submit" src="button.gif" aria-labelledby="id1" />
```

#### Failed example 4
#### Failed Example 4

Accessible name is only whitespace.

Expand Down
4 changes: 2 additions & 2 deletions _rules/image-has-name-23a2a8.md
Expand Up @@ -99,7 +99,7 @@ The HTML `img` element is marked as [decorative](#decorative) through `role="non
<img role="none" />
```

#### Passed example 6
#### Passed Example 7

The HTML `img` element has an accessible name that does not only consist of whitespace

Expand Down Expand Up @@ -133,7 +133,7 @@ The `img` element inside a `div` positioned off screen has no accessible name an
<div style="margin-left:-9999px;"><img /></div>
```

#### Failed example 4
#### Failed Example 4

The HTML `img` element has an accessible name that only consist of whitespace

Expand Down
8 changes: 4 additions & 4 deletions _rules/lang-valid-de46e4.md
Expand Up @@ -91,7 +91,7 @@ The `lang` and `xml:lang` attribute values are not empty ("") and both have a va
</html>
```

#### Passed example 5
#### Passed Example 5

The `lang` and `xml:lang` attribute values are either empty ("") or have a valid primary language subtag.

Expand Down Expand Up @@ -141,7 +141,7 @@ The `lang` attribute value has a valid primary language subtag, but a syntactica
</html>
```

#### Failed example 4
#### Failed Example 4

The `lang` attribute value is not empty ("") and is not a valid primary language subtag.

Expand All @@ -153,7 +153,7 @@ The `lang` attribute value is not empty ("") and is not a valid primary language
</html>
```

#### Failed example 5
#### Failed Example 5

The `lang` attribute value is not empty ("") and is not a valid primary language subtag.

Expand All @@ -165,7 +165,7 @@ The `lang` attribute value is not empty ("") and is not a valid primary language
</html>
```

#### Failed example 5
#### Failed Example 6

The `lang` attribute value is not empty ("") and is not a valid primary language subtag.

Expand Down
12 changes: 6 additions & 6 deletions _rules/link-has-name-c487ae.md
Expand Up @@ -139,7 +139,7 @@ When `link` is off screen.
</html>
```

#### Passed example 10
#### Passed Example 10

`area` element with `href` attribute has accessible name.

Expand All @@ -151,7 +151,7 @@ When `link` is off screen.
</map>
```

#### Passed example 11
#### Passed Example 11

`a` element where accessible name does not only consist of whitespace.

Expand Down Expand Up @@ -220,15 +220,15 @@ Non-visible link.
</a>
```

#### Failed example 9
#### Failed Example 9

Link is completely empty, but still shows up in focus order, so it should have an accessible name.

```html
<a href="http://www.w3.org/WAI"></a>
```

#### Failed example 10
#### Failed Example 10

`area` element with `href` attribute does not have accessible name.

Expand All @@ -240,7 +240,7 @@ Link is completely empty, but still shows up in focus order, so it should have a
</map>
```

#### Failed example 11
#### Failed Example 11

`a` element where accessible name through content only consist of whitespace.

Expand Down Expand Up @@ -286,7 +286,7 @@ Not included in the accessibility tree due to `aria-hidden="true"`.
</a>
```

#### Inapplicable example 5
#### Inapplicable Example 5

`area` element without `href` attribute does not have role of `link`.

Expand Down
Expand Up @@ -188,7 +188,7 @@ Links created via scripting with [explicit role](#explicit-role) of link, but le
</span>
```

#### Failed example 4
#### Failed Example 4

Same accessible name used for image links going to different resources:

Expand Down Expand Up @@ -261,7 +261,7 @@ Link is not included in the accessibility tree:
<a href="/test-assets/links-with-identical-names-serve-equivalent-purpose-b20e66/pabe2.html">Contact Us</a>
```

#### Inapplicable example 4
#### Inapplicable Example 4

Links created via scripting, but without the semantic role of link:

Expand Down
4 changes: 2 additions & 2 deletions _rules/role-attribute-has-valid-value-674b10.md
Expand Up @@ -89,15 +89,15 @@ Element with multiple invalid `role` value.
<input type="text" role="invalid role" />
```

#### Failed example 3
#### Failed Example 3

Element with role attribute that is not empty (""), neither a valid `role` value.

```html
<input type="text" role=" " />
```

#### Failed example 4
#### Failed Example 4

Element with role attribute that is not empty (""), neither a valid `role` value.

Expand Down

0 comments on commit 1f856ce

Please sign in to comment.