import React from 'react'; 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', }, }, }, }; const ComponentToBeRendered: React.FC<{ contextValue: DetailContextProps }> = ({ contextValue }) => ( ); describe(' component', () => { afterEach(() => { cleanup(); }); test('should render the component in default state', () => { const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); test('when there is no action bar data', () => { const packageMeta = { ...detailContextValue.packageMeta, latest: { ...detailContextValue.packageMeta.latest, homepage: undefined, bugs: undefined, dist: { ...detailContextValue.packageMeta.latest.dist, tarball: undefined, }, }, }; const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); test('when there is a button to download a tarball', () => { const { getByTitle } = render(); expect(getByTitle('Download tarball')).toBeTruthy(); }); test('when there is a button to open an issue', () => { const { getByTitle } = render(); expect(getByTitle('Open an issue')).toBeTruthy(); }); });