generated from nl-design-system/example
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jaap-Hein Wester
committed
Nov 7, 2024
1 parent
0742118
commit 14f3050
Showing
3 changed files
with
55 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/components-react/src/form-field-textbox/test/form-field-textbox.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { LuxFormFieldTextbox } from '../FormFieldTextbox'; | ||
|
||
describe('Form Field Textbox', () => { | ||
it('renders a basic form field textbox with label and input', () => { | ||
render(<LuxFormFieldTextbox label="Name" />); | ||
|
||
expect(screen.getByText('Name')).toBeInTheDocument(); | ||
expect(screen.getByRole('textbox')).toBeInTheDocument(); | ||
}); | ||
|
||
it('applies the base class', () => { | ||
render(<LuxFormFieldTextbox label="Name" />); | ||
|
||
const formField = screen.getByText('Name').closest('.utrecht-form-field'); | ||
expect(formField).toHaveClass('utrecht-form-field'); | ||
}); | ||
|
||
it('can have an additional class name', () => { | ||
render(<LuxFormFieldTextbox label="Name" className="custom-class" />); | ||
|
||
const formField = screen.getByText('Name').closest('.utrecht-form-field'); | ||
expect(formField).toHaveClass('utrecht-form-field'); | ||
expect(formField).toHaveClass('custom-class'); | ||
}); | ||
|
||
it('renders description when provided', () => { | ||
render(<LuxFormFieldTextbox label="Name" description="Enter your full name" />); | ||
|
||
expect(screen.getByText('Enter your full name')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders error message when invalid and error message provided', () => { | ||
render(<LuxFormFieldTextbox label="Name" invalid={true} errorMessage="Name is required" />); | ||
|
||
expect(screen.getByText('Name is required')).toBeInTheDocument(); | ||
}); | ||
|
||
it('adds the correct attributes to the Textbox', () => { | ||
render(<LuxFormFieldTextbox label="Name" autoComplete="on" inputDir="rtl" required />); | ||
|
||
const textbox = screen.getByRole('textbox'); | ||
|
||
expect(textbox).toBeInTheDocument(); | ||
expect(textbox).toHaveAttribute('autocomplete', 'on'); | ||
expect(textbox).toHaveAttribute('dir', 'rtl'); | ||
expect(textbox).toHaveAttribute('aria-required', 'true'); | ||
expect(textbox).not.toHaveAttribute('required'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters