Skip to content

Commit

Permalink
migrate rest of Account tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari committed Jan 10, 2023
1 parent 7647b0e commit 14b6e6d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 81 deletions.
11 changes: 8 additions & 3 deletions src/containers/shared/components/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@ export const Account = (props: AccountProps) => {
return (
<>
{link ? (
<Link className="account" title={parts[0]} to={`/accounts/${parts[0]}`}>
<Link
data-testid="account"
className="account"
title={parts[0]}
to={`/accounts/${parts[0]}`}
>
{parts[0]}
</Link>
) : (
<span className="account" title={parts[0]}>
<span data-testid="account" className="account" title={parts[0]}>
{parts[0]}
</span>
)}
{computedTag && (
<span className="dt" data-testid="dt'">
<span className="dt" data-testid="dt">
:{computedTag}
</span>
)}
Expand Down
152 changes: 74 additions & 78 deletions src/containers/shared/components/test/Account.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
<I18nextProvider i18n={i18n}>
<BrowserRouter>{component}</BrowserRouter>
</I18nextProvider>
)
const createWrapper = (component: JSX.Element) =>
render(
<I18nextProvider i18n={i18n}>
<BrowserRouter>{component}</BrowserRouter>
</I18nextProvider>,
)

describe('Account', () => {
afterEach(cleanup)
it('should render with a link', () => {
const account = 'rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt'
render(createWrapper(<Account account={account} />))
const link = screen.getByRole('link')
createWrapper(<Account account={account} />)
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(
// <Account account="rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt" link={false} />,
// )
// 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(
<Account account="rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt" link={false} />,
)
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(
// <Account account="rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt:381702" />,
// )
// 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(
<Account account="rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt:381702" />,
)
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(
// <Account
// account="rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt:381702"
// link={false}
// />,
// )
// 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(
<Account
account="rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt:381702"
link={false}
/>,
)
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(
// <Account account="rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt" tag={123} />,
// )
// 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(
<Account account="rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt" tag={123} />,
)
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(
// <Account
// account="rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt"
// tag={123}
// link={false}
// />,
// )
// 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(
<Account
account="rHWcuuZoFvDS6gNbmHSdpb7u1hZzxvCoMt"
tag={123}
link={false}
/>,
)
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')
})
})

0 comments on commit 14b6e6d

Please sign in to comment.