summaryrefslogtreecommitdiffstats
path: root/frontend/__tests__/ResetRequest.test.js
blob: 6d8d99fad8aae03a6dffb2b62e4a2c4363af0ff8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React from 'react';
import { mount } from 'enzyme';
import toJSON from 'enzyme-to-json';
import { ApolloProvider } from 'react-apollo';
import ResetRequest from '../components/ResetRequest';
import mountOptions from './mockMang';

describe('<ResetRequest/>', () => {
  it('renders and matches snapshot', async () => {
    const wrapper = mount(<ResetRequest />, mountOptions);
    const Form = wrapper.find("Form[data-test='ResetRequest']");
    expect(toJSON(Form)).toMatchSnapshot();
  });

  it('calls the mutation', async () => {
    const wrapper = mount(<ResetRequest />, mountOptions);
    const mutation = wrapper.find('Mutation').instance();
    const input = wrapper.find('input[name="email"]');
    input.simulate('change', { target: { name: 'email', value: 'wesbos@gmail.com' } });
    // Create a spy function on mutate
    mutation.client.mutate = jest.fn();
    mutation.forceUpdate();
    wrapper.find('Form').simulate('submit');
    expect(mutation.client.mutate.mock.calls[0][0].variables).toEqual({
      email: 'wesbos@gmail.com',
    });
    expect(toJSON(wrapper)).toMatchSnapshot();
  });

  it('renders errors', () => {
    const wrapper = mount(<ResetRequest />, mountOptions);
    const mutation = wrapper.find('Mutation').instance();
    mutation.setState({ error: { message: 'Shit!' } });
    wrapper.update();
    const error = wrapper.find('DisplayError');
    expect(error).toHaveLength(1);
    expect(toJSON(error)).toMatchSnapshot();
  });
});