2017-12-01 20:04:01 +01:00
|
|
|
/**
|
|
|
|
* Header component
|
|
|
|
*/
|
|
|
|
import React from 'react';
|
2018-08-20 16:29:47 +02:00
|
|
|
import { shallow } from 'enzyme';
|
2018-07-17 21:22:44 +02:00
|
|
|
import Header from '../../../../src/webui/components/Header';
|
2017-12-03 11:14:17 +01:00
|
|
|
|
2018-08-01 15:00:39 +02:00
|
|
|
console.error = jest.fn();
|
|
|
|
|
2017-12-01 20:04:01 +01:00
|
|
|
describe('<Header /> component shallow', () => {
|
|
|
|
|
2018-08-20 16:29:47 +02:00
|
|
|
it('should give error for required props', () => {
|
|
|
|
shallow(<Header />);
|
|
|
|
expect(console.error).toHaveBeenCalled();
|
2017-12-01 20:04:01 +01:00
|
|
|
});
|
|
|
|
|
2018-08-20 16:29:47 +02: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 15:00:39 +02:00
|
|
|
}
|
2018-08-20 16:29:47 +02:00
|
|
|
const wrapper = shallow(<Header {...props} />);
|
|
|
|
wrapper.find('.header-button-logout').simulate('click');
|
|
|
|
expect(props.handleLogout).toHaveBeenCalled();
|
2017-12-02 15:01:06 +01:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2018-08-01 15:00:39 +02:00
|
|
|
|
2018-08-20 16:29:47 +02: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 15:00:39 +02:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
})
|