2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import ReactCSSTransitionGroup from 'react-transition-group/CSSTransitionGroup';
|
2021-03-16 22:00:08 +01:00
|
|
|
import CustomizeGas from '../gas-customization/gas-modal-page-container';
|
|
|
|
import Sidebar from './sidebar.component';
|
2018-08-23 04:27:35 +02:00
|
|
|
|
|
|
|
const propsMethodSpies = {
|
|
|
|
hideSidebar: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-23 04:27:35 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Sidebar Component', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
2018-08-23 04:27:35 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper = shallow(
|
2019-12-03 17:35:44 +01:00
|
|
|
<Sidebar
|
|
|
|
sidebarOpen={false}
|
|
|
|
hideSidebar={propsMethodSpies.hideSidebar}
|
|
|
|
transitionName="someTransition"
|
2020-04-01 18:35:07 +02:00
|
|
|
type="customize-gas"
|
2020-11-03 00:41:28 +01:00
|
|
|
/>,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2018-08-23 04:27:35 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
propsMethodSpies.hideSidebar.resetHistory();
|
|
|
|
});
|
2018-08-23 04:27:35 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('renderOverlay', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let renderOverlay;
|
2018-08-23 04:27:35 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
renderOverlay = shallow(wrapper.instance().renderOverlay());
|
|
|
|
});
|
2018-08-23 04:27:35 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render a overlay element', () => {
|
|
|
|
expect(renderOverlay.hasClass('sidebar-overlay')).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-08-23 04:27:35 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should pass the correct onClick function to the element', () => {
|
|
|
|
expect(propsMethodSpies.hideSidebar.callCount).toStrictEqual(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
renderOverlay.props().onClick();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(propsMethodSpies.hideSidebar.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-08-23 04:27:35 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('renderSidebarContent', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let renderSidebarContent;
|
2018-08-23 04:27:35 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
renderSidebarContent = wrapper.instance().renderSidebarContent();
|
|
|
|
});
|
2018-08-23 04:27:35 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render sidebar content with the type customize-gas', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
renderSidebarContent = wrapper.instance().renderSidebarContent();
|
|
|
|
const renderedSidebarContent = shallow(renderSidebarContent);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderedSidebarContent.hasClass('sidebar-left')).toStrictEqual(
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
expect(renderedSidebarContent.childAt(0).is(CustomizeGas)).toStrictEqual(
|
|
|
|
true,
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-10-26 07:50:36 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should not render with an unrecognized type', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.setProps({ type: 'foobar' });
|
|
|
|
renderSidebarContent = wrapper.instance().renderSidebarContent();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderSidebarContent).toBeNull();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-08-23 04:27:35 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('render', () => {
|
|
|
|
it('should render a div with one child', () => {
|
|
|
|
expect(wrapper.is('div')).toStrictEqual(true);
|
|
|
|
expect(wrapper.children()).toHaveLength(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-08-23 04:27:35 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
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);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-08-23 04:27:35 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render sidebar content and the overlay if sidebarOpen is true', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.setProps({ sidebarOpen: true });
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(wrapper.children()).toHaveLength(2);
|
|
|
|
expect(
|
|
|
|
wrapper.children().at(1).hasClass('sidebar-overlay'),
|
|
|
|
).toStrictEqual(true);
|
|
|
|
expect(wrapper.children().at(0).children()).toHaveLength(1);
|
|
|
|
expect(
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.children().at(0).children().at(0).hasClass('sidebar-left'),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(true);
|
|
|
|
expect(
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper
|
|
|
|
.children()
|
|
|
|
.at(0)
|
|
|
|
.children()
|
|
|
|
.at(0)
|
|
|
|
.children()
|
|
|
|
.at(0)
|
|
|
|
.is(CustomizeGas),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toBe(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|