From a58069a1233f4edca503771c14ff9c56fa6c62e4 Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 2 May 2022 09:48:37 -0400 Subject: [PATCH] Add tests for Report modal --- .../__tests__/report-modal.test.tsx | 68 +++++++++++++++++++ .../modals/report-modal/steps/reason-step.tsx | 1 + 2 files changed, 69 insertions(+) create mode 100644 app/soapbox/features/ui/components/modals/report-modal/__tests__/report-modal.test.tsx diff --git a/app/soapbox/features/ui/components/modals/report-modal/__tests__/report-modal.test.tsx b/app/soapbox/features/ui/components/modals/report-modal/__tests__/report-modal.test.tsx new file mode 100644 index 0000000000..f50732146b --- /dev/null +++ b/app/soapbox/features/ui/components/modals/report-modal/__tests__/report-modal.test.tsx @@ -0,0 +1,68 @@ +import userEvent from '@testing-library/user-event'; +import { Map as ImmutableMap, Set as ImmutableSet } from 'immutable'; +import React from 'react'; + +import { __stub } from 'soapbox/api'; + +import { render, screen } from '../../../../../../jest/test-helpers'; +import { normalizeAccount, normalizeStatus } from '../../../../../../normalizers'; +import ReportModal from '../report-modal'; + +describe('', () => { + let store; + + beforeEach(() => { + const rules = require('soapbox/__fixtures__/rules.json'); + const status = require('soapbox/__fixtures__/status-unordered-mentions.json'); + + store = { + accounts: ImmutableMap({ + '1': normalizeAccount({ + id: '1', + acct: 'username', + display_name: 'My name', + avatar: 'test.jpg', + }), + }), + reports: ImmutableMap({ + new: { + account_id: '1', + status_ids: ImmutableSet(['1']), + }, + }), + statuses: ImmutableMap({ + '1': normalizeStatus(status), + }), + rules: { + items: rules, + }, + }; + + __stub(mock => { + mock.onGet('/api/v1/instance/rules').reply(200, rules); + mock.onPost('/api/v1/reports').reply(200, {}); + }); + }); + + it('successfully renders the first step', () => { + render(, {}, store); + expect(screen.getByText('Reason for reporting')).toBeInTheDocument(); + }); + + it('successfully moves to the second step', async() => { + const user = userEvent.setup(); + render(, {}, store); + await user.click(screen.getByTestId('rule-1')); + await user.click(screen.getByText('Next')); + expect(screen.getByText(/Further actions:/)).toBeInTheDocument(); + }); + + it('successfully moves to the third step', async() => { + const user = userEvent.setup(); + render(, {}, store); + await user.click(screen.getByTestId('rule-1')); + await user.click(screen.getByText(/Next/)); + await user.click(screen.getByText(/Submit/)); + expect(screen.getByText(/Thanks for submitting your report/)).toBeInTheDocument(); + }); +}); diff --git a/app/soapbox/features/ui/components/modals/report-modal/steps/reason-step.tsx b/app/soapbox/features/ui/components/modals/report-modal/steps/reason-step.tsx index e8a6d07ef9..8bd5a48607 100644 --- a/app/soapbox/features/ui/components/modals/report-modal/steps/reason-step.tsx +++ b/app/soapbox/features/ui/components/modals/report-modal/steps/reason-step.tsx @@ -127,6 +127,7 @@ const ReasonStep = (_props: IReasonStep) => { return (