import * as React from 'react'; import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { Button } from '../Button'; import { ComponentClassNames } from '../../shared'; describe('Button test suite', () => { it('should render button variations', async () => { render(
); const primary = await screen.findByTestId('primary'); const link = await screen.findByTestId('link'); const menu = await screen.findByTestId('menu'); const warning = await screen.findByTestId('warning'); const destructive = await screen.findByTestId('destructive'); expect(primary.classList).toContain('amplify-button--primary'); expect(link.classList).toContain('amplify-button--link'); expect(menu.classList).toContain('amplify-button--menu'); expect(warning.classList).toContain('amplify-button--warning'); expect(destructive.classList).toContain('amplify-button--destructive'); expect(primary.classList).toContain( `${ComponentClassNames['Button']}--primary` ); expect(link.classList).toContain(`${ComponentClassNames['Button']}--link`); expect(menu.classList).toContain(`${ComponentClassNames['Button']}--menu`); }); it('should add the disabled class with the disabled attribute', async () => { render( ); const disabled = await screen.findByTestId('disabled'); expect(disabled).toHaveClass('amplify-button--disabled'); }); it('should render button states', async () => { render(
); const fullwidth = await screen.findByTestId('fullwidth'); const disabled = await screen.findByTestId('disabled'); const loading = await screen.findByTestId('loading'); expect(fullwidth.classList).toContain( `${ComponentClassNames['Button']}--fullwidth` ); expect(disabled.classList).toContain( `${ComponentClassNames['Button']}--disabled` ); expect(loading.classList).toContain( `${ComponentClassNames['Button']}--loading` ); }); it('should render button sizes', async () => { render(
); const small = await screen.findByTestId('small'); const large = await screen.findByTestId('large'); expect(small.classList).toContain( `${ComponentClassNames['Button']}--small` ); expect(large.classList).toContain( `${ComponentClassNames['Button']}--large` ); }); it('should render classname and custom classname', async () => { const className = 'test-class'; render(); await screen.findByRole('button'); expect(ref.current?.nodeName).toBe('BUTTON'); expect(ref.current?.innerHTML).toBe(buttonText); }); it('should set size and variation props correctly', async () => { const size = 'large'; const variation = 'primary'; render(