/** * @fileoverview Enforce ARIA state and property values are valid. * @author Ethan Cohen */ // ----------------------------------------------------------------------------- // Requirements // ----------------------------------------------------------------------------- import { aria } from 'aria-query'; import { RuleTester } from 'eslint'; import expect from 'expect'; import parserOptionsMapper from '../../__util__/parserOptionsMapper'; import parsers from '../../__util__/helpers/parsers'; import rule from '../../../src/rules/aria-proptypes'; const { validityCheck } = rule; // ----------------------------------------------------------------------------- // Tests // ----------------------------------------------------------------------------- const ruleTester = new RuleTester(); const errorMessage = (name) => { const { type, values: permittedValues, } = aria.get(name.toLowerCase()); switch (type) { case 'tristate': return { message: `The value for ${name} must be a boolean or the string "mixed".` }; case 'token': return { message: `The value for ${name} must be a single token from the following: ${permittedValues}.` }; case 'tokenlist': return { message: `The value for ${name} must be a list of one or more \ tokens from the following: ${permittedValues}.`, }; case 'idlist': return { message: `The value for ${name} must be a list of strings that represent DOM element IDs (idlist)` }; case 'id': return { message: `The value for ${name} must be a string that represents a DOM element ID` }; case 'boolean': case 'string': case 'integer': case 'number': default: return { message: `The value for ${name} must be a ${type}.` }; } }; describe('validityCheck', () => { it('should false for an unknown expected type', () => { expect(validityCheck( null, null, )).toBe(false); }); }); ruleTester.run('aria-proptypes', rule, { valid: parsers.all([].concat( // DON'T TEST INVALID ARIA-* PROPS { code: '
' }, { code: '' }, // BOOLEAN { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '} />' }, // STRING { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, // TRISTATE { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, // INTEGER { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, // NUMBER { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, // TOKEN { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, // TOKENLIST { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, // ID { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, // IDLIST { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, { code: '' }, )).map(parserOptionsMapper), invalid: parsers.all([].concat( // BOOLEAN { code: '', errors: [errorMessage('aria-hidden')] }, { code: '', errors: [errorMessage('aria-hidden')] }, { code: '', errors: [errorMessage('aria-hidden')] }, { code: '', errors: [errorMessage('aria-hidden')], }, // STRING { code: '', errors: [errorMessage('aria-label')] }, { code: '', errors: [errorMessage('aria-label')] }, { code: '', errors: [errorMessage('aria-label')] }, { code: '', errors: [errorMessage('aria-label')] }, { code: '', errors: [errorMessage('aria-label')] }, // TRISTATE { code: '', errors: [errorMessage('aria-checked')] }, { code: '', errors: [errorMessage('aria-checked')] }, { code: '', errors: [errorMessage('aria-checked')] }, { code: '', errors: [errorMessage('aria-checked')], }, // INTEGER { code: '', errors: [errorMessage('aria-level')] }, { code: '', errors: [errorMessage('aria-level')] }, { code: '', errors: [errorMessage('aria-level')] }, { code: '', errors: [errorMessage('aria-level')] }, { code: '', errors: [errorMessage('aria-level')] }, { code: '', errors: [errorMessage('aria-level')] }, { code: '', errors: [errorMessage('aria-level')] }, // NUMBER { code: '', errors: [errorMessage('aria-valuemax')] }, { code: '', errors: [errorMessage('aria-valuemax')] }, { code: '', errors: [errorMessage('aria-valuemax')], }, { code: '', errors: [errorMessage('aria-valuemax')], }, { code: '', errors: [errorMessage('aria-valuemax')] }, { code: '', errors: [errorMessage('aria-valuemax')], }, { code: '', errors: [errorMessage('aria-valuemax')], }, // TOKEN { code: '', errors: [errorMessage('aria-sort')] }, { code: '', errors: [errorMessage('aria-sort')] }, { code: '', errors: [errorMessage('aria-sort')] }, { code: '', errors: [errorMessage('aria-sort')] }, { code: '', errors: [errorMessage('aria-sort')] }, { code: '', errors: [errorMessage('aria-sort')], }, // TOKENLIST { code: '', errors: [errorMessage('aria-relevant')] }, { code: '', errors: [errorMessage('aria-relevant')], }, { code: '', errors: [errorMessage('aria-relevant')] }, { code: '', errors: [errorMessage('aria-relevant')], }, { code: '', errors: [errorMessage('aria-relevant')], }, { code: '', errors: [errorMessage('aria-relevant')], }, { code: '', errors: [errorMessage('aria-relevant')], }, )).map(parserOptionsMapper), });