
import React from "react";
import {createStore} from "redux";

import {leanReducer, connectLean} from "../src/lean";

import {render} from "./helpers";

describe("handler context", () => {
    test("has state from initial state", () => {
        const spy = jest.fn();
        const store = createStore(leanReducer);
        let handler = null;

        let Hello = ({name, setName}) => {
            handler = setName;
            return <div>Hello {name}</div>;
        };

        Hello = connectLean({
            scope: "ascope",
            getInitialState() {
                return {name: "from initial"};
            },
            setName() {
                spy(this.state.name);
                this.setState({name: "from handler"});
            },
        })(Hello);

        render(store, Hello);
        handler();
        expect(spy).toHaveBeenLastCalledWith("from initial");
    });
});


@@ -894,13 +894,822 @@
     %7D);%0A
+%0A    test(%22state is not overridden by map state%22, () =%3E %7B%0A        const spy = jest.fn();%0A        const store = createStore(leanReducer);%0A        let handler = null;%0A%0A        let Hello = (%7Bname, setName%7D) =%3E %7B%0A            handler = setName;%0A            return %3Cdiv%3EHello %7Bname%7D%3C/div%3E;%0A        %7D;%0A%0A        Hello = connectLean(%7B%0A            scope: %22ascope%22,%0A            getInitialState() %7B%0A                return %7Bname: %22from initial%22%7D;%0A            %7D,%0A            mapState() %7B%0A                return %7Bname: %22from mapState%22%7D;%0A            %7D,%0A            setName() %7B%0A                spy(this.state.name);%0A                this.setState(%7Bname: %22from handler%22%7D);%0A            %7D,%0A        %7D)(Hello);%0A%0A        render(store, Hello);%0A        handler();%0A        expect(spy).toHaveBeenLastCalledWith(%22from initial%22);%0A    %7D);%0A%0A
 %7D);%0A%0A

test handlers: state not overridden by mapstate