2019-04-05 02:23:40 +07:00
|
|
|
import React from 'react';
|
2019-11-23 19:41:14 +07:00
|
|
|
|
2019-12-01 22:14:17 +07:00
|
|
|
import { render } from '../../utils/test-react-testing-library';
|
|
|
|
import { DetailContext, DetailContextProps } from '../../pages/Version';
|
2019-10-08 03:19:18 +07:00
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
import Repository from './Repository';
|
2019-12-01 22:14:17 +07:00
|
|
|
import data from './__partials__/data.json';
|
2019-04-05 02:23:40 +07:00
|
|
|
|
2019-12-01 22:14:17 +07:00
|
|
|
const detailContextValue: DetailContextProps = {
|
|
|
|
packageName: 'foo',
|
|
|
|
readMe: 'readMe',
|
|
|
|
enableLoading: () => {},
|
|
|
|
isLoading: false,
|
|
|
|
hasNotBeenFound: false,
|
|
|
|
packageMeta: data,
|
|
|
|
};
|
2019-04-05 02:23:40 +07:00
|
|
|
|
2019-12-01 22:14:17 +07:00
|
|
|
const ComponentToBeRendered: React.FC<{ contextValue: DetailContextProps }> = ({ contextValue }) => (
|
|
|
|
<DetailContext.Provider value={contextValue}>
|
|
|
|
<Repository />
|
|
|
|
</DetailContext.Provider>
|
|
|
|
);
|
2019-08-31 16:02:46 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
describe('<Repository /> component', () => {
|
2019-12-01 22:14:17 +07:00
|
|
|
test('should load the component in default state', () => {
|
|
|
|
const { container } = render(<ComponentToBeRendered contextValue={detailContextValue} />);
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-07-10 04:48:26 +07:00
|
|
|
});
|
|
|
|
|
2019-12-01 22:14:17 +07:00
|
|
|
test('should render the component in with no repository data', () => {
|
2019-07-10 04:48:26 +07:00
|
|
|
const packageMeta = {
|
2019-12-01 22:14:17 +07:00
|
|
|
...detailContextValue.packageMeta,
|
2019-07-10 04:48:26 +07:00
|
|
|
latest: {
|
2019-12-01 22:14:17 +07:00
|
|
|
...detailContextValue.packageMeta?.latest,
|
|
|
|
repository: undefined,
|
2019-07-10 04:48:26 +07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-12-01 22:14:17 +07:00
|
|
|
const { queryByText } = render(
|
|
|
|
<ComponentToBeRendered
|
|
|
|
contextValue={{
|
|
|
|
...detailContextValue,
|
|
|
|
packageMeta,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
2019-07-10 04:48:26 +07:00
|
|
|
|
2019-12-01 22:14:17 +07:00
|
|
|
expect(queryByText('Repository')).toBeFalsy();
|
2019-07-10 04:48:26 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should render the component in with invalid url', () => {
|
|
|
|
const packageMeta = {
|
2019-12-01 22:14:17 +07:00
|
|
|
...detailContextValue.packageMeta,
|
2019-07-10 04:48:26 +07:00
|
|
|
latest: {
|
2019-12-01 22:14:17 +07:00
|
|
|
...detailContextValue.packageMeta?.latest,
|
2019-07-10 04:48:26 +07:00
|
|
|
repository: {
|
|
|
|
type: 'git',
|
|
|
|
url: 'git://github.com/verdaccio/ui.git',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-12-01 22:14:17 +07:00
|
|
|
const { queryByText } = render(
|
|
|
|
<ComponentToBeRendered
|
|
|
|
contextValue={{
|
|
|
|
...detailContextValue,
|
|
|
|
packageMeta,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
2019-07-10 04:48:26 +07:00
|
|
|
|
2019-12-01 22:14:17 +07:00
|
|
|
expect(queryByText('Repository')).toBeFalsy();
|
2019-07-10 04:48:26 +07:00
|
|
|
});
|
2019-04-05 02:23:40 +07:00
|
|
|
});
|