Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mirefly committed Jan 17, 2019
1 parent 33bd3e8 commit c7eded3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/amo/components/ReportAbuseButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ export class ReportAbuseButtonBase extends React.Component<InternalProps> {
placeholder={i18n.gettext(
'Explain how this add-on is violating our policies.',
)}
microButtons
/>
</div>
</div>
Expand Down
40 changes: 22 additions & 18 deletions tests/unit/amo/components/TestReportAbuseButton.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { mount } from 'enzyme';
import * as React from 'react';

import ReportAbuseButton, {
ReportAbuseButtonBase,
} from 'amo/components/ReportAbuseButton';
import { setError } from 'core/actions/errors';
import I18nProvider from 'core/i18n/Provider';
import {
loadAddonAbuseReport,
sendAddonAbuseReport,
showAddonAbuseReportUI,
hideAddonAbuseReportUI,
} from 'core/reducers/abuse';
import Button from 'ui/components/Button';
import ErrorList from 'ui/components/ErrorList';
import DismissibleTextForm from 'ui/components/DismissibleTextForm';
import {
Expand All @@ -32,14 +31,6 @@ describe(__filename, () => {
store: dispatchClientMetadata().store,
};

function renderMount({ ...props } = {}) {
return mount(
<I18nProvider i18n={props.i18n || defaultRenderProps.i18n}>
<ReportAbuseButton {...defaultRenderProps} {...props} />
</I18nProvider>,
);
}

function renderShallow({ ...props } = {}) {
return shallowUntilTarget(
<ReportAbuseButton {...defaultRenderProps} {...props} />,
Expand All @@ -53,7 +44,7 @@ describe(__filename, () => {
expect(root.find('.ReportAbuseButton')).toHaveLength(0);
});

it('render textarea and buttons when add-on exists', () => {
it('renders a DismissibleTextForm to report an add-on', () => {
const root = renderShallow();

expect(root.find('.ReportAbuseButton')).toHaveLength(1);
Expand Down Expand Up @@ -89,16 +80,14 @@ describe(__filename, () => {
const fakeEvent = createFakeEvent();
const { store } = dispatchClientMetadata();
const dispatchSpy = sinon.spy(store, 'dispatch');
// We need to use mount here because we're interacting with refs. (In
// this case, the textarea.)
const root = renderMount({ addon, store });
let root = renderShallow({ addon, store });

root
.find('button.ReportAbuseButton-show-more')
.simulate('click', fakeEvent);
root.find(Button).simulate('click', fakeEvent);

sinon.assert.called(fakeEvent.preventDefault);
sinon.assert.calledWith(dispatchSpy, showAddonAbuseReportUI({ addon }));

root = renderShallow({ addon, store });
expect(root.find('.ReportAbuseButton--is-expanded')).toHaveLength(1);
});

Expand Down Expand Up @@ -161,7 +150,22 @@ describe(__filename, () => {
const message = '';
const root = renderShallow({ addon, store });

dispatchSpy.resetHistory();
root.find(DismissibleTextForm).prop('onSubmit')({
event: fakeEvent,
text: message,
});

sinon.assert.notCalled(dispatchSpy);
});

it('does not allow dispatch if textarea is whitespace', () => {
const fakeEvent = createFakeEvent();
const addon = { ...fakeAddon, slug: 'this-should-not-happen' };
const { store } = dispatchClientMetadata();
const dispatchSpy = sinon.spy(store, 'dispatch');
const message = ' ';
const root = renderShallow({ addon, store });

root.find(DismissibleTextForm).prop('onSubmit')({
event: fakeEvent,
text: message,
Expand Down

0 comments on commit c7eded3

Please sign in to comment.