You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
3.2 KiB
109 lines
3.2 KiB
4 years ago
|
import React from 'react';
|
||
|
import { shallow } from 'enzyme';
|
||
|
import sinon from 'sinon';
|
||
|
import ReactCSSTransitionGroup from 'react-transition-group/CSSTransitionGroup';
|
||
4 years ago
|
import CustomizeGas from '../gas-customization/gas-modal-page-container';
|
||
|
import Sidebar from './sidebar.component';
|
||
6 years ago
|
|
||
|
const propsMethodSpies = {
|
||
|
hideSidebar: sinon.spy(),
|
||
4 years ago
|
};
|
||
6 years ago
|
|
||
4 years ago
|
describe('Sidebar Component', () => {
|
||
4 years ago
|
let wrapper;
|
||
6 years ago
|
|
||
4 years ago
|
beforeEach(() => {
|
||
4 years ago
|
wrapper = shallow(
|
||
5 years ago
|
<Sidebar
|
||
|
sidebarOpen={false}
|
||
|
hideSidebar={propsMethodSpies.hideSidebar}
|
||
|
transitionName="someTransition"
|
||
5 years ago
|
type="customize-gas"
|
||
4 years ago
|
/>,
|
||
4 years ago
|
);
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
afterEach(() => {
|
||
4 years ago
|
propsMethodSpies.hideSidebar.resetHistory();
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('renderOverlay', () => {
|
||
4 years ago
|
let renderOverlay;
|
||
6 years ago
|
|
||
4 years ago
|
beforeEach(() => {
|
||
4 years ago
|
renderOverlay = shallow(wrapper.instance().renderOverlay());
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should render a overlay element', () => {
|
||
|
expect(renderOverlay.hasClass('sidebar-overlay')).toStrictEqual(true);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should pass the correct onClick function to the element', () => {
|
||
|
expect(propsMethodSpies.hideSidebar.callCount).toStrictEqual(0);
|
||
4 years ago
|
renderOverlay.props().onClick();
|
||
4 years ago
|
expect(propsMethodSpies.hideSidebar.callCount).toStrictEqual(1);
|
||
4 years ago
|
});
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('renderSidebarContent', () => {
|
||
4 years ago
|
let renderSidebarContent;
|
||
6 years ago
|
|
||
4 years ago
|
beforeEach(() => {
|
||
4 years ago
|
renderSidebarContent = wrapper.instance().renderSidebarContent();
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should render sidebar content with the type customize-gas', () => {
|
||
4 years ago
|
renderSidebarContent = wrapper.instance().renderSidebarContent();
|
||
|
const renderedSidebarContent = shallow(renderSidebarContent);
|
||
4 years ago
|
expect(renderedSidebarContent.hasClass('sidebar-left')).toStrictEqual(
|
||
|
true,
|
||
|
);
|
||
|
expect(renderedSidebarContent.childAt(0).is(CustomizeGas)).toStrictEqual(
|
||
|
true,
|
||
|
);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should not render with an unrecognized type', () => {
|
||
4 years ago
|
wrapper.setProps({ type: 'foobar' });
|
||
|
renderSidebarContent = wrapper.instance().renderSidebarContent();
|
||
4 years ago
|
expect(renderSidebarContent).toBeNull();
|
||
4 years ago
|
});
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('render', () => {
|
||
|
it('should render a div with one child', () => {
|
||
|
expect(wrapper.is('div')).toStrictEqual(true);
|
||
|
expect(wrapper.children()).toHaveLength(1);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should render the ReactCSSTransitionGroup without any children', () => {
|
||
|
expect(
|
||
|
wrapper.children().at(0).is(ReactCSSTransitionGroup),
|
||
|
).toStrictEqual(true);
|
||
|
expect(wrapper.children().at(0).children()).toHaveLength(0);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should render sidebar content and the overlay if sidebarOpen is true', () => {
|
||
4 years ago
|
wrapper.setProps({ sidebarOpen: true });
|
||
4 years ago
|
expect(wrapper.children()).toHaveLength(2);
|
||
|
expect(
|
||
|
wrapper.children().at(1).hasClass('sidebar-overlay'),
|
||
|
).toStrictEqual(true);
|
||
|
expect(wrapper.children().at(0).children()).toHaveLength(1);
|
||
|
expect(
|
||
4 years ago
|
wrapper.children().at(0).children().at(0).hasClass('sidebar-left'),
|
||
4 years ago
|
).toStrictEqual(true);
|
||
|
expect(
|
||
4 years ago
|
wrapper
|
||
|
.children()
|
||
|
.at(0)
|
||
|
.children()
|
||
|
.at(0)
|
||
|
.children()
|
||
|
.at(0)
|
||
|
.is(CustomizeGas),
|
||
4 years ago
|
).toBe(true);
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|