bigbuffet-rw/app/soapbox/features/ui/components/__tests__/compose-button.test.tsx

38 lines
1 KiB
TypeScript
Raw Normal View History

import { fireEvent, render, screen } from '@testing-library/react';
2022-03-21 11:09:01 -07:00
import React from 'react';
import { IntlProvider } from 'react-intl';
import { Provider } from 'react-redux';
import '@testing-library/jest-dom';
2022-03-21 11:09:01 -07:00
import { MODAL_OPEN } from 'soapbox/actions/modals';
import { mockStore, rootState } from 'soapbox/jest/test-helpers';
2022-03-21 11:09:01 -07:00
import ComposeButton from '../compose-button';
const store = mockStore(rootState);
const renderComposeButton = () => {
render(
<Provider store={store}>
<IntlProvider locale='en'>
<ComposeButton />
</IntlProvider>
</Provider>,
);
};
2022-03-21 11:09:01 -07:00
describe('<ComposeButton />', () => {
it('renders a button element', () => {
renderComposeButton();
2022-03-21 11:09:01 -07:00
expect(screen.getByRole('button')).toHaveTextContent('Compose');
2022-03-21 11:09:01 -07:00
});
it('dispatches the MODAL_OPEN action', () => {
renderComposeButton();
2022-03-21 11:09:01 -07:00
expect(store.getActions().length).toEqual(0);
fireEvent.click(screen.getByRole('button'));
2022-03-21 11:09:01 -07:00
expect(store.getActions()[0].type).toEqual(MODAL_OPEN);
});
});