sforkowany z mirror/soapbox
Add test for handling the Refresh button
rodzic
7a7fda0c08
commit
dcde237fc9
|
@ -1,12 +1,16 @@
|
|||
import userEvent from '@testing-library/user-event';
|
||||
import React from 'react';
|
||||
import { IntlProvider } from 'react-intl';
|
||||
import { Provider } from 'react-redux';
|
||||
|
||||
import { __stub } from 'soapbox/api';
|
||||
import { normalizePoll } from 'soapbox/normalizers/poll';
|
||||
|
||||
import { render, screen } from '../../../jest/test-helpers';
|
||||
import { mockStore, render, rootReducer, screen } from '../../../jest/test-helpers';
|
||||
import PollFooter from '../poll-footer';
|
||||
|
||||
|
||||
let poll = normalizePoll({
|
||||
id: 1,
|
||||
options: [{ title: 'Apples', votes_count: 0 }],
|
||||
emojis: [],
|
||||
expired: false,
|
||||
|
@ -26,6 +30,30 @@ describe('<PollFooter />', () => {
|
|||
expect(screen.getByTestId('poll-footer')).toHaveTextContent('Refresh');
|
||||
});
|
||||
|
||||
it('responds to the Refresh button', async() => {
|
||||
__stub((mock) => {
|
||||
mock.onGet('/api/v1/polls/1').reply(200, {});
|
||||
});
|
||||
|
||||
const user = userEvent.setup();
|
||||
const store = mockStore(rootReducer(undefined, {}));
|
||||
render(
|
||||
<Provider store={store}>
|
||||
<IntlProvider locale='en'>
|
||||
<PollFooter poll={poll} showResults selected={{}} />
|
||||
</IntlProvider>
|
||||
</Provider>,
|
||||
);
|
||||
|
||||
await user.click(screen.getByTestId('poll-refresh'));
|
||||
const actions = store.getActions();
|
||||
expect(actions).toEqual([
|
||||
{ type: 'POLL_FETCH_REQUEST' },
|
||||
{ type: 'POLLS_IMPORT', polls: [{}] },
|
||||
{ type: 'POLL_FETCH_SUCCESS', poll: {} },
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not render the Vote button', () => {
|
||||
render(<PollFooter poll={poll} showResults selected={{}} />);
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ const PollFooter: React.FC<IPollFooter> = ({ poll, showResults, selected }): JSX
|
|||
<HStack space={1.5} alignItems='center'>
|
||||
{showResults && (
|
||||
<>
|
||||
<button className='text-gray-600 underline' onClick={handleRefresh}>
|
||||
<button className='text-gray-600 underline' onClick={handleRefresh} data-testid='poll-refresh'>
|
||||
<Text theme='muted' weight='medium'>
|
||||
<FormattedMessage id='poll.refresh' defaultMessage='Refresh' />
|
||||
</Text>
|
||||
|
|
Ładowanie…
Reference in New Issue