Add test for handling the Refresh button
This commit is contained in:
parent
7a7fda0c08
commit
dcde237fc9
2 changed files with 31 additions and 3 deletions
|
@ -1,12 +1,16 @@
|
||||||
|
import userEvent from '@testing-library/user-event';
|
||||||
import React from 'react';
|
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 { 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';
|
import PollFooter from '../poll-footer';
|
||||||
|
|
||||||
|
|
||||||
let poll = normalizePoll({
|
let poll = normalizePoll({
|
||||||
|
id: 1,
|
||||||
options: [{ title: 'Apples', votes_count: 0 }],
|
options: [{ title: 'Apples', votes_count: 0 }],
|
||||||
emojis: [],
|
emojis: [],
|
||||||
expired: false,
|
expired: false,
|
||||||
|
@ -26,6 +30,30 @@ describe('<PollFooter />', () => {
|
||||||
expect(screen.getByTestId('poll-footer')).toHaveTextContent('Refresh');
|
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', () => {
|
it('does not render the Vote button', () => {
|
||||||
render(<PollFooter poll={poll} showResults selected={{}} />);
|
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'>
|
<HStack space={1.5} alignItems='center'>
|
||||||
{showResults && (
|
{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'>
|
<Text theme='muted' weight='medium'>
|
||||||
<FormattedMessage id='poll.refresh' defaultMessage='Refresh' />
|
<FormattedMessage id='poll.refresh' defaultMessage='Refresh' />
|
||||||
</Text>
|
</Text>
|
||||||
|
|
Loading…
Reference in a new issue