84348047 |
import ActionLink from "./action-link";
import { mount } from "enzyme";
import ezJson from "enzyme-to-json";
import Enzyme from "enzyme";
import Adapter from "enzyme-adapter-react-16";
|
cb71ce92 |
Enzyme.configure({ adapter: new Adapter() });
|
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!"
};
|
84348047 |
const context = { store };
|
478c0afb |
const wrapper = mount(ActionLink(props, context));
// 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!"
};
|
84348047 |
const context = { store };
|
478c0afb |
const wrapper = mount(ActionLink(props, context));
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"
};
|
84348047 |
const context = { store };
|
18e98de9 |
const wrapper = mount(ActionLink(props, context));
expect(ezJson(wrapper)).toMatchSnapshot();
});
|