kibana/packages/kbn-eslint-plugin-eui-a11y/helpers/utils.test.ts
Coen Warmer 54add717b6
Create eslint-plugin-eui-a11y plugin (#215859)
## Summary

This adds an additional custom ESLint rule package which checks certain
Eui elements for the existence of an `aria-label` prop.

If it exists, it will leave it untouched. If it doesn't, it will warn
the engineer it needs to be added, and offers a autofix suggestion for
those engineers who have fix on save enabled in their IDE.

<img width="739" alt="Screenshot 2025-03-25 at 13 59 28"
src="https://github.com/user-attachments/assets/0813b317-c752-40d7-b569-e866a3ecf6b0"
/>

<img width="804" alt="Screenshot 2025-03-25 at 13 59 36"
src="https://github.com/user-attachments/assets/3c45c49c-6db8-4740-b5de-89aa534c248b"
/>

This package is an offshoot of the `kbn-eslint-plugin-i18n` and
`kbn-eslint-plugin-telemetry` packages.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-03-26 23:00:31 +02:00

50 lines
2.4 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import { lowerCaseFirstChar, upperCaseFirstChar, sanitizeEuiElementName } from './utils';
describe('Utils', () => {
describe('lowerCaseFirstLetter', () => {
it('should lowercase the first letter', () => {
expect(lowerCaseFirstChar('Hello')).toBe('hello');
expect(lowerCaseFirstChar('GreatSuccessYes')).toBe('greatSuccessYes');
expect(lowerCaseFirstChar('How is it going?')).toBe('how is it going?');
});
it('should lowercase all letters if the passed string is in ALL CAPS', () => {
expect(lowerCaseFirstChar('HELLO')).toBe('hello');
expect(lowerCaseFirstChar('GREATSUCCESSYES')).toBe('greatsuccessyes');
});
});
describe('upperCaseFirstLetter', () => {
it('should uppercase the first letter', () => {
expect(upperCaseFirstChar('hello')).toBe('Hello');
expect(upperCaseFirstChar('greatSuccessYes')).toBe('GreatSuccessYes');
expect(upperCaseFirstChar('how is it going?')).toBe('How is it going?');
});
});
describe('sanitizeEuiElementName', () => {
it('should remove Eui, Empty, Icon, WithWidth, Super from the element name', () => {
expect(sanitizeEuiElementName('EuiButtonEmpty').elementName).toBe('Button');
expect(sanitizeEuiElementName('EuiButtonIcon').elementName).toBe('Button');
expect(sanitizeEuiElementName('EuiButtonSuper').elementName).toBe('Button');
expect(sanitizeEuiElementName('EuiBetaBadge').elementName).toBe('BetaBadge');
});
it('should return the element name with spaces', () => {
expect(sanitizeEuiElementName('EuiButtonEmpty').elementNameWithSpaces).toBe('Button');
expect(sanitizeEuiElementName('EuiButtonIcon').elementNameWithSpaces).toBe('Button');
expect(sanitizeEuiElementName('EuiButtonWithWidth').elementNameWithSpaces).toBe('Button');
expect(sanitizeEuiElementName('EuiButtonSuper').elementNameWithSpaces).toBe('Button');
expect(sanitizeEuiElementName('EuiBetaBadge').elementNameWithSpaces).toBe('Beta Badge');
});
});
});