2019-07-08 00:30:01 +07:00
|
|
|
import React from 'react';
|
2019-07-29 05:12:14 +07:00
|
|
|
import { mount, shallow } from 'enzyme';
|
2019-07-08 00:30:01 +07:00
|
|
|
|
|
|
|
describe('<ActionBar /> component', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetModules();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should render the component in default state', () => {
|
|
|
|
const packageMeta = {
|
|
|
|
latest: {
|
|
|
|
homepage: 'https://verdaccio.tld',
|
|
|
|
bugs: {
|
|
|
|
url: 'https://verdaccio.tld/bugs',
|
|
|
|
},
|
|
|
|
dist: {
|
2019-07-08 13:36:10 +07:00
|
|
|
tarball: 'https://verdaccio.tld/download',
|
2019-07-08 00:30:01 +07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-08-25 19:34:27 +07:00
|
|
|
jest.doMock('../../pages/Version', () => ({
|
2019-07-08 00:30:01 +07:00
|
|
|
DetailContextConsumer: component => {
|
|
|
|
return component.children({ packageMeta });
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
const ActionBar = require('./ActionBar').default;
|
|
|
|
const wrapper = shallow(<ActionBar />);
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when there is no action bar data', () => {
|
|
|
|
const packageMeta = {
|
|
|
|
latest: {},
|
|
|
|
};
|
|
|
|
|
2019-08-25 19:34:27 +07:00
|
|
|
jest.doMock('../../pages/Version', () => ({
|
2019-07-08 00:30:01 +07:00
|
|
|
DetailContextConsumer: component => {
|
|
|
|
return component.children({ packageMeta });
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
const ActionBar = require('./ActionBar').default;
|
|
|
|
const wrapper = shallow(<ActionBar />);
|
2019-07-29 05:12:14 +07:00
|
|
|
// FIXME: this only renders the DetailContextConsumer, thus
|
2019-07-29 13:42:37 +07:00
|
|
|
// the wrapper will be always empty
|
2019-07-08 00:30:01 +07:00
|
|
|
expect(wrapper.html()).toEqual('');
|
|
|
|
});
|
2019-07-29 05:12:14 +07:00
|
|
|
|
|
|
|
test('when there is a button to download a tarball', () => {
|
|
|
|
const packageMeta = {
|
|
|
|
latest: {
|
|
|
|
dist: {
|
|
|
|
tarball: 'http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-08-25 19:34:27 +07:00
|
|
|
jest.doMock('../../pages/Version', () => ({
|
2019-07-29 05:12:14 +07:00
|
|
|
DetailContextConsumer: component => {
|
|
|
|
return component.children({ packageMeta });
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
const ActionBar = require('./ActionBar').default;
|
|
|
|
const wrapper = mount(<ActionBar />);
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
|
|
|
|
const button = wrapper.find('button');
|
|
|
|
expect(button).toHaveLength(1);
|
|
|
|
});
|
2019-07-08 00:30:01 +07:00
|
|
|
});
|