2019-07-08 00:30:01 +07:00
|
|
|
import React from 'react';
|
2019-08-31 16:02:46 +07:00
|
|
|
import { mount } from 'enzyme';
|
2019-10-08 03:19:18 +07:00
|
|
|
|
2019-10-26 17:02:03 +07:00
|
|
|
import api from '../../utils/api';
|
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
import { ActionBar } from './ActionBar';
|
|
|
|
|
2019-10-03 18:23:11 +07:00
|
|
|
const mockPackageMeta: jest.Mock = jest.fn(() => ({
|
2019-08-31 16:02:46 +07:00
|
|
|
latest: {
|
|
|
|
homepage: 'https://verdaccio.tld',
|
|
|
|
bugs: {
|
|
|
|
url: 'https://verdaccio.tld/bugs',
|
|
|
|
},
|
|
|
|
dist: {
|
|
|
|
tarball: 'https://verdaccio.tld/download',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('../../pages/Version', () => ({
|
|
|
|
DetailContextConsumer: component => {
|
|
|
|
return component.children({ packageMeta: mockPackageMeta() });
|
|
|
|
},
|
|
|
|
}));
|
2019-07-08 00:30:01 +07:00
|
|
|
|
|
|
|
describe('<ActionBar /> component', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetModules();
|
2019-08-31 16:02:46 +07:00
|
|
|
jest.resetAllMocks();
|
2019-07-08 00:30:01 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should render the component in default state', () => {
|
2019-08-31 16:02:46 +07:00
|
|
|
const wrapper = mount(<ActionBar />);
|
2019-07-08 00:30:01 +07:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when there is no action bar data', () => {
|
2019-08-31 16:02:46 +07:00
|
|
|
mockPackageMeta.mockImplementation(() => ({
|
2019-07-08 00:30:01 +07:00
|
|
|
latest: {},
|
|
|
|
}));
|
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
const wrapper = mount(<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
|
|
|
|
2019-10-26 17:02:03 +07:00
|
|
|
test('when there is no latest property in package meta', () => {
|
|
|
|
mockPackageMeta.mockImplementation(() => ({}));
|
|
|
|
const wrapper = mount(<ActionBar />);
|
|
|
|
expect(wrapper.html()).toEqual('');
|
|
|
|
});
|
|
|
|
|
2019-07-29 05:12:14 +07:00
|
|
|
test('when there is a button to download a tarball', () => {
|
2019-08-31 16:02:46 +07:00
|
|
|
mockPackageMeta.mockImplementation(() => ({
|
2019-07-29 05:12:14 +07:00
|
|
|
latest: {
|
|
|
|
dist: {
|
|
|
|
tarball: 'http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
const wrapper = mount(<ActionBar />);
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
|
|
|
|
const button = wrapper.find('button');
|
|
|
|
expect(button).toHaveLength(1);
|
2019-10-26 17:02:03 +07:00
|
|
|
|
|
|
|
const spy = jest.spyOn(api, 'request');
|
|
|
|
button.simulate('click');
|
|
|
|
expect(spy).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when there is a button to open an issue', () => {
|
|
|
|
mockPackageMeta.mockImplementation(() => ({
|
|
|
|
latest: {
|
|
|
|
bugs: {
|
|
|
|
url: 'https://verdaccio.tld/bugs',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
const wrapper = mount(<ActionBar />);
|
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
|
|
|
|
const button = wrapper.find('button');
|
|
|
|
expect(button).toHaveLength(1);
|
2019-07-29 05:12:14 +07:00
|
|
|
});
|
2019-07-08 00:30:01 +07:00
|
|
|
});
|