2017-12-01 20:04:01 +01:00
|
|
|
/**
|
2018-09-24 22:04:37 +02:00
|
|
|
* @prettier
|
|
|
|
* @flow
|
2017-12-01 20:04:01 +01:00
|
|
|
*/
|
2018-09-24 22:04:37 +02:00
|
|
|
|
2017-12-01 20:04:01 +01:00
|
|
|
import React from 'react';
|
2018-10-01 07:06:30 +02:00
|
|
|
import { mount } 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-09-24 22:04:37 +02:00
|
|
|
describe('<Header /> component with logged in state', () => {
|
|
|
|
let wrapper;
|
|
|
|
let props;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
props = {
|
|
|
|
username: 'test user',
|
|
|
|
handleLogout: jest.fn(),
|
2018-12-15 09:18:26 +01:00
|
|
|
onToggleLoginModal: jest.fn(),
|
2018-09-24 22:04:37 +02:00
|
|
|
scope: 'test scope',
|
2018-10-27 21:19:45 +02:00
|
|
|
withoutSearch: true,
|
2018-09-24 22:04:37 +02:00
|
|
|
};
|
|
|
|
wrapper = mount(<Header {...props} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should load the component in logged in state', () => {
|
2018-10-27 21:19:45 +02:00
|
|
|
const state = {
|
|
|
|
openInfoDialog: false,
|
|
|
|
packages: undefined,
|
|
|
|
registryUrl: 'http://localhost',
|
|
|
|
showMobileNavBar: false,
|
|
|
|
};
|
2018-09-24 22:04:37 +02:00
|
|
|
expect(wrapper.state()).toEqual(state);
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('handleLoggedInMenu: set anchorEl to html element value in state', () => {
|
2018-10-01 07:06:30 +02:00
|
|
|
const { handleLoggedInMenu } = wrapper.instance();
|
2018-08-01 15:00:39 +02:00
|
|
|
|
2018-09-24 22:04:37 +02:00
|
|
|
// creates a sample menu
|
|
|
|
const div = document.createElement('div');
|
|
|
|
const text = document.createTextNode('sample menu');
|
|
|
|
div.appendChild(text);
|
2017-12-01 20:04:01 +01:00
|
|
|
|
2018-09-24 22:04:37 +02:00
|
|
|
const event = {
|
|
|
|
currentTarget: div,
|
|
|
|
};
|
|
|
|
|
|
|
|
handleLoggedInMenu(event);
|
|
|
|
expect(wrapper.state('anchorEl')).toEqual(div);
|
2017-12-01 20:04:01 +01:00
|
|
|
});
|
2018-09-24 22:04:37 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('<Header /> component with logged out state', () => {
|
|
|
|
let wrapper;
|
|
|
|
let props;
|
2017-12-01 20:04:01 +01:00
|
|
|
|
2018-09-24 22:04:37 +02:00
|
|
|
beforeEach(() => {
|
|
|
|
props = {
|
2018-08-20 16:29:47 +02:00
|
|
|
handleLogout: jest.fn(),
|
2018-12-15 09:18:26 +01:00
|
|
|
onToggleLoginModal: jest.fn(),
|
2018-09-24 22:04:37 +02:00
|
|
|
scope: 'test scope',
|
2018-10-27 21:19:45 +02:00
|
|
|
withoutSearch: true,
|
2018-09-24 22:04:37 +02:00
|
|
|
};
|
|
|
|
wrapper = mount(<Header {...props} />);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should load the component in logged out state', () => {
|
2018-10-27 21:19:45 +02:00
|
|
|
const state = {
|
|
|
|
openInfoDialog: false,
|
|
|
|
packages: undefined,
|
|
|
|
registryUrl: 'http://localhost',
|
|
|
|
showMobileNavBar: false,
|
|
|
|
};
|
2018-09-24 22:04:37 +02:00
|
|
|
expect(wrapper.state()).toEqual(state);
|
2017-12-02 15:01:06 +01:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2018-08-01 15:00:39 +02:00
|
|
|
|
2018-09-24 22:04:37 +02:00
|
|
|
test('handleLoggedInMenuClose: set anchorEl value to null in state', () => {
|
2018-10-01 07:06:30 +02:00
|
|
|
const { handleLoggedInMenuClose } = wrapper.instance();
|
2018-09-24 22:04:37 +02:00
|
|
|
handleLoggedInMenuClose();
|
|
|
|
expect(wrapper.state('anchorEl')).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('handleOpenRegistryInfoDialog: set openInfoDialog to be truthy in state', () => {
|
2018-10-01 07:06:30 +02:00
|
|
|
const { handleOpenRegistryInfoDialog } = wrapper.instance();
|
2018-09-24 22:04:37 +02:00
|
|
|
handleOpenRegistryInfoDialog();
|
|
|
|
expect(wrapper.state('openInfoDialog')).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('handleCloseRegistryInfoDialog: set openInfoDialog to be falsy in state', () => {
|
2018-10-01 07:06:30 +02:00
|
|
|
const { handleCloseRegistryInfoDialog } = wrapper.instance();
|
2018-09-24 22:04:37 +02:00
|
|
|
handleCloseRegistryInfoDialog();
|
|
|
|
expect(wrapper.state('openInfoDialog')).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('handleToggleLogin: close/open popover menu', () => {
|
2018-10-01 07:06:30 +02:00
|
|
|
const { handleToggleLogin } = wrapper.instance();
|
2018-09-24 22:04:37 +02:00
|
|
|
handleToggleLogin();
|
|
|
|
expect(wrapper.state('anchorEl')).toBeNull();
|
2018-12-15 09:18:26 +01:00
|
|
|
expect(props.onToggleLoginModal).toHaveBeenCalled();
|
2018-08-01 15:00:39 +02:00
|
|
|
});
|
2018-09-24 22:04:37 +02:00
|
|
|
});
|