| 1 | /**
|
|---|
| 2 | * @fileoverview Enforce <marquee> elements are not used.
|
|---|
| 3 | * @author Ethan Cohen
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | // -----------------------------------------------------------------------------
|
|---|
| 7 | // Requirements
|
|---|
| 8 | // -----------------------------------------------------------------------------
|
|---|
| 9 |
|
|---|
| 10 | import { RuleTester } from 'eslint';
|
|---|
| 11 | import parserOptionsMapper from '../../__util__/parserOptionsMapper';
|
|---|
| 12 | import rule from '../../../src/rules/accessible-emoji';
|
|---|
| 13 | import parsers from '../../__util__/helpers/parsers';
|
|---|
| 14 |
|
|---|
| 15 | // -----------------------------------------------------------------------------
|
|---|
| 16 | // Tests
|
|---|
| 17 | // -----------------------------------------------------------------------------
|
|---|
| 18 |
|
|---|
| 19 | const ruleTester = new RuleTester();
|
|---|
| 20 |
|
|---|
| 21 | const expectedError = {
|
|---|
| 22 | message: 'Emojis should be wrapped in <span>, have role="img", and have an accessible description with aria-label or aria-labelledby.',
|
|---|
| 23 | type: 'JSXOpeningElement',
|
|---|
| 24 | };
|
|---|
| 25 |
|
|---|
| 26 | ruleTester.run('accessible-emoji', rule, {
|
|---|
| 27 | valid: parsers.all([].concat(
|
|---|
| 28 | { code: '<div />;' },
|
|---|
| 29 | { code: '<span />' },
|
|---|
| 30 | { code: '<span>No emoji here!</span>' },
|
|---|
| 31 | { code: '<span role="img" aria-label="Panda face">๐ผ</span>' },
|
|---|
| 32 | { code: '<span role="img" aria-label="Snowman">☃</span>' },
|
|---|
| 33 | { code: '<span role="img" aria-labelledby="id1">๐ผ</span>' },
|
|---|
| 34 | { code: '<span role="img" aria-labelledby="id1">☃</span>' },
|
|---|
| 35 | { code: '<span role="img" aria-labelledby="id1" aria-label="Snowman">☃</span>' },
|
|---|
| 36 | { code: '<span>{props.emoji}</span>' },
|
|---|
| 37 | { code: '<span aria-hidden>{props.emoji}</span>' },
|
|---|
| 38 | { code: '<span aria-hidden="true">๐ผ</span>' },
|
|---|
| 39 | { code: '<span aria-hidden>๐ผ</span>' },
|
|---|
| 40 | { code: '<div aria-hidden="true">๐ผ</div>' },
|
|---|
| 41 | { code: '<input type="hidden">๐ผ</input>' },
|
|---|
| 42 | {
|
|---|
| 43 | code: '<CustomInput type="hidden">๐ผ</CustomInput>',
|
|---|
| 44 | settings: { 'jsx-a11y': { components: { CustomInput: 'input' } } },
|
|---|
| 45 | },
|
|---|
| 46 | {
|
|---|
| 47 | code: '<Box as="input" type="hidden">๐ผ</Box>',
|
|---|
| 48 | settings: { 'jsx-a11y': { polymorphicPropName: 'as' } },
|
|---|
| 49 | },
|
|---|
| 50 | )).map(parserOptionsMapper),
|
|---|
| 51 | invalid: parsers.all([].concat(
|
|---|
| 52 | { code: '<span>๐ผ</span>', errors: [expectedError] },
|
|---|
| 53 | { code: '<span>foo๐ผbar</span>', errors: [expectedError] },
|
|---|
| 54 | { code: '<span>foo ๐ผ bar</span>', errors: [expectedError] },
|
|---|
| 55 | { code: '<i role="img" aria-label="Panda face">๐ผ</i>', errors: [expectedError] },
|
|---|
| 56 | { code: '<i role="img" aria-labelledby="id1">๐ผ</i>', errors: [expectedError] },
|
|---|
| 57 | { code: '<Foo>๐ผ</Foo>', errors: [expectedError] },
|
|---|
| 58 | { code: '<span aria-hidden="false">๐ผ</span>', errors: [expectedError] },
|
|---|
| 59 | { code: '<CustomInput type="hidden">๐ผ</CustomInput>', errors: [expectedError] },
|
|---|
| 60 | {
|
|---|
| 61 | code: '<Box as="span">๐ผ</Box>',
|
|---|
| 62 | settings: { 'jsx-a11y': { polymorphicPropName: 'as' } },
|
|---|
| 63 | errors: [expectedError],
|
|---|
| 64 | },
|
|---|
| 65 | )).map(parserOptionsMapper),
|
|---|
| 66 | });
|
|---|