7f3173c3 |
import { _internal } from "../action-link";
import Enzyme, { mount } from "enzyme";
|
84348047 |
import ezJson from "enzyme-to-json";
import Adapter from "enzyme-adapter-react-16";
|
cb71ce92 |
Enzyme.configure({ adapter: new Adapter() });
|
478c0afb |
|
384920b4 |
import React from "react";
import PropTypes from "prop-types";
|
28b358e1 |
const _Link = _internal.ActionLink(React, PropTypes);
|
384920b4 |
|
478c0afb |
it("dispatches an action on click", () => {
// given
const store = {
|
84348047 |
pathForAction: jest.fn(() => "/my/path"),
|
478c0afb |
dispatch: jest.fn()
};
const props = {
|
84348047 |
action: { type: "ACTION", id: "123" },
|
478c0afb |
children: "Hello World!"
};
|
28b358e1 |
class Link extends _Link {
constructor() {
super();
this.store = store;
}
}
|
478c0afb |
|
28b358e1 |
const wrapper = mount(<Link {...{ ...props, store }} />);
|
478c0afb |
// when
|
84348047 |
wrapper.simulate("click");
|
478c0afb |
//then
|
84348047 |
expect(store.pathForAction.mock.calls).toEqual([
[{ type: "ACTION", id: "123" }]
]);
expect(store.dispatch.mock.calls).toEqual([[{ type: "ACTION", id: "123" }]]);
|
478c0afb |
});
it("renders the url calculated by our internal function", () => {
// given
const store = {
|
84348047 |
pathForAction: jest.fn(() => "/my/path"),
|
478c0afb |
dispatch: jest.fn()
};
const props = {
action: {},
children: "Hello World!"
};
|
28b358e1 |
class Link extends _Link {
constructor() {
super();
this.store = store;
}
}
const wrapper = mount(<Link {...{ ...props, store }} />);
|
478c0afb |
expect(ezJson(wrapper)).toMatchSnapshot();
});
|
18e98de9 |
it("additional props are passed through", () => {
// given
const store = {
|
84348047 |
pathForAction: jest.fn(() => "/my/path"),
|
18e98de9 |
dispatch: jest.fn()
};
const props = {
action: {},
children: "Hello World!",
className: "foo"
};
|
28b358e1 |
class Link extends _Link {
constructor() {
super();
this.store = store;
}
}
const wrapper = mount(<Link {...{ ...props, store }} />);
|
18e98de9 |
expect(ezJson(wrapper)).toMatchSnapshot();
});
|