2019-07-08 00:30:01 +07:00
|
|
|
import React from 'react';
|
2019-10-08 03:19:18 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
import { render, cleanup } from '../../utils/test-react-testing-library';
|
|
|
|
import { DetailContext, DetailContextProps } from '../../pages/Version';
|
|
|
|
|
|
|
|
import ActionBar from './ActionBar';
|
|
|
|
|
|
|
|
const detailContextValue: DetailContextProps = {
|
|
|
|
packageName: 'foo',
|
|
|
|
readMe: 'test',
|
|
|
|
enableLoading: () => {},
|
|
|
|
isLoading: false,
|
|
|
|
hasNotBeenFound: false,
|
|
|
|
packageMeta: {
|
|
|
|
_uplinks: {},
|
|
|
|
latest: {
|
|
|
|
name: '@verdaccio/local-storage',
|
|
|
|
version: '8.0.1-next.1',
|
|
|
|
dist: { fileCount: 0, unpackedSize: 0, tarball: 'http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz' },
|
|
|
|
homepage: 'https://verdaccio.org',
|
|
|
|
bugs: {
|
|
|
|
url: 'https://github.com/verdaccio/monorepo/issues',
|
|
|
|
},
|
2019-08-31 16:02:46 +07:00
|
|
|
},
|
|
|
|
},
|
2019-12-03 15:44:44 +07:00
|
|
|
};
|
2019-08-31 16:02:46 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
const ComponentToBeRendered: React.FC<{ contextValue: DetailContextProps }> = ({ contextValue }) => (
|
|
|
|
<DetailContext.Provider value={contextValue}>
|
|
|
|
<ActionBar />
|
|
|
|
</DetailContext.Provider>
|
|
|
|
);
|
2019-07-08 00:30:01 +07:00
|
|
|
|
|
|
|
describe('<ActionBar /> component', () => {
|
2019-12-03 15:44:44 +07:00
|
|
|
afterEach(() => {
|
|
|
|
cleanup();
|
2019-07-08 00:30:01 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should render the component in default state', () => {
|
2019-12-03 15:44:44 +07:00
|
|
|
const { container } = render(<ComponentToBeRendered contextValue={detailContextValue} />);
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-07-08 00:30:01 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('when there is no action bar data', () => {
|
2019-12-03 15:44:44 +07:00
|
|
|
const packageMeta = {
|
|
|
|
...detailContextValue.packageMeta,
|
2019-07-29 05:12:14 +07:00
|
|
|
latest: {
|
2019-12-03 15:44:44 +07:00
|
|
|
...detailContextValue.packageMeta.latest,
|
|
|
|
homepage: undefined,
|
|
|
|
bugs: undefined,
|
2019-07-29 05:12:14 +07:00
|
|
|
dist: {
|
2019-12-03 15:44:44 +07:00
|
|
|
...detailContextValue.packageMeta.latest.dist,
|
|
|
|
tarball: undefined,
|
2019-07-29 05:12:14 +07:00
|
|
|
},
|
|
|
|
},
|
2019-12-03 15:44:44 +07:00
|
|
|
};
|
2019-07-29 05:12:14 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
const { container } = render(<ComponentToBeRendered contextValue={{ ...detailContextValue, packageMeta }} />);
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
|
|
|
});
|
2019-10-26 17:02:03 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
test('when there is a button to download a tarball', () => {
|
|
|
|
const { getByTitle } = render(<ComponentToBeRendered contextValue={{ ...detailContextValue }} />);
|
|
|
|
expect(getByTitle('Download tarball')).toBeTruthy();
|
2019-10-26 17:02:03 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('when there is a button to open an issue', () => {
|
2019-12-03 15:44:44 +07:00
|
|
|
const { getByTitle } = render(<ComponentToBeRendered contextValue={{ ...detailContextValue }} />);
|
|
|
|
expect(getByTitle('Open an issue')).toBeTruthy();
|
2019-07-29 05:12:14 +07:00
|
|
|
});
|
2019-07-08 00:30:01 +07:00
|
|
|
});
|