import * as React from 'react'; import SpinnerContainer from './SpinnerContainer'; import {render, within} from '@testing-library/react'; import {testA11y} from '../../axe'; describe('SpinnerContainer', () => { it('render', () => { const spinnerContainer = render(foo); expect(spinnerContainer.getByText('foo')).toBeTruthy(); }); it('loading', () => { const container = render(); expect(container.getByRole('status')).toBeTruthy(); }); describe('loading: ', () => { it('should have a role status', () => { const spinnerContainer = render(); expect(spinnerContainer.getByRole('status')).toBeTruthy(); }); it('children should have aria-busy="true"', () => { const spinnerContainer = render(
children
); expect( spinnerContainer.getByRole('banner').getAttribute('aria-busy') ).toBe('true'); }); it('should announce loading information', () => { const spinnerContainer = render(); const status = spinnerContainer.getByRole('status'); expect(status.getAttribute('aria-live')).toBe('assertive'); expect(within(status).getByText('content is loading')).toBeTruthy(); }); }); describe('loaded: ', () => { it('should have a role status', () => { const spinnerContainer = render(); expect(spinnerContainer.getByRole('status')).toBeTruthy(); }); it('should announce information is loaded', () => { const spinnerContainer = render(); const status = spinnerContainer.getByRole('status'); expect(status.getAttribute('aria-live')).toBe('assertive'); expect(within(status).getByText('content loaded')).toBeTruthy(); }); }); describe('a11y', () => { it('should have no a11y violations when loading', async () => { await testA11y(); }); it('should have no a11y violations when loaded', async () => { await testA11y(); }); }); });