2019-04-05 02:23:40 +07:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
|
2019-07-10 04:48:26 +07:00
|
|
|
jest.mock('./img/git.png', () => '');
|
2019-04-05 02:23:40 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
describe('<Repository /> component', () => {
|
2019-07-10 04:48:26 +07:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetModules();
|
|
|
|
});
|
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
jest.doMock('../../pages/version/Version', () => ({
|
|
|
|
DetailContextConsumer: component => {
|
|
|
|
return component.children({ packageMeta });
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
const Repository = require('./Repository').default;
|
2019-06-20 19:37:28 +07:00
|
|
|
const wrapper = shallow(<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: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
jest.doMock('../../pages/version/Version', () => ({
|
|
|
|
DetailContextConsumer: component => {
|
|
|
|
return component.children({ packageMeta });
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
const Repository = require('./Repository').default;
|
|
|
|
const wrapper = shallow(<Repository />);
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
jest.doMock('../../pages/version/Version', () => ({
|
|
|
|
DetailContextConsumer: component => {
|
|
|
|
return component.children({ packageMeta });
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
|
|
|
const Repository = require('./Repository').default;
|
|
|
|
const wrapper = shallow(<Repository />);
|
|
|
|
expect(wrapper.html()).toEqual('');
|
|
|
|
});
|
2019-04-05 02:23:40 +07:00
|
|
|
});
|