Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dlnr committed Oct 9, 2024
1 parent 6bfb91c commit 479bd06
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
43 changes: 33 additions & 10 deletions packages/react/src/Button/Button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ShareIcon } from '@amsterdam/design-system-react-icons'
import { render, screen } from '@testing-library/react'
import '@testing-library/jest-dom'
import { createRef } from 'react'
import { Button } from './Button'

describe('Button', () => {
it('renders an element with role button', () => {
render(<Button label="Click me!" />)
render(<Button>Click me!</Button>)

const button = screen.getByRole('button', {
name: 'Click me!',
Expand All @@ -16,7 +17,7 @@ describe('Button', () => {
})

it('renders an additional class name', () => {
render(<Button label="Click me!" className="extra" />)
render(<Button className="extra">Click me!</Button>)

const button = screen.getByRole('button', {
name: 'Click me!',
Expand All @@ -26,7 +27,7 @@ describe('Button', () => {
})

it('renders a default button with variant primary', () => {
render(<Button label="primary" />)
render(<Button>primary</Button>)

const button = screen.getByRole('button', {
name: 'primary',
Expand All @@ -40,9 +41,9 @@ describe('Button', () => {
it('renders a button with a specified variant', () => {
render(
<>
<Button variant="primary" label="primary" />
<Button variant="secondary" label="secondary" />
<Button variant="tertiary" label="tertiary" />
<Button variant="primary">primary</Button>
<Button variant="secondary">secondary</Button>
<Button variant="tertiary">tertiary</Button>
</>,
)

Expand All @@ -69,9 +70,15 @@ describe('Button', () => {
it('renders a disabled button with a specified variant', () => {
render(
<>
<Button disabled variant="primary" label="primary" />
<Button disabled variant="secondary" label="secondary" />
<Button disabled variant="tertiary" label="tertiary" />
<Button disabled variant="primary">
primary
</Button>
<Button disabled variant="secondary">
secondary
</Button>
<Button disabled variant="tertiary">
tertiary
</Button>
</>,
)

Expand All @@ -98,10 +105,26 @@ describe('Button', () => {
it('is able to pass a React ref', () => {
const ref = createRef<HTMLButtonElement>()

const { container } = render(<Button label="Click me!" ref={ref} />)
const { container } = render(<Button ref={ref}>Click me!</Button>)

const button = container.querySelector(':only-child')

expect(ref.current).toBe(button)
})

it('renders a button with an icon', () => {
render(
<Button icon={ShareIcon} iconPosition="end">
Share
</Button>,
)

const button = screen.getByRole('button', {
name: 'Share',
})

expect(button).toBeInTheDocument()
const icon = button.querySelector('.ams-icon')
expect(icon).toBeInTheDocument()
})
})
3 changes: 3 additions & 0 deletions storybook/src/components/Button/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const meta = {
disabled: false,
},
argTypes: {
icon: {
table: { disable: true },
},
disabled: {
description: 'Prevents interaction. Avoid if possible.',
},
Expand Down

0 comments on commit 479bd06

Please sign in to comment.