2017-12-01 14:04:01 -05:00
|
|
|
/**
|
|
|
|
* Header component
|
|
|
|
*/
|
|
|
|
import React from 'react';
|
2018-08-20 09:29:47 -05:00
|
|
|
import { shallow } from 'enzyme';
|
2018-07-17 14:22:44 -05:00
|
|
|
import Header from '../../../../src/webui/components/Header';
|
2017-12-03 05:14:17 -05:00
|
|
|
|
2018-08-01 08:00:39 -05:00
|
|
|
console.error = jest.fn();
|
|
|
|
|
2017-12-01 14:04:01 -05:00
|
|
|
describe('<Header /> component shallow', () => {
|
|
|
|
|
2018-08-20 09:29:47 -05:00
|
|
|
it('should give error for required props', () => {
|
|
|
|
shallow(<Header />);
|
|
|
|
expect(console.error).toHaveBeenCalled();
|
2017-12-01 14:04:01 -05:00
|
|
|
});
|
|
|
|
|
2018-08-20 09:29:47 -05:00
|
|
|
it('should load header component in login state', () => {
|
|
|
|
const props = {
|
|
|
|
username: 'verdaccio',
|
|
|
|
logo: 'logo.png',
|
|
|
|
scope: 'scope:',
|
|
|
|
handleLogout: jest.fn(),
|
|
|
|
toggleLoginModal: () => {}
|
2018-08-01 08:00:39 -05:00
|
|
|
}
|
2018-08-20 09:29:47 -05:00
|
|
|
const wrapper = shallow(<Header {...props} />);
|
|
|
|
wrapper.find('.header-button-logout').simulate('click');
|
|
|
|
expect(props.handleLogout).toHaveBeenCalled();
|
2017-12-02 09:01:06 -05:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2018-08-01 08:00:39 -05:00
|
|
|
|
2018-08-20 09:29:47 -05:00
|
|
|
it('should load header component in logout state', () => {
|
|
|
|
const props = {
|
|
|
|
username: undefined,
|
|
|
|
logo: 'logo.png',
|
|
|
|
scope: 'scope:',
|
|
|
|
handleLogout: () => {},
|
|
|
|
toggleLoginModal: jest.fn()
|
|
|
|
}
|
|
|
|
const wrapper = shallow(<Header {...props} />);
|
|
|
|
wrapper.find('.header-button-login').simulate('click');
|
|
|
|
expect(props.toggleLoginModal).toHaveBeenCalled();
|
2018-08-01 08:00:39 -05:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
})
|