/* eslint-disable jest/require-top-level-describe */ import { render } from '@testing-library/react'; import React from 'react'; import { COLORS } from '../../../helpers/constants/design-system'; import { BUTTON_ICON_SIZES } from './button-icon.constants'; import { ButtonIcon } from './button-icon'; describe('ButtonIcon', () => { it('should render button element correctly', () => { const { getByTestId, container } = render( , ); expect(container.querySelector('button')).toBeDefined(); expect(getByTestId('button-icon')).toHaveClass('mm-button-icon'); expect(container).toMatchSnapshot(); }); it('should render anchor element correctly', () => { const { getByTestId, container } = render( , ); expect(getByTestId('button-icon')).toHaveClass('mm-button-icon'); const anchor = container.getElementsByTagName('a').length; expect(anchor).toBe(1); }); it('should render anchor element correctly using href', () => { const { getByTestId, getByRole } = render( , ); expect(getByTestId('button-icon')).toHaveClass('mm-button-icon'); expect(getByRole('link')).toBeDefined(); }); it('should render with different size classes', () => { const { getByTestId } = render( <> , ); expect(getByTestId(BUTTON_ICON_SIZES.SM)).toHaveClass( `mm-button-icon--size-${BUTTON_ICON_SIZES.SM}`, ); expect(getByTestId(BUTTON_ICON_SIZES.LG)).toHaveClass( `mm-button-icon--size-${BUTTON_ICON_SIZES.LG}`, ); }); it('should render with different colors', () => { const { getByTestId } = render( <> , ); expect(getByTestId(COLORS.ICON_DEFAULT)).toHaveClass( `box--color-${COLORS.ICON_DEFAULT}`, ); expect(getByTestId(COLORS.ERROR_DEFAULT)).toHaveClass( `box--color-${COLORS.ERROR_DEFAULT}`, ); }); it('should render with added classname', () => { const { getByTestId } = render( , ); expect(getByTestId('classname')).toHaveClass('mm-button-icon--test'); }); it('should render with different button states', () => { const { getByTestId } = render( <> , ); expect(getByTestId('disabled')).toHaveClass(`mm-button-icon--disabled`); expect(getByTestId('disabled')).toBeDisabled(); }); it('should render with icon', () => { const { getByTestId } = render( , ); expect(getByTestId('button-icon')).toBeDefined(); }); it('should render with aria-label', () => { const { getByLabelText } = render( , ); expect(getByLabelText('add')).toBeDefined(); }); });