Convert old tests to use "react-testing-library"

This commit is contained in:
Justin
2022-04-04 11:53:47 -04:00
parent 9a099b3fa7
commit ed47cf5f09
71 changed files with 411 additions and 1515 deletions

View File

@ -1,26 +1,39 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { Map as ImmutableMap } from 'immutable';
import React from 'react';
import { IntlProvider } from 'react-intl';
import { Provider } from 'react-redux';
import '@testing-library/jest-dom';
import { MODAL_OPEN } from 'soapbox/actions/modals';
import { mockStore } from 'soapbox/jest/test-helpers';
import rootReducer from 'soapbox/reducers';
import { createComponent, mockStore } from 'soapbox/test_helpers';
import ComposeButton from '../compose-button';
const store = mockStore(rootReducer(ImmutableMap(), {}));
const renderComposeButton = () => {
render(
<Provider store={store}>
<IntlProvider locale='en'>
<ComposeButton />
</IntlProvider>
</Provider>,
);
};
describe('<ComposeButton />', () => {
it('renders a button element', () => {
const component = createComponent(<ComposeButton />);
const tree = component.toJSON();
renderComposeButton();
expect(tree).toMatchSnapshot();
expect(screen.getByRole('button')).toHaveTextContent('Compose');
});
it('dispatches the MODAL_OPEN action', () => {
const store = mockStore(rootReducer(ImmutableMap(), {}));
const component = createComponent(<ComposeButton />, { store });
renderComposeButton();
expect(store.getActions().length).toEqual(0);
component.root.findByType('button').props.onClick();
fireEvent.click(screen.getByRole('button'));
expect(store.getActions()[0].type).toEqual(MODAL_OPEN);
});
});