react-spatial
Version:
Components to build React map apps.
65 lines (56 loc) • 2.36 kB
JavaScript
import React from 'react';
import renderer from 'react-test-renderer';
import { configure, shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { FaGithub } from 'react-icons/fa';
import ActionLink from '../ActionLink';
import SidebarMenuItem from './SidebarMenuItem';
configure({ adapter: new Adapter() });
describe('SidebarMenuItem', function () {
test('should match snapshot.', function () {
var component = renderer.create(
React.createElement( SidebarMenuItem, { title: "Title", icon: React.createElement( FaGithub, null ), onClick: function () {} })
);
var tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
test('should match snapshot with props "showIconOnly".', function () {
var component = renderer.create(
React.createElement( SidebarMenuItem, {
title: "Title", icon: React.createElement( FaGithub, null ), onClick: function () {}, showIconOnly: true })
);
var tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
test('should match snapshot with props "active".', function () {
var component = renderer.create(
React.createElement( SidebarMenuItem, {
title: "Title", icon: React.createElement( FaGithub, null ), onClick: function () {}, active: true })
);
var tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
test('should match snapshot with ActionLink as body.', function () {
var component = renderer.create(
React.createElement( SidebarMenuItem, { title: "Title", icon: React.createElement( FaGithub, null ), onClick: function () {} },
React.createElement( ActionLink, { onClick: function () {} }, "Click Me!")
)
);
var tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
test('Should trigger onClick.', function () {
var funcs = { onClick: function () {} };
var spy = jest.spyOn(funcs, 'onClick');
var item = shallow(
React.createElement( SidebarMenuItem, {
title: "Title", icon: React.createElement( FaGithub, null ), className: "item-class", onClick: function () { return funcs.onClick(); }, showIconOnly: true })
);
item
.find('.item-class')
.first()
.simulate('click');
expect(spy).toHaveBeenCalledTimes(1);
});
});
//# sourceMappingURL=SidebarMenuItem.test.js.map