1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/test/unit/webui/components/header.spec.js
Priscila 9d265996f9 Refactor: Moved Search to Header (#1064)
* refactor: Moved Search to Header

feat: added TxtField. WIP

refactor: replaced downshift by react-autosuggest

refactor: moved search's state

refactor: introduced weight 300 & 500

refactor: changed container css margin

refactor: made it more abstract

refactor: replaced name by label. changed css

refactor: removed aria

refactor: removed margin

fix: fixed flow  types

fix: fixed tags overlapping

fix: fixed search. WIP

refactor: removed useless library and added rect-router

refactor: fixed tests

* chore: remove tpm file

* feat: added component Loading

feat: added component Layout

refactor: changed css

refactor: added md prop

refactor: moved Header back to App

* chore: fix flow

* fix: update snapshot

fix: fixed componentDidMount parameter

refactor: added onKeyDown event

fix: fixed bad request

refactor: renamed interfaces files

refactor: refactor: logic display results

refactor: changed minor things

fix: fixed tests

fix: fixed tests
2018-10-27 21:19:45 +02:00

103 lines
2.8 KiB
JavaScript

/**
* @prettier
* @flow
*/
import React from 'react';
import { mount } from 'enzyme';
import Header from '../../../../src/webui/components/Header';
describe('<Header /> component with logged in state', () => {
let wrapper;
let props;
beforeEach(() => {
props = {
username: 'test user',
handleLogout: jest.fn(),
toggleLoginModal: jest.fn(),
scope: 'test scope',
withoutSearch: true,
};
wrapper = mount(<Header {...props} />);
});
test('should load the component in logged in state', () => {
const state = {
openInfoDialog: false,
packages: undefined,
registryUrl: 'http://localhost',
showMobileNavBar: false,
};
expect(wrapper.state()).toEqual(state);
expect(wrapper.html()).toMatchSnapshot();
});
test('handleLoggedInMenu: set anchorEl to html element value in state', () => {
const { handleLoggedInMenu } = wrapper.instance();
// creates a sample menu
const div = document.createElement('div');
const text = document.createTextNode('sample menu');
div.appendChild(text);
const event = {
currentTarget: div,
};
handleLoggedInMenu(event);
expect(wrapper.state('anchorEl')).toEqual(div);
});
});
describe('<Header /> component with logged out state', () => {
let wrapper;
let props;
beforeEach(() => {
props = {
handleLogout: jest.fn(),
toggleLoginModal: jest.fn(),
scope: 'test scope',
withoutSearch: true,
};
wrapper = mount(<Header {...props} />);
});
test('should load the component in logged out state', () => {
const state = {
openInfoDialog: false,
packages: undefined,
registryUrl: 'http://localhost',
showMobileNavBar: false,
};
expect(wrapper.state()).toEqual(state);
expect(wrapper.html()).toMatchSnapshot();
});
test('handleLoggedInMenuClose: set anchorEl value to null in state', () => {
const { handleLoggedInMenuClose } = wrapper.instance();
handleLoggedInMenuClose();
expect(wrapper.state('anchorEl')).toBeNull();
});
test('handleOpenRegistryInfoDialog: set openInfoDialog to be truthy in state', () => {
const { handleOpenRegistryInfoDialog } = wrapper.instance();
handleOpenRegistryInfoDialog();
expect(wrapper.state('openInfoDialog')).toBeTruthy();
});
test('handleCloseRegistryInfoDialog: set openInfoDialog to be falsy in state', () => {
const { handleCloseRegistryInfoDialog } = wrapper.instance();
handleCloseRegistryInfoDialog();
expect(wrapper.state('openInfoDialog')).toBeFalsy();
});
test('handleToggleLogin: close/open popover menu', () => {
const { handleToggleLogin } = wrapper.instance();
handleToggleLogin();
expect(wrapper.state('anchorEl')).toBeNull();
expect(props.toggleLoginModal).toHaveBeenCalled();
});
});