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
Ayush Sharma 9cd3ccb408 fix: login without reload (#678) (#679) (#914)
* fix: login without reload (#678) (#679)

* fix: implements code review suggestions (#914)

* refactor: adds scope to the app

* refactor: handles null value from localstorage for username

* refactor: removes text type from <Input />

* refactor: replaces isNull with isNil

* refactor: improves makeLogin method

* refactor: adds error from api constant

* fix: updates error using API_ERROR constant in tests

* refactor: updates regex for moduleMapper in jest config
2018-08-20 16:29:47 +02:00

45 lines
1.2 KiB
JavaScript

/**
* Header component
*/
import React from 'react';
import { shallow } from 'enzyme';
import Header from '../../../../src/webui/components/Header';
console.error = jest.fn();
describe('<Header /> component shallow', () => {
it('should give error for required props', () => {
shallow(<Header />);
expect(console.error).toHaveBeenCalled();
});
it('should load header component in login state', () => {
const props = {
username: 'verdaccio',
logo: 'logo.png',
scope: 'scope:',
handleLogout: jest.fn(),
toggleLoginModal: () => {}
}
const wrapper = shallow(<Header {...props} />);
wrapper.find('.header-button-logout').simulate('click');
expect(props.handleLogout).toHaveBeenCalled();
expect(wrapper.html()).toMatchSnapshot();
});
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();
expect(wrapper.html()).toMatchSnapshot();
});
})