1
0
mirror of https://github.com/SomboChea/ui synced 2026-01-17 00:25:50 +07:00

chore: adds unit tests for <Repository /> component

This commit is contained in:
Ayush Sharma
2019-07-09 23:48:26 +02:00
parent 6afc2c0e54
commit 9e0c9db78c
2 changed files with 59 additions and 2 deletions

View File

@@ -1,11 +1,68 @@
import React from 'react';
import { shallow } from 'enzyme';
import Repository from './Repository';
jest.mock('./img/git.png', () => '');
describe('<Repository /> component', () => {
beforeEach(() => {
jest.resetModules();
});
test('should render the component in default state', () => {
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;
const wrapper = shallow(<Repository />);
expect(wrapper.html()).toMatchSnapshot();
});
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('');
});
});