-
-
Notifications
You must be signed in to change notification settings - Fork 200
test: add unit tests for GeneralCompliantComponent #2018
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
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d1a3071
test: add unit tests for GeneralCompliantComponent
addresskrish ecb8030
fix(#1835): Refactor tests based on reviewer feedback
addresskrish b3d52a0
Merge branch 'main' into fix/issue-1835
kasya 97ea30d
Merge branch 'main' into fix/issue-1835
kasya 01ec661
Merge branch 'main' into fix/issue-1835
kasya 478c393
Fix make check and revert unnecessary changes
kasya a794f1d
Fix issues
kasya d2e9f87
Merge branch 'main' into fix/issue-1835
kasya 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
82 changes: 82 additions & 0 deletions
82
frontend/__tests__/unit/components/GeneralCompliantComponent.test.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,82 @@ | ||
import { IconProp } from '@fortawesome/fontawesome-svg-core' | ||
import { faCertificate } from '@fortawesome/free-solid-svg-icons' | ||
import { render, screen } from '@testing-library/react' | ||
import React from 'react' | ||
|
||
import '@testing-library/jest-dom' | ||
|
||
// Mock the Tooltip component to prevent async state update warnings | ||
jest.mock('@heroui/tooltip', () => ({ | ||
Tooltip: ({ children, content }: { children: React.ReactNode; content: string }) => ( | ||
<div data-testid="tooltip" title={content}> | ||
{children} | ||
</div> | ||
), | ||
})) | ||
|
||
import GeneralCompliantComponent from 'components/GeneralCompliantComponent' | ||
|
||
type GeneralCompliantComponentProps = { | ||
compliant: boolean | ||
icon: IconProp | ||
title: string | ||
} | ||
|
||
describe('GeneralCompliantComponent', () => { | ||
const baseProps: GeneralCompliantComponentProps = { | ||
compliant: true, | ||
icon: faCertificate, | ||
title: 'Test Title', | ||
} | ||
|
||
it('renders successfully with minimal required props', () => { | ||
const { container } = render(<GeneralCompliantComponent {...baseProps} />) | ||
expect(container).toBeInTheDocument() | ||
}) | ||
|
||
it('applies correct color for compliant=true', () => { | ||
const { container } = render(<GeneralCompliantComponent {...baseProps} compliant={true} />) | ||
const svg = container.querySelector('svg') | ||
expect(svg).toBeInTheDocument() | ||
expect(svg).toHaveClass('text-green-400/80') | ||
}) | ||
|
||
it('applies correct color for compliant=false', () => { | ||
const { container } = render(<GeneralCompliantComponent {...baseProps} compliant={false} />) | ||
const svg = container.querySelector('svg') | ||
expect(svg).toBeInTheDocument() | ||
expect(svg).toHaveClass('text-red-400/80') | ||
}) | ||
|
||
it('renders the correct icon structure', () => { | ||
const { container } = render(<GeneralCompliantComponent {...baseProps} />) | ||
const icons = container.querySelectorAll('svg') | ||
expect(icons).toHaveLength(2) | ||
}) | ||
|
||
it('renders tooltip wrapper with title attribute', () => { | ||
render(<GeneralCompliantComponent {...baseProps} title="Tooltip Title" />) | ||
const tooltip = screen.getByTestId('tooltip') | ||
expect(tooltip).toBeInTheDocument() | ||
expect(tooltip).toHaveAttribute('title', 'Tooltip Title') | ||
}) | ||
|
||
it('handles edge case: empty title', () => { | ||
const { container } = render(<GeneralCompliantComponent {...baseProps} title="" />) | ||
expect(container).toBeInTheDocument() | ||
}) | ||
|
||
it('has accessible SVG icons', () => { | ||
const { container } = render(<GeneralCompliantComponent {...baseProps} />) | ||
const icons = container.querySelectorAll('svg[role="img"]') | ||
expect(icons).toHaveLength(2) | ||
expect(icons[0]).toHaveAttribute('aria-hidden', 'true') | ||
expect(icons[1]).toHaveAttribute('aria-hidden', 'true') | ||
}) | ||
|
||
it('renders with custom icon', () => { | ||
const customIcon = faCertificate | ||
const { container } = render(<GeneralCompliantComponent {...baseProps} icon={customIcon} />) | ||
expect(container.querySelector('svg')).toBeInTheDocument() | ||
}) | ||
}) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Edge case: empty title should define behavior (tooltip rendered or not?)
Currently this test only checks that render doesn’t crash. Consider asserting the intended behavior: either no tooltip wrapper is rendered for empty title, or it is rendered with an empty title. Pick one based on the component’s spec and enforce it.
To confirm the intended behavior in code, you can run:
🏁 Script executed:
Length of output: 2228
Enforce tooltip wrapper for empty title
Update the test at
frontend/__tests__/unit/components/GeneralCompliantComponent.test.tsx
to assert that the tooltip wrapper is rendered with an emptytitle
attribute whentitle=""
:📝 Committable suggestion
🤖 Prompt for AI Agents