Skip to content

Commit

Permalink
fix(hint): ♾️ recursive fn and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenSibon committed Sep 10, 2024
1 parent 6ece317 commit e3ba6f0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/react/src/FieldSet/FieldSet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('FieldSet', () => {
expect(legend).toHaveTextContent('Legend (not required)')
})

it('renders the provided hint text after the legend when `optional` is set to `false`', () => {
it('renders the provided hint text after the legend while `optional` is set to `false`', () => {
const { container } = render(<FieldSet legend="Legend" optional={false} hint="required" />)

const legend = container.querySelector('legend')
Expand Down
24 changes: 12 additions & 12 deletions packages/react/src/Hint/Hint.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import '@testing-library/jest-dom'

describe('Hint', () => {
it('renders', () => {
const { container } = render(<Hint />)
const { container } = render(<Hint hint="hint" />)

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

Expand All @@ -14,15 +14,15 @@ describe('Hint', () => {
})

it('renders a design system BEM class name', () => {
const { container } = render(<Hint />)
const { container } = render(<Hint optional />)

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

expect(component).toHaveClass('ams-hint')
})

it('renders an additional class name', () => {
const { container } = render(<Hint className="extra" />)
const { container } = render(<Hint optional className="extra" />)

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

Expand All @@ -42,32 +42,32 @@ describe('Hint', () => {
it('renders the provided hint text', () => {
const { container } = render(<Hint hint="hint text" />)

const hint = container.querySelector('span.ams-hint')
const component = container.querySelector(':only-child')

expect(hint).toHaveTextContent('(hint text)')
expect(component).toHaveTextContent('(hint text)')
})

it('renders the default hint text', () => {
const { container } = render(<Hint optional={true} />)

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

expect(label).toHaveTextContent('Label (niet verplicht)')
expect(component).toHaveTextContent('(niet verplicht)')
})

it('renders the provided hint text when `optional` is set to `false`', () => {
const { container } = render(<Hint optional={true} hint="not required" />)

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

expect(label).toHaveTextContent('Label (not required)')
expect(component).toHaveTextContent('(not required)')
})

it('renders the provided hint text "required" marked as not optional', () => {
it('renders the provided hint text "required" while also being marked as not optional', () => {
const { container } = render(<Hint optional={false} hint="required" />)

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

expect(label).toHaveTextContent('Label (required)')
expect(component).toHaveTextContent('(required)')
})
})
4 changes: 2 additions & 2 deletions packages/react/src/Hint/Hint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export type HintProps = PropsWithChildren<HTMLAttributes<HTMLElement>> & {

const getHintText = ({ hint, optional }: HintProps) => {
if (hint) {
return <Hint hint={hint} />
return hint
} else if (optional) {
return <Hint hint="niet verplicht" />
return 'niet verplicht'
}

return null
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/Label/Label.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('Label', () => {
expect(label).toHaveTextContent('Label (not required)')
})

it('renders the provided hint text "required" after the label marked as not optional', () => {
it('renders the provided hint text after the label while `optional` is set to `false`', () => {
const { container } = render(
<Label htmlFor="form-control" optional={false} hint="required">
Label
Expand Down

0 comments on commit e3ba6f0

Please sign in to comment.