Permalink
Cannot retrieve contributors at this time
86 lines (76 sloc)
3.08 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/eslint-plugin-jsx-a11y/__tests__/src/util/isFocusable-test.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import expect from 'expect'; | |
import { elementType } from 'jsx-ast-utils'; | |
import isFocusable from '../../../src/util/isFocusable'; | |
import { | |
genElementSymbol, | |
genInteractiveElements, | |
genNonInteractiveElements, | |
} from '../../../__mocks__/genInteractives'; | |
import JSXAttributeMock from '../../../__mocks__/JSXAttributeMock'; | |
function mergeTabIndex(index, attributes) { | |
return [...attributes, JSXAttributeMock('tabIndex', index)]; | |
} | |
describe('isFocusable', () => { | |
describe('interactive elements', () => { | |
genInteractiveElements().forEach(({ openingElement }) => { | |
it(`should identify \`${genElementSymbol(openingElement)}\` as a focusable element`, () => { | |
expect(isFocusable( | |
elementType(openingElement), | |
openingElement.attributes, | |
)).toBe(true); | |
}); | |
it(`should not identify \`${genElementSymbol(openingElement)}\` with tabIndex of -1 as a focusable element`, () => { | |
expect(isFocusable( | |
elementType(openingElement), | |
mergeTabIndex(-1, openingElement.attributes), | |
)).toBe(false); | |
}); | |
it(`should identify \`${genElementSymbol(openingElement)}\` with tabIndex of 0 as a focusable element`, () => { | |
expect(isFocusable( | |
elementType(openingElement), | |
mergeTabIndex(0, openingElement.attributes), | |
)).toBe(true); | |
}); | |
it(`should identify \`${genElementSymbol(openingElement)}\` with tabIndex of 1 as a focusable element`, () => { | |
expect(isFocusable( | |
elementType(openingElement), | |
mergeTabIndex(1, openingElement.attributes), | |
)).toBe(true); | |
}); | |
}); | |
}); | |
describe('non-interactive elements', () => { | |
genNonInteractiveElements().forEach(({ openingElement }) => { | |
it(`should not identify \`${genElementSymbol(openingElement)}\` as a focusable element`, () => { | |
expect(isFocusable( | |
elementType(openingElement), | |
openingElement.attributes, | |
)).toBe(false); | |
}); | |
it(`should not identify \`${genElementSymbol(openingElement)}\` with tabIndex of -1 as a focusable element`, () => { | |
expect(isFocusable( | |
elementType(openingElement), | |
mergeTabIndex(-1, openingElement.attributes), | |
)).toBe(false); | |
}); | |
it(`should identify \`${genElementSymbol(openingElement)}\` with tabIndex of 0 as a focusable element`, () => { | |
expect(isFocusable( | |
elementType(openingElement), | |
mergeTabIndex(0, openingElement.attributes), | |
)).toBe(true); | |
}); | |
it(`should identify \`${genElementSymbol(openingElement)}\` with tabIndex of 1 as a focusable element`, () => { | |
expect(isFocusable( | |
elementType(openingElement), | |
mergeTabIndex(1, openingElement.attributes), | |
)).toBe(true); | |
}); | |
it(`should not identify \`${genElementSymbol(openingElement)}\` with tabIndex of 'bogus' as a focusable element`, () => { | |
expect(isFocusable( | |
elementType(openingElement), | |
mergeTabIndex('bogus', openingElement.attributes), | |
)).toBe(false); | |
}); | |
}); | |
}); | |
}); |