Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update ui/TokenWrapper tests to vitest #3229

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ui/CopyClipboard/CopyClipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ const CopyClipboard = React.forwardRef<HTMLButtonElement, CopyClipboardProps>(
>
{showSuccess ? (
<div className="text-ds-primary-green">
<Icon name="check" />
<Icon name="check" label="check" />
</div>
) : (
<div className={cn(copyClipboard({ className, variant }))}>
<Icon name="clipboardCopy" />
<Icon name="clipboardCopy" label="clipboardCopy" />
</div>
)}
</button>
Expand Down
34 changes: 0 additions & 34 deletions src/ui/TokenWrapper/TokenWrapper.spec.jsx

This file was deleted.

13 changes: 0 additions & 13 deletions src/ui/TokenWrapper/TokenWrapper.stories.jsx

This file was deleted.

29 changes: 29 additions & 0 deletions src/ui/TokenWrapper/TokenWrapper.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { type Meta, type StoryObj } from '@storybook/react'

import TokenWrapper from './TokenWrapper'

const meta: Meta<typeof TokenWrapper> = {
title: 'Components/TokenWrapper',
component: TokenWrapper,
argTypes: {
truncate: {
description: 'Truncate the token',
control: 'boolean',
},
token: {
description: 'The token to be displayed',
control: 'text',
},
},
}

export default meta

type Story = StoryObj<typeof TokenWrapper>

export const Default: Story = {
render: (args) => <TokenWrapper {...args} />,
args: {
token: 'randomTokenCopyMe',
},
}
32 changes: 32 additions & 0 deletions src/ui/TokenWrapper/TokenWrapper.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { render, screen } from '@testing-library/react'

import TokenWrapper from './TokenWrapper'

describe('TokenWrapper', () => {
describe('public scope', () => {
it('renders the token', () => {
render(<TokenWrapper token="randomToken" />)

const token = screen.getByText(/randomToken/)
expect(token).toBeInTheDocument()
})

it('renders a copy button', () => {
render(<TokenWrapper token="randomToken" />)

const copyButton = screen.getByTestId('clipboardCopy')
expect(copyButton).toBeInTheDocument()
})
})

describe('public scope with truncated token', () => {
it('renders truncated token', () => {
const token =
'Nostrud tempor irure id consequat cupidatat exercitation ex mollit.'
render(<TokenWrapper token={token} truncate={true} />)

const text = screen.getByText(/Nostrud tempor .../)
expect(text).toBeInTheDocument()
})
})
})
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import cs from 'classnames'
import PropTypes from 'prop-types'

import { cn } from 'shared/utils/cn'
import { CopyClipboard } from 'ui/CopyClipboard'

const TokenWrapper = ({ token, onClick, truncate = false, encodedToken }) => {
interface TokenWrapperProps {
token: string
onClick?: React.ComponentProps<typeof CopyClipboard>['onClick']
truncate?: boolean
encodedToken?: string
}

const TokenWrapper = ({
token,
onClick,
truncate = false,
encodedToken,
}: TokenWrapperProps) => {
return (
<div className="flex flex-row gap-1 overflow-auto">
<pre
className={cs(
'font-mono bg-ds-gray-secondary text-ds-gray-octonary h-auto whitespace-pre-line',
{
'line-clamp-1': truncate,
}
className={cn(
'h-auto whitespace-pre-line bg-ds-gray-secondary font-mono text-ds-gray-octonary',
truncate && 'line-clamp-1'
)}
>
{encodedToken ? encodedToken : token}
Expand Down
File renamed without changes.
Loading