import { FirstUser, mapDispatchToProps } from "../FirstUser";

describe("<FirstUser />", () => {
    let props;

    it("should render", () => {
        const wrapper = shallow(<FirstUser {...props} />);
        wrapper.setState({
            username: "foo",
            password: "bar"
        });
        expect(wrapper).toMatchSnapshot();
    });

    it("should call onSubmit when form is submitted", () => {
        props = {
            onSubmit: jest.fn()
        };
        const wrapper = shallow(<FirstUser {...props} />);
        wrapper.setState({
            username: "fee",
            password: "baz"
        });
        const e = {
            preventDefault: jest.fn()
        };
        wrapper.find("form").simulate("submit", e);
        expect(e.preventDefault).toHaveBeenCalled();
        expect(props.onSubmit).toHaveBeenCalledWith("fee", "baz");
    });

    it("should call onChange username changes", () => {
        const e = {
            target: {
                name: "username",
                value: "bar"
            }
        };
        const wrapper = shallow(<FirstUser {...props} />);
        wrapper
            .find("Input")
            .at(0)
            .prop("onChange")(e);

        expect(wrapper.state()).toEqual({
            username: "bar",
            password: ""
        });
    });

    it("should call onChange when password changes", () => {
        const e = {
            target: {
                name: "password",
                value: "foo"
            }
        };
        const wrapper = shallow(<FirstUser {...props} />);
        wrapper
            .find("Input")
            .at(1)
            .prop("onChange")(e);

        expect(wrapper.state()).toEqual({
            username: "",
            password: "foo"
        });
    });
});

describe("mapDispatchToProps", () => {
    it("should return onSubmit() on props", () => {
        const dispatch = jest.fn();
        const props = mapDispatchToProps(dispatch);

        props.onSubmit("foo", "bar");

        expect(dispatch).toHaveBeenCalledWith({
            userId: "foo",
            password: "bar",
            type: "CREATE_FIRST_USER_REQUESTED"
        });
    });
});

@@ -883,161 +883,467 @@
   it
-(%22should call onChange username changes%22, () =%3E %7B%0A        const e = %7B%0A            target: %7B%0A                name: %22username%22,%0A                value: %22bar
+.each(%5B%0A        %5B%0A            0,%0A            %7B%0A                username: %22bar%22,%0A                password: %22%22%0A            %7D%0A        %5D,%0A        %5B%0A            1,%0A            %7B%0A                username: %22%22,%0A                password: %22foo%22%0A            %7D%0A        %5D%0A    %5D)(%22.match(%25o, %25o)%22, (index, expected) =%3E %7B%0A        const e = %7B%0A            target: %7B%0A                name: index === 0 ? %22username%22 : %22password%22,%0A                value: index === 0 ? %22bar%22 : %22foo
 %22%0A  
@@ -1357,32 +1357,33 @@
    %7D%0A        %7D;%0A
+%0A
         const wr
@@ -1429,471 +1429,8 @@
 %3E);%0A
-        wrapper%0A            .find(%22Input%22)%0A            .at(0)%0A            .prop(%22onChange%22)(e);%0A%0A        expect(wrapper.state()).toEqual(%7B%0A            username: %22bar%22,%0A            password: %22%22%0A        %7D);%0A    %7D);%0A%0A    it(%22should call onChange when password changes%22, () =%3E %7B%0A        const e = %7B%0A            target: %7B%0A                name: %22password%22,%0A                value: %22foo%22%0A            %7D%0A        %7D;%0A        const wrapper = shallow(%3CFirstUser %7B...props%7D /%3E);
 %0A   
@@ -1485,17 +1485,21 @@
     .at(
-1
+index
 )%0A      
@@ -1571,73 +1571,16 @@
 ual(
-%7B%0A            username: %22%22,%0A            password: %22foo%22%0A        %7D
+expected
 );%0A 

Add test for FirstUser component