diff --git a/app/soapbox/components/polls/__tests__/poll-footer.test.tsx b/app/soapbox/components/polls/__tests__/poll-footer.test.tsx new file mode 100644 index 000000000..2f4f21a6f --- /dev/null +++ b/app/soapbox/components/polls/__tests__/poll-footer.test.tsx @@ -0,0 +1,103 @@ +import React from 'react'; + +import { normalizePoll } from 'soapbox/normalizers/poll'; + +import { render, screen } from '../../../jest/test-helpers'; +import PollFooter from '../poll-footer'; + + +let poll = normalizePoll({ + options: [{ title: 'Apples', votes_count: 0 }], + emojis: [], + expired: false, + expires_at: '2020-03-24T19:33:06.000Z', + multiple: true, + voters_count: 0, + votes_count: 0, + own_votes: null, + voted: false, +}); + +describe('', () => { + describe('with "showResults" enabled', () => { + it('renders the Refresh button', () => { + render(); + + expect(screen.getByTestId('poll-footer')).toHaveTextContent('Refresh'); + }); + + it('does not render the Vote button', () => { + render(); + + expect(screen.queryAllByTestId('button')).toHaveLength(0); + }); + + describe('when the Poll has not expired', () => { + beforeEach(() => { + poll = normalizePoll({ + ...poll.toJS(), + expired: false, + }); + }); + + it('renders time remaining', () => { + render(); + + expect(screen.getByTestId('poll-expiration')).toHaveTextContent('Moments remaining'); + }); + }); + + describe('when the Poll has expired', () => { + beforeEach(() => { + poll = normalizePoll({ + ...poll.toJS(), + expired: true, + }); + }); + + it('renders closed', () => { + render(); + + expect(screen.getByTestId('poll-expiration')).toHaveTextContent('Closed'); + }); + }); + }); + + describe('with "showResults" disabled', () => { + it('does not render the Refresh button', () => { + render(); + + expect(screen.getByTestId('poll-footer')).not.toHaveTextContent('Refresh'); + }); + + describe('when the Poll is multiple', () => { + beforeEach(() => { + poll = normalizePoll({ + ...poll.toJS(), + multiple: true, + }); + }); + + it('renders the Vote button', () => { + render(); + + expect(screen.getByTestId('button')).toHaveTextContent('Vote'); + }); + }); + + describe('when the Poll is not multiple', () => { + beforeEach(() => { + poll = normalizePoll({ + ...poll.toJS(), + multiple: false, + }); + }); + + it('does not render the Vote button', () => { + render(); + + expect(screen.queryAllByTestId('button')).toHaveLength(0); + }); + }); + }); +}); diff --git a/app/soapbox/components/polls/poll-footer.tsx b/app/soapbox/components/polls/poll-footer.tsx index 386d25180..ad3db5dbd 100644 --- a/app/soapbox/components/polls/poll-footer.tsx +++ b/app/soapbox/components/polls/poll-footer.tsx @@ -37,7 +37,7 @@ const PollFooter: React.FC = ({ poll, showResults, selected }): JSX ; return ( - + {(!showResults && poll?.multiple) && (