generated from nl-design-system/example
-
Notifications
You must be signed in to change notification settings - Fork 1
test(components-react): add visual baseline to all formfield components #347
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
Merged
MrSkippy
merged 13 commits into
main
from
344-chore-add-visual-regression-tests-to-all-formfield-components
Jan 3, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0cd7ec5
Tests added, fixes on component
4d22752
First set of Vis reg tests
83aa6a8
Second set of Vis reg tests (WIP)
cf23e7f
Third set of Vis reg tests (WIP)
46447ea
Forth set of Vis reg tests
315d938
RadioOptionValue
ea46d13
forwardRef bug fixed
58141ec
Merge branch 'main' into 302-form-field-single-checkbox-continued
23abd1f
Merge branch '302-form-field-single-checkbox-continued' into 344-chor…
6f09628
refactor(components-react): move visreg scenarios to VisualStates com…
remypar5 62177de
chore: remove tryout files from index
remypar5 0289e0e
refactor(components-react): fix imports
remypar5 834c639
fix: build
remypar5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
50 changes: 50 additions & 0 deletions
50
packages/components-react/src/form-field-checkbox/test/form-field-checkbox.spec.tsx
This file contains hidden or 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,50 @@ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { LuxFormFieldCheckbox } from '../FormFieldCheckbox'; | ||
|
||
describe('Form Field Checkbox', () => { | ||
it('renders a basic form field checkbox with label and input', () => { | ||
render(<LuxFormFieldCheckbox label="Name" />); | ||
|
||
expect(screen.getByText('Name')).toBeInTheDocument(); | ||
expect(screen.getByRole('checkbox')).toBeInTheDocument(); | ||
}); | ||
|
||
it('applies the base class', () => { | ||
render(<LuxFormFieldCheckbox 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(<LuxFormFieldCheckbox 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(<LuxFormFieldCheckbox 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(<LuxFormFieldCheckbox label="Name" invalid={true} errorMessage="Name is required" />); | ||
|
||
expect(screen.getByText('Name is required')).toBeInTheDocument(); | ||
}); | ||
|
||
it('adds the correct attributes to the Checkbox', () => { | ||
render(<LuxFormFieldCheckbox label="Name" checked required />); | ||
|
||
const checkbox = screen.getByRole('checkbox'); | ||
|
||
expect(checkbox).toBeInTheDocument(); | ||
expect(checkbox).toBeChecked(); | ||
expect(checkbox).toHaveAttribute('aria-required', 'true'); | ||
expect(checkbox).not.toHaveAttribute('required'); | ||
}); | ||
}); |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,17 @@ | ||
/** | ||
* Pick only certain keys form object. | ||
* | ||
* @export | ||
* @template {object} T | ||
* @template {keyof T} U | ||
* @param {T} obj Object to pick from | ||
* @param {Array<U>} keys Keys to pick | ||
* @returns {Pick<T, U>} Object containing only picked keys | ||
*/ | ||
export function pick<T extends object, U extends keyof T>(obj: T, keys: Array<U>): Pick<T, U> { | ||
const ret = {} as Pick<T, U>; | ||
for (const k of keys) { | ||
ret[k] = obj[k]; | ||
} | ||
return ret; | ||
} |
This file contains hidden or 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
23 changes: 23 additions & 0 deletions
23
packages/storybook/src/react-components/form-field-checkbox/visual/States.tsx
This file contains hidden or 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,23 @@ | ||
import { LuxFormFieldCheckbox } from '@lux-design-system/components-react'; | ||
|
||
export const VisualStates = () => ( | ||
<> | ||
<LuxFormFieldCheckbox label="Label" /> | ||
<LuxFormFieldCheckbox label="Label" checked /> | ||
<LuxFormFieldCheckbox label="Label" description="Description" /> | ||
<h5 className="utrecht-heading-4">Hover & Focus</h5> | ||
<div className="pseudo-hover-all"> | ||
<LuxFormFieldCheckbox label="Label" /> | ||
</div> | ||
<div className="pseudo-focus-all pseudo-focus-visible-all"> | ||
<LuxFormFieldCheckbox label="Label" /> | ||
</div> | ||
<h5 className="utrecht-heading-4">Invalid</h5> | ||
<LuxFormFieldCheckbox label="Label" errorMessage="Error Message" invalid /> | ||
<LuxFormFieldCheckbox label="Label" description="Description" errorMessage="Error Message" invalid /> | ||
<h5 className="utrecht-heading-4">Disabled</h5> | ||
<LuxFormFieldCheckbox label="Label" disabled /> | ||
<LuxFormFieldCheckbox label="Label" disabled checked /> | ||
<LuxFormFieldCheckbox label="Label" description="Description" disabled /> | ||
</> | ||
); |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.