/* eslint-disable jest/require-top-level-describe */ import { render } from '@testing-library/react'; import React from 'react'; import { IconName } from '..'; import { Button } from './button'; import { ButtonSize, ButtonVariant } from '.'; describe('Button', () => { it('should render button element correctly', () => { const { getByTestId, getByText, container } = render( , ); expect(getByText('Button')).toBeDefined(); expect(container.querySelector('button')).toBeDefined(); expect(getByTestId('button')).toHaveClass('mm-button-base'); expect(container).toMatchSnapshot(); }); it('should render anchor element correctly', () => { const { getByTestId, container } = render( , ); expect(getByTestId('button')).toHaveClass('mm-button-base'); const anchor = container.getElementsByTagName('a').length; expect(anchor).toBe(1); }); it('should render anchor element correctly by href only being passed', () => { const { getByTestId, container } = render( , ); expect(getByTestId('button')).toHaveClass('mm-button-base'); const anchor = container.getElementsByTagName('a').length; expect(anchor).toBe(1); }); it('should render button as block', () => { const { getByTestId } = render( , ); expect(getByTestId(ButtonVariant.Primary)).toHaveClass( `mm-button-${ButtonVariant.Primary}`, ); expect(getByTestId(ButtonVariant.Secondary)).toHaveClass( `mm-button-${ButtonVariant.Secondary}`, ); expect(getByTestId(ButtonVariant.Link)).toHaveClass( `mm-button-${ButtonVariant.Link}`, ); expect(container).toMatchSnapshot(); }); it('should render with different size classes', () => { const { getByTestId } = render( <> , ); expect(getByTestId(ButtonSize.Inherit)).toHaveClass( `mm-button-link--size-${ButtonSize.Inherit}`, ); expect(getByTestId(ButtonSize.Sm)).toHaveClass( `mm-button-base--size-${ButtonSize.Sm}`, ); expect(getByTestId(ButtonSize.Md)).toHaveClass( `mm-button-base--size-${ButtonSize.Md}`, ); expect(getByTestId(ButtonSize.Lg)).toHaveClass( `mm-button-base--size-${ButtonSize.Lg}`, ); }); it('should render with added classname', () => { const { getByTestId } = render( , ); expect(getByTestId('classname')).toHaveClass('mm-button-base--test'); }); it('should render with different button states', () => { const { getByTestId } = render( <> , ); expect(getByTestId('loading')).toHaveClass(`mm-button-base--loading`); expect(getByTestId('disabled')).toHaveClass(`mm-button-base--disabled`); }); it('should render with icon', () => { const { getByTestId } = render( , ); expect(getByTestId('start-button-icon')).toBeDefined(); }); }); it('should render as danger', () => { const { getByTestId } = render( <> , ); expect(getByTestId('danger')).toHaveClass('mm-button-primary--type-danger'); });