it('dispatches when the send button is clicked if textarea has text', () => {
    const addon = { ...fakeAddon, slug: 'which-browser' };
    const fakeEvent = createFakeEvent();
    const { store } = dispatchClientMetadata();
    const dispatchSpy = sinon.spy(store, 'dispatch');
    const root = renderMount({ addon, store });

    // This simulates entering text into the textarea.
    const textarea = root.find('.ReportAbuseButton-textarea > textarea');
    textarea.instance().value = 'Opera did it first!';
    textarea.simulate('change');

    root
      .find('button.ReportAbuseButton-send-report')
      .simulate('click', fakeEvent);
    sinon.assert.calledWith(
      dispatchSpy,
      sendAddonAbuseReport({
        addonSlug: addon.slug,
        errorHandlerId: 'create-stub-error-handler-id',
        message: 'Opera did it first!',
      }),
    );
    sinon.assert.called(fakeEvent.preventDefault);
  });
  it('disables the buttons while sending the abuse report', () => {
    const addon = { ...fakeAddon, slug: 'bank-machine-skimmer' };
    const fakeEvent = createFakeEvent();
    const { store } = dispatchClientMetadata();
    store.dispatch(
      sendAddonAbuseReport({
        addonSlug: addon.slug,
        errorHandlerId: 'my-error',
        message: 'All my money is gone',
      }),
    );
    const root = renderMount({ addon, store });

    // Expand the view so we can test that it wasn't contracted when
    // clicking on the disabled "dismiss" link.
    root
      .find('button.ReportAbuseButton-show-more')
      .simulate('click', fakeEvent);
    expect(root.find('.ReportAbuseButton--is-expanded')).toHaveLength(1);

    const dismissButton = root.find('.ReportAbuseButton-dismiss-report');
    const sendButton = root.find('button.ReportAbuseButton-send-report');

    expect(dismissButton).toHaveClassName(
      'ReportAbuseButton-dismiss-report--disabled',
    );
    expect(sendButton.prop('disabled')).toEqual(true);
    expect(sendButton.prop('children')).toEqual('Sending abuse report');

    dismissButton.simulate('click', fakeEvent);
    sinon.assert.called(fakeEvent.preventDefault);
    expect(root.find('.ReportAbuseButton--is-expanded')).toHaveLength(1);
  });
Beispiel #3
0
 function _sendAddonAbuseReport(params) {
   sagaTester.dispatch(
     sendAddonAbuseReport({
       addonSlug: fakeAddon.slug,
       errorHandlerId: errorHandler.id,
       message: 'Testing',
       ...params,
     }),
   );
 }
Beispiel #4
0
  sendReport = ({ text }: OnSubmitParams) => {
    // The button isn't clickable if there is no content, but just in case:
    // we verify there's a message to send.
    if (!text.trim().length) {
      log.debug(oneLine`User managed to click submit button while textarea
        was empty. Ignoring this onClick/sendReport event.`);
      return;
    }

    const { addon, dispatch, errorHandler } = this.props;

    dispatch(
      sendAddonAbuseReport({
        addonSlug: addon.slug,
        errorHandlerId: errorHandler.id,
        message: text,
      }),
    );
  };
        expect(() => {
          const partialParams = { ...defaultParams };
          delete partialParams.message;

          sendAddonAbuseReport(partialParams);
        }).toThrow('message is required');
        expect(() => {
          const partialParams = { ...defaultParams };
          delete partialParams.errorHandlerId;

          sendAddonAbuseReport(partialParams);
        }).toThrow('errorHandlerId is required');
        expect(() => {
          const partialParams = { ...defaultParams };
          delete partialParams.addonSlug;

          sendAddonAbuseReport(partialParams);
        }).toThrow('addonSlug is required');
      it('dispatches a sendAddonAbuseReport', () => {
        const action = sendAddonAbuseReport(defaultParams);

        expect(action.type).toEqual(SEND_ADDON_ABUSE_REPORT);
        expect(action.payload).toEqual(defaultParams);
      });