2019-04-05 02:23:40 +07:00
|
|
|
import React from 'react';
|
2019-11-23 19:41:14 +07:00
|
|
|
|
|
|
|
import { mount } from '../../utils/test-enzyme';
|
2019-10-08 03:19:18 +07:00
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
import Repository from './Repository';
|
2019-04-05 02:23:40 +07:00
|
|
|
|
2019-07-10 04:48:26 +07:00
|
|
|
jest.mock('./img/git.png', () => '');
|
2019-04-05 02:23:40 +07:00
|
|
|
|
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-06-20 19:37:28 +07:00
|
|
|
describe('<Repository /> component', () => {
|
2019-07-10 04:48:26 +07:00
|
|
|
beforeEach(() => {
|
2019-08-31 16:02:46 +07:00
|
|
|
jest.resetAllMocks();
|
2019-07-10 04:48:26 +07:00
|
|
|
});
|
|
|
|
|
2019-04-05 02:23:40 +07:00
|
|
|
test('should render the component in default state', () => {
|
2019-07-10 04:48:26 +07:00
|
|
|
const packageMeta = {
|
|
|
|
latest: {
|
|
|
|
repository: {
|
|
|
|
type: 'git',
|
|
|
|
url: 'git+https://github.com/verdaccio/ui.git',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
mockPackageMeta.mockImplementation(() => packageMeta);
|
2019-07-10 04:48:26 +07:00
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
const wrapper = mount(<Repository />);
|
2019-04-05 02:23:40 +07:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
2019-07-10 04:48:26 +07:00
|
|
|
|
|
|
|
test('should render the component in with no repository data', () => {
|
|
|
|
const packageMeta = {
|
|
|
|
latest: {},
|
|
|
|
};
|
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
mockPackageMeta.mockImplementation(() => packageMeta);
|
2019-07-10 04:48:26 +07:00
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
const wrapper = mount(<Repository />);
|
2019-07-10 04:48:26 +07:00
|
|
|
expect(wrapper.html()).toEqual('');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should render the component in with invalid url', () => {
|
|
|
|
const packageMeta = {
|
|
|
|
latest: {
|
|
|
|
repository: {
|
|
|
|
type: 'git',
|
|
|
|
url: 'git://github.com/verdaccio/ui.git',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
mockPackageMeta.mockImplementation(() => packageMeta);
|
2019-07-10 04:48:26 +07:00
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
const wrapper = mount(<Repository />);
|
2019-07-10 04:48:26 +07:00
|
|
|
expect(wrapper.html()).toEqual('');
|
|
|
|
});
|
2019-04-05 02:23:40 +07:00
|
|
|
});
|