mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
refactor: adds method to load verdaccio logo
This commit is contained in:
parent
4f6fd66bf3
commit
98abac4dec
3 changed files with 23 additions and 12 deletions
|
@ -27,6 +27,7 @@ export default class Header extends React.Component {
|
|||
this.toggleLoginModal = this.toggleLoginModal.bind(this);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
this.handleInput = this.handleInput.bind(this);
|
||||
this.loadLogo = this.loadLogo.bind(this);
|
||||
}
|
||||
|
||||
toggleLoginModal() {
|
||||
|
@ -43,11 +44,16 @@ export default class Header extends React.Component {
|
|||
}
|
||||
|
||||
componentWillMount() {
|
||||
API.request('logo')
|
||||
.then((logo) => this.setState({logo}))
|
||||
.catch((error) => {
|
||||
this.loadLogo();
|
||||
}
|
||||
|
||||
async loadLogo() {
|
||||
try {
|
||||
const logo = await API.request('logo');
|
||||
this.setState({logo});
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async handleSubmit(event) {
|
||||
|
|
|
@ -34,9 +34,19 @@ describe('<Header /> component shallow', () => {
|
|||
expect(HeaderWrapper.state()).toEqual(state);
|
||||
});
|
||||
|
||||
it('should load verdaccio logo', () => {
|
||||
const HeaderWrapper = wrapper.find(Header).dive();
|
||||
const { loadLogo } = HeaderWrapper.instance();
|
||||
|
||||
loadLogo().then(() => {
|
||||
expect(HeaderWrapper.state('logo'))
|
||||
.toEqual('http://localhost/-/static/logo.png');
|
||||
});
|
||||
});
|
||||
|
||||
it('should toggleLogin modal', () => {
|
||||
const HeaderWrapper = wrapper.find(Header).dive();
|
||||
const toggleLoginModal = HeaderWrapper.instance().toggleLoginModal;
|
||||
const { toggleLoginModal } = HeaderWrapper.instance();
|
||||
|
||||
expect(toggleLoginModal()).toBeUndefined();
|
||||
expect(HeaderWrapper.state('showLogin')).toBeTruthy();
|
||||
|
@ -127,4 +137,4 @@ describe('<Header /> snapshot test', () => {
|
|||
);
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -3,10 +3,5 @@
|
|||
* @returns {promise}
|
||||
*/
|
||||
export default function() {
|
||||
const response = {
|
||||
text(){
|
||||
return 'http://xyz.com/image.jpg';
|
||||
}
|
||||
};
|
||||
return Promise.resolve(response);
|
||||
return Promise.resolve('http://localhost/-/static/logo.png');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue