From 14b6e6d07b7e69d48cb9e89520c80fa1a70cb875 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Thu, 5 Jan 2023 09:49:16 -0500 Subject: [PATCH] migrate rest of Account tests --- src/containers/shared/components/Account.tsx | 11 +- .../shared/components/test/Account.test.tsx | 152 +++++++++--------- 2 files changed, 82 insertions(+), 81 deletions(-) diff --git a/src/containers/shared/components/Account.tsx b/src/containers/shared/components/Account.tsx index d3ef1063a..a7e90874c 100644 --- a/src/containers/shared/components/Account.tsx +++ b/src/containers/shared/components/Account.tsx @@ -15,16 +15,21 @@ export const Account = (props: AccountProps) => { return ( <> {link ? ( - + {parts[0]} ) : ( - + {parts[0]} )} {computedTag && ( - + :{computedTag} )} diff --git a/src/containers/shared/components/test/Account.test.tsx b/src/containers/shared/components/test/Account.test.tsx index 73b618e8d..77061b532 100644 --- a/src/containers/shared/components/test/Account.test.tsx +++ b/src/containers/shared/components/test/Account.test.tsx @@ -6,97 +6,93 @@ import { cleanup, render, screen } from '@testing-library/react' import i18n from '../../../../i18nTestConfig' import { Account } from '../Account' -const createWrapper = (component: JSX.Element) => ( - - {component} - -) +const createWrapper = (component: JSX.Element) => + render( + + {component} + , + ) describe('Account', () => { afterEach(cleanup) it('should render with a link', () => { const account = 'rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt' - render(createWrapper()) - const link = screen.getByRole('link') + createWrapper() + const link = screen.getByTestId('account') expect(link).toHaveClass('account') expect(link).toHaveTextContent(account) expect(link).toHaveAttribute('href', `/accounts/${account}`) expect(link).toHaveAttribute('title', account) expect(screen.queryByTestId('dt')).toBeNull() - screen.debug() }) - // it('should render without a link', () => { - // const wrapper = createWrapper( - // , - // ) - // const address = wrapper.find('.account').hostNodes() - // expect(address).toHaveText('rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') - // expect(address).not.toHaveTagName('a') - // expect(address).toHaveProp('title', 'rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') - // expect(wrapper.find('.dt')).not.toExist() - // wrapper.unmount() - // }) + it('should render without a link', () => { + createWrapper( + , + ) + const link = screen.getByTestId('account') + expect(link).toHaveTextContent('rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') + expect(link).not.toHaveAttribute('href') + expect(link).toHaveAttribute('title', 'rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') + expect(screen.queryByTestId('dt')).toBeNull() + }) - // it('should render with a destination tag', () => { - // const wrapper = createWrapper( - // , - // ) - // const anchor = wrapper.find('a') - // expect(anchor).toHaveClassName('account') - // expect(anchor).toHaveText('rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') - // expect(anchor).toHaveProp( - // 'href', - // '/accounts/rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt', - // ) - // expect(anchor).toHaveProp('title', 'rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') - // expect(wrapper.find('.dt')).toHaveText(':381702') - // wrapper.unmount() - // }) + it('should render with a destination tag', () => { + createWrapper( + , + ) + const link = screen.getByTestId('account') + expect(link).toHaveClass('account') + expect(link).toHaveTextContent('rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') + expect(link).toHaveAttribute( + 'href', + '/accounts/rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt', + ) + expect(link).toHaveAttribute('title', 'rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') + expect(screen.queryByTestId('dt')).toHaveTextContent(':381702') + }) - // it('should render with a destination tag and no link', () => { - // const wrapper = createWrapper( - // , - // ) - // const address = wrapper.find('.account') - // expect(address).toHaveText('rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') - // expect(address).not.toHaveTagName('a') - // expect(address).toHaveProp('title', 'rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') - // expect(wrapper.find('.dt')).toHaveText(':381702') - // wrapper.unmount() - // }) + it('should render with a destination tag and no link', () => { + createWrapper( + , + ) + const link = screen.getByTestId('account') + expect(link).toHaveClass('account') + expect(link).toHaveTextContent('rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') + expect(link).not.toHaveAttribute('href') + expect(link).toHaveAttribute('title', 'rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') + expect(screen.queryByTestId('dt')).toHaveTextContent(':381702') + }) - // it('should render with a destination tag supplied separately', () => { - // const wrapper = createWrapper( - // , - // ) - // const anchor = wrapper.find('a') - // expect(anchor).toHaveClassName('account') - // expect(anchor).toHaveText('rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') - // expect(anchor).toHaveProp( - // 'href', - // '/accounts/rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt', - // ) - // expect(anchor).toHaveProp('title', 'rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') - // expect(wrapper.find('.dt')).toHaveText(':123') - // wrapper.unmount() - // }) + it('should render with a destination tag supplied separately', () => { + createWrapper( + , + ) + const link = screen.getByTestId('account') + expect(link).toHaveClass('account') + expect(link).toHaveTextContent('rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') + expect(link).toHaveAttribute( + 'href', + '/accounts/rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt', + ) + expect(link).toHaveAttribute('title', 'rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') + expect(screen.queryByTestId('dt')).toHaveTextContent(':123') + }) - // it('should render with a destination tag supplied separately and no link', () => { - // const wrapper = createWrapper( - // , - // ) - // const address = wrapper.find('.account') - // expect(address).toHaveText('rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') - // expect(address).not.toHaveTagName('a') - // expect(address).toHaveProp('title', 'rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') - // expect(wrapper.find('.dt')).toHaveText(':123') - // wrapper.unmount() - // }) + it('should render with a destination tag supplied separately and no link', () => { + createWrapper( + , + ) + const link = screen.getByTestId('account') + expect(link).toHaveTextContent('rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') + expect(link).not.toHaveAttribute('href') + expect(link).toHaveAttribute('title', 'rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt') + expect(screen.queryByTestId('dt')).toHaveTextContent(':123') + }) })