Skip to content

Conversation

@MohdWaqar98
Copy link
Contributor

PR Description
Added comprehensive test cases for BarChart component

Tests cover rendering, data handling, and prop validation

Follows project testing standards

Proposed change

Resolves #1801

This PR introduces unit tests for the BarChart component to ensure correctness across a range of scenarios. The tests validate prop-based behavior, rendering logic, edge case handling, and follow the structure defined in existing tests like AutoScrollToTop.test.tsx.

Checklist
I've read and followed the contributing guidelines.

I've run make check-test locally; all checks and tests passed.

- Added comprehensive test cases for BarChart component
- Tests cover rendering, data handling, and prop validation
- Follows project testing standards
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 29, 2025

Warning

Rate limit exceeded

@kasya has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 18 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between a5dfaa7 and f78d576.

📒 Files selected for processing (1)
  • frontend/__tests__/unit/components/BarChart.test.tsx (1 hunks)

Summary by CodeRabbit

  • Tests
    • Introduced a comprehensive unit test suite for the BarChart component, covering rendering, theming (light/dark modes), icon support, color logic, data label formatting, edge cases, dynamic theme updates, and integration with child components.

Walkthrough

A new unit test suite for the <BarChart> React component has been added. The tests cover rendering with various props, theming (light and dark modes), icon support, empty data handling, and color reversal logic. Mocking and setup are provided for external dependencies and consistent theming during tests.

Changes

Cohort / File(s) Change Summary
BarChart Component Unit Tests
frontend/__tests__/unit/components/BarChart.test.tsx
Adds a comprehensive test suite for the <BarChart> component, covering rendering, theming, icon support, edge cases, and prop-based behaviors. Mocks external dependencies and sets up theme context for tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Renders successfully with minimal required props (#1801)
Conditional rendering logic; Prop-based behavior; Text/content rendering (#1801)
Handles edge cases and invalid inputs (#1801)
Theming, icon support, color reversal, empty data handling (#1801)
Event handling, accessibility, DOM/classNames/styles (#1801) Event handling and accessibility roles/labels are not covered in the test cases.

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Suggested reviewers

  • arkid15r
  • kasya
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aeea306 and 5fb29a1.

📒 Files selected for processing (1)
  • frontend/__tests__/unit/components/BarChart.test.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ahmedxgouda
PR: OWASP/Nest#1703
File: frontend/src/components/BarChart.tsx:33-46
Timestamp: 2025-07-03T03:08:03.290Z
Learning: In the OWASP Nest project's BarChart component (frontend/src/components/BarChart.tsx), the days and requirements arrays are guaranteed to always have the same length in their use cases, so input validation for array length matching is not needed.
Learnt from: Rajgupta36
PR: OWASP/Nest#1717
File: frontend/__tests__/unit/pages/createProgram.test.tsx:70-86
Timestamp: 2025-07-12T17:36:57.255Z
Learning: When testing React page components that use mocked form components, validation logic should be tested at the form component level, not the page level. Page-level tests should focus on authentication, role checking, submission handling, and navigation logic.
Learnt from: ahmedxgouda
PR: OWASP/Nest#1633
File: frontend/src/components/GradientRadialChart.tsx:67-116
Timestamp: 2025-06-21T12:21:32.372Z
Learning: The react-apexcharts Chart component does not support ARIA attributes like aria-label and role as direct props. To add accessibility attributes to ApexCharts in React, wrap the Chart component in a container div with the appropriate ARIA attributes.
frontend/__tests__/unit/components/BarChart.test.tsx (3)

Learnt from: ahmedxgouda
PR: #1703
File: frontend/src/components/BarChart.tsx:33-46
Timestamp: 2025-07-03T03:08:03.290Z
Learning: In the OWASP Nest project's BarChart component (frontend/src/components/BarChart.tsx), the days and requirements arrays are guaranteed to always have the same length in their use cases, so input validation for array length matching is not needed.

Learnt from: ahmedxgouda
PR: #1633
File: frontend/src/components/GradientRadialChart.tsx:67-116
Timestamp: 2025-06-21T12:21:32.372Z
Learning: The react-apexcharts Chart component does not support ARIA attributes like aria-label and role as direct props. To add accessibility attributes to ApexCharts in React, wrap the Chart component in a container div with the appropriate ARIA attributes.

Learnt from: Rajgupta36
PR: #1717
File: frontend/tests/unit/pages/createProgram.test.tsx:70-86
Timestamp: 2025-07-12T17:36:57.255Z
Learning: When testing React page components that use mocked form components, validation logic should be tested at the form component level, not the page level. Page-level tests should focus on authentication, role checking, submission handling, and navigation logic.

🔇 Additional comments (4)
frontend/__tests__/unit/components/BarChart.test.tsx (4)

1-8: LGTM! Comprehensive test setup.

The imports cover all necessary testing utilities including React Testing Library, Jest DOM matchers, theming support, and FontAwesome icons. This provides a solid foundation for comprehensive component testing.


9-10: LGTM! Proper FontAwesome setup.

Adding the faFire icon to the FontAwesome library is necessary for testing icon functionality and aligns with the test case that uses the fire icon.


12-19: Good mocking strategy with a minor concern about error suppression.

The ApexCharts mock is well-implemented for unit testing, avoiding dynamic import complexity while providing a testable element. The targeted console error suppression for act(...) warnings is reasonable, but be cautious that this doesn't mask legitimate testing issues.


33-38: LGTM! Well-structured test data.

The mock props provide realistic test data with properly matched array lengths. This aligns with the component's expected usage patterns and supports comprehensive testing scenarios.

@kasya
Copy link
Collaborator

kasya commented Jul 30, 2025

@MohdWaqar98 Thanks for working on this.

There are issues with your code that you need to address.

  1. Run make check locally and address all issues that it shows (imports order, console in the code). Push changed files when it's all green and no error showing:
Screenshot 2025-07-29 at 5 36 29 PM
  1. Update test cases to not have any expect in if statements - this is why we have unit tests. One check for each tests, no if/else.
  2. Remove emojis from the tests and comments 👀 This is not acceptable for code.
  3. Do not create a new PR for these changes - push everything to this same PR.

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking as request changes

Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed linting issues for you, but the test coverage is very low for this file.
Screenshot 2025-07-30 at 8 53 00 PM
47.36% coverage for statements, 0% for branches and 66.66% for functions.
Could you at least get it to cover those lines mentioned on the right side?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
frontend/__tests__/unit/components/BarChart.test.tsx (1)

28-39: Simplify the helper function implementation.

The renderWithTheme helper unnecessarily wraps the synchronous render call in Promise.resolve and act. The function should be simplified to be synchronous and return the render result directly.

Apply this refactor:

-const renderWithTheme = async (ui: React.ReactElement, theme: 'light' | 'dark' = 'light') => {
-  let result: ReturnType<typeof render> | undefined
-  await act(async () => {
-    result = render(
-      <ThemeProvider attribute="class" forcedTheme={theme}>
-        {ui}
-      </ThemeProvider>
-    )
-  })
-  return result!
-}
+const renderWithTheme = (ui: React.ReactElement, theme: 'light' | 'dark' = 'light') => {
+  return render(
+    <ThemeProvider attribute="class" forcedTheme={theme}>
+      {ui}
+    </ThemeProvider>
+  )
+}

Then remove await from all test calls to renderWithTheme.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 52f99ca and a935130.

📒 Files selected for processing (1)
  • frontend/__tests__/unit/components/BarChart.test.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: ahmedxgouda
PR: OWASP/Nest#1703
File: frontend/src/components/BarChart.tsx:33-46
Timestamp: 2025-07-03T03:08:03.290Z
Learning: In the OWASP Nest project's BarChart component (frontend/src/components/BarChart.tsx), the days and requirements arrays are guaranteed to always have the same length in their use cases, so input validation for array length matching is not needed.
Learnt from: Rajgupta36
PR: OWASP/Nest#1717
File: frontend/__tests__/unit/pages/createProgram.test.tsx:70-86
Timestamp: 2025-07-12T17:36:57.255Z
Learning: When testing React page components that use mocked form components, validation logic should be tested at the form component level, not the page level. Page-level tests should focus on authentication, role checking, submission handling, and navigation logic.
Learnt from: ahmedxgouda
PR: OWASP/Nest#1633
File: frontend/src/components/GradientRadialChart.tsx:67-116
Timestamp: 2025-06-21T12:21:32.372Z
Learning: The react-apexcharts Chart component does not support ARIA attributes like aria-label and role as direct props. To add accessibility attributes to ApexCharts in React, wrap the Chart component in a container div with the appropriate ARIA attributes.
📚 Learning: in the owasp nest project's barchart component (frontend/src/components/barchart.tsx), the days and ...
Learnt from: ahmedxgouda
PR: OWASP/Nest#1703
File: frontend/src/components/BarChart.tsx:33-46
Timestamp: 2025-07-03T03:08:03.290Z
Learning: In the OWASP Nest project's BarChart component (frontend/src/components/BarChart.tsx), the days and requirements arrays are guaranteed to always have the same length in their use cases, so input validation for array length matching is not needed.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: the react-apexcharts chart component does not support aria attributes like aria-label and role as di...
Learnt from: ahmedxgouda
PR: OWASP/Nest#1633
File: frontend/src/components/GradientRadialChart.tsx:67-116
Timestamp: 2025-06-21T12:21:32.372Z
Learning: The react-apexcharts Chart component does not support ARIA attributes like aria-label and role as direct props. To add accessibility attributes to ApexCharts in React, wrap the Chart component in a container div with the appropriate ARIA attributes.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: when testing react page components that use mocked form components, validation logic should be teste...
Learnt from: Rajgupta36
PR: OWASP/Nest#1717
File: frontend/__tests__/unit/pages/createProgram.test.tsx:70-86
Timestamp: 2025-07-12T17:36:57.255Z
Learning: When testing React page components that use mocked form components, validation logic should be tested at the form component level, not the page level. Page-level tests should focus on authentication, role checking, submission handling, and navigation logic.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: in the detailscard component (frontend/src/components/carddetailspage.tsx), there's a length check b...
Learnt from: ahmedxgouda
PR: OWASP/Nest#1633
File: frontend/src/components/HealthMetrics.tsx:30-30
Timestamp: 2025-06-20T16:12:59.256Z
Learning: In the DetailsCard component (frontend/src/components/CardDetailsPage.tsx), there's a length check before rendering HealthMetrics: `healthMetricsData.length > 0`. This ensures that when HealthMetrics is rendered, the data array has at least one element, making accessing data[0] safe within the HealthMetrics component.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: the owasp nest application has logging disabled, so avoid suggesting console.log, console.error, or ...
Learnt from: Rajgupta36
PR: OWASP/Nest#1634
File: frontend/src/app/api/auth/[...nextauth]/route.ts:30-55
Timestamp: 2025-06-18T20:00:23.899Z
Learning: The OWASP Nest application has logging disabled, so avoid suggesting console.log, console.error, or any other logging statements in code review suggestions.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
🔇 Additional comments (3)
frontend/__tests__/unit/components/BarChart.test.tsx (3)

1-11: LGTM! Clean import structure and icon setup.

The imports follow standard testing patterns and the FontAwesome library setup is correctly configured for testing icon functionality.


13-26: Well-structured ApexCharts mock.

The mock effectively captures chart options and series data through data attributes while avoiding the complexity of the actual charting library. This approach is ideal for unit testing component behavior.


41-47: Well-defined test props.

The mock props provide realistic test data with properly matched array lengths, which aligns with the BarChart component's expected usage patterns.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
frontend/__tests__/unit/components/BarChart.test.tsx (1)

28-39: Fix the unnecessary async/await pattern in the helper function.

The renderWithTheme helper function unnecessarily wraps the synchronous render call in an async pattern. The render function from React Testing Library is synchronous and doesn't need to be wrapped in act() or Promise.resolve().

-const renderWithTheme = async (ui: React.ReactElement, theme: 'light' | 'dark' = 'light') => {
-  let result: ReturnType<typeof render> | undefined
-  await act(async () => {
-    result = render(
-      <ThemeProvider attribute="class" forcedTheme={theme}>
-        {ui}
-      </ThemeProvider>
-    )
-  })
-  return result!
-}
+const renderWithTheme = (ui: React.ReactElement, theme: 'light' | 'dark' = 'light') => {
+  return render(
+    <ThemeProvider attribute="class" forcedTheme={theme}>
+      {ui}
+    </ThemeProvider>
+  )
+}

Then update all test calls to remove await:

-await renderWithTheme(<BarChart {...mockProps} />)
+renderWithTheme(<BarChart {...mockProps} />)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a935130 and 8346cf4.

📒 Files selected for processing (1)
  • frontend/__tests__/unit/components/BarChart.test.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (9)
📓 Common learnings
Learnt from: ahmedxgouda
PR: OWASP/Nest#1703
File: frontend/src/components/BarChart.tsx:33-46
Timestamp: 2025-07-03T03:08:03.290Z
Learning: In the OWASP Nest project's BarChart component (frontend/src/components/BarChart.tsx), the days and requirements arrays are guaranteed to always have the same length in their use cases, so input validation for array length matching is not needed.
Learnt from: Rajgupta36
PR: OWASP/Nest#1717
File: frontend/__tests__/unit/pages/createProgram.test.tsx:70-86
Timestamp: 2025-07-12T17:36:57.255Z
Learning: When testing React page components that use mocked form components, validation logic should be tested at the form component level, not the page level. Page-level tests should focus on authentication, role checking, submission handling, and navigation logic.
Learnt from: ahmedxgouda
PR: OWASP/Nest#1633
File: frontend/src/components/GradientRadialChart.tsx:67-116
Timestamp: 2025-06-21T12:21:32.372Z
Learning: The react-apexcharts Chart component does not support ARIA attributes like aria-label and role as direct props. To add accessibility attributes to ApexCharts in React, wrap the Chart component in a container div with the appropriate ARIA attributes.
📚 Learning: in the owasp nest project's barchart component (frontend/src/components/barchart.tsx), the days and ...
Learnt from: ahmedxgouda
PR: OWASP/Nest#1703
File: frontend/src/components/BarChart.tsx:33-46
Timestamp: 2025-07-03T03:08:03.290Z
Learning: In the OWASP Nest project's BarChart component (frontend/src/components/BarChart.tsx), the days and requirements arrays are guaranteed to always have the same length in their use cases, so input validation for array length matching is not needed.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: the react-apexcharts chart component does not support aria attributes like aria-label and role as di...
Learnt from: ahmedxgouda
PR: OWASP/Nest#1633
File: frontend/src/components/GradientRadialChart.tsx:67-116
Timestamp: 2025-06-21T12:21:32.372Z
Learning: The react-apexcharts Chart component does not support ARIA attributes like aria-label and role as direct props. To add accessibility attributes to ApexCharts in React, wrap the Chart component in a container div with the appropriate ARIA attributes.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: when testing react page components that use mocked form components, validation logic should be teste...
Learnt from: Rajgupta36
PR: OWASP/Nest#1717
File: frontend/__tests__/unit/pages/createProgram.test.tsx:70-86
Timestamp: 2025-07-12T17:36:57.255Z
Learning: When testing React page components that use mocked form components, validation logic should be tested at the form component level, not the page level. Page-level tests should focus on authentication, role checking, submission handling, and navigation logic.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: in the detailscard component (frontend/src/components/carddetailspage.tsx), there's a length check b...
Learnt from: ahmedxgouda
PR: OWASP/Nest#1633
File: frontend/src/components/HealthMetrics.tsx:30-30
Timestamp: 2025-06-20T16:12:59.256Z
Learning: In the DetailsCard component (frontend/src/components/CardDetailsPage.tsx), there's a length check before rendering HealthMetrics: `healthMetricsData.length > 0`. This ensures that when HealthMetrics is rendered, the data array has at least one element, making accessing data[0] safe within the HealthMetrics component.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: the owasp nest application has logging disabled, so avoid suggesting console.log, console.error, or ...
Learnt from: Rajgupta36
PR: OWASP/Nest#1634
File: frontend/src/app/api/auth/[...nextauth]/route.ts:30-55
Timestamp: 2025-06-18T20:00:23.899Z
Learning: The OWASP Nest application has logging disabled, so avoid suggesting console.log, console.error, or any other logging statements in code review suggestions.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: when implementing dropdown menus or similar interactive components, always include proper accessibil...
Learnt from: codic-yeeshu
PR: OWASP/Nest#1444
File: frontend/src/components/NavDropDown.tsx:0-0
Timestamp: 2025-04-30T13:41:20.846Z
Learning: When implementing dropdown menus or similar interactive components, always include proper accessibility features: ARIA attributes (aria-expanded, aria-haspopup, aria-controls), keyboard navigation support (Enter, Space, Escape keys), and mechanisms to close dropdowns when clicking outside.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: use react's useid() hook rather than manually generating random strings when creating accessibility ...
Learnt from: codic-yeeshu
PR: OWASP/Nest#1444
File: frontend/src/components/NavDropDown.tsx:0-0
Timestamp: 2025-04-30T13:41:20.846Z
Learning: Use React's useId() hook rather than manually generating random strings when creating accessibility identifiers for UI components. This creates stable, unique IDs without causing hydration mismatches.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: in the detailscard component (frontend/src/components/carddetailspage.tsx), there's a safety check t...
Learnt from: ahmedxgouda
PR: OWASP/Nest#1633
File: frontend/src/components/HealthMetrics.tsx:30-30
Timestamp: 2025-06-20T16:12:59.256Z
Learning: In the DetailsCard component (frontend/src/components/CardDetailsPage.tsx), there's a safety check that ensures HealthMetrics component is only rendered when healthMetricsData exists and has at least one element: `healthMetricsData && healthMetricsData.length > 0`. This makes accessing data[0] safe within the HealthMetrics component.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
🪛 Biome (2.1.2)
frontend/__tests__/unit/components/BarChart.test.tsx

[error] 210-210: Expected a semicolon or an implicit semicolon after a statement, but found none

An explicit or implicit semicolon is expected here...

...Which is required to end this statement

(parse)

🔇 Additional comments (6)
frontend/__tests__/unit/components/BarChart.test.tsx (6)

50-54: Remove unnecessary await from synchronous render call.

Once the renderWithTheme helper is made synchronous, remove the await keyword from this test.

-  it('renders without crashing with minimal props', async () => {
-    await renderWithTheme(<BarChart {...mockProps} />)
+  it('renders without crashing with minimal props', () => {
+    renderWithTheme(<BarChart {...mockProps} />)
     expect(screen.getByText('Calories Burned')).toBeInTheDocument()
     expect(screen.getByTestId('mock-chart')).toBeInTheDocument()
   })

56-68: Remove unnecessary await and improve icon validation.

The test logic for custom icons needs the same async fix. Also, the assertion could be more specific about icon behavior.

-  it('renders with custom icon when provided', async () => {
+  it('renders with custom icon when provided', () => {
     // cspell:ignore fas
-    await renderWithTheme(<BarChart {...mockProps} icon={['fas', 'fire']} />)
+    renderWithTheme(<BarChart {...mockProps} icon={['fas', 'fire']} />)
     expect(screen.getByText('Calories Burned')).toBeInTheDocument()
     
     // Check for custom FontAwesome fire icon
     const fireIconElement = document.querySelector('svg[data-icon="fire"]')
     expect(fireIconElement).toBeInTheDocument()
     
     // Verify the specific icon behavior based on component implementation
     const allIcons = document.querySelectorAll('svg[data-icon]')
     expect(allIcons.length).toBeGreaterThanOrEqual(1)
   })

70-81: Apply async/await fixes to all remaining test cases.

All these test cases need the same fix - remove async from the function declaration and await from the renderWithTheme calls.

Apply this pattern to all remaining tests:

-  it('test description', async () => {
-    await renderWithTheme(...)
+  it('test description', () => {
+    renderWithTheme(...)

Also applies to: 83-93, 95-105, 107-117, 119-126, 128-131, 133-142, 144-151, 153-161, 163-172, 174-183, 185-194, 196-200


1-11: LGTM on imports and FontAwesome setup.

The imports are properly organized and the FontAwesome icon registration follows the correct pattern for testing icon components.


13-26: LGTM on ApexCharts mocking strategy.

The mock implementation correctly avoids dynamic import issues by providing a simple div with test attributes. The data serialization approach will help validate that correct props are passed to the chart component.


41-47: Well-structured test data.

The mock props provide good baseline data for testing various scenarios. The data aligns with the component's expected prop structure.

Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MohdWaqar98 I fixed issues with make check again and pushed those changes to this PR. Also some tests were failing- please check that tests work before committing your changes.
Also, you need to run make check before every commit - not just once.

I also noticed that the coverage is still about the same. This will need more test cases.
Screenshot 2025-08-01 at 6 23 16 PM

@MohdWaqar98
Copy link
Contributor Author

Hi @kasya ,

I've been working on this issue consistently for the past 4 days — going through your suggestions, fixing everything step by step, and writing as many test cases as I possibly could. I've managed to improve the coverage a bit, but I understand it's still below the expected threshold.

This is truly the best I could achieve with my current knowledge and resources. I really pushed myself because I wanted to contribute meaningfully, especially since I had a Level 1 issue merged earlier and was hopeful I could handle this one too.

If you feel the effort and partial improvements are worth accepting, I’d sincerely appreciate it. If not, I completely understand and respect your standards. Either way, I'm genuinely thankful for the opportunity — I’ve learned a lot through this process.

Thanks again,
Mohd Waqar

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ac3e2c and a5dfaa7.

📒 Files selected for processing (1)
  • frontend/__tests__/unit/components/BarChart.test.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: ahmedxgouda
PR: OWASP/Nest#1703
File: frontend/src/components/BarChart.tsx:33-46
Timestamp: 2025-07-03T03:08:03.290Z
Learning: In the OWASP Nest project's BarChart component (frontend/src/components/BarChart.tsx), the days and requirements arrays are guaranteed to always have the same length in their use cases, so input validation for array length matching is not needed.
Learnt from: Rajgupta36
PR: OWASP/Nest#1717
File: frontend/__tests__/unit/pages/createProgram.test.tsx:70-86
Timestamp: 2025-07-12T17:36:57.255Z
Learning: When testing React page components that use mocked form components, validation logic should be tested at the form component level, not the page level. Page-level tests should focus on authentication, role checking, submission handling, and navigation logic.
Learnt from: ahmedxgouda
PR: OWASP/Nest#1633
File: frontend/src/components/GradientRadialChart.tsx:67-116
Timestamp: 2025-06-21T12:21:32.372Z
Learning: The react-apexcharts Chart component does not support ARIA attributes like aria-label and role as direct props. To add accessibility attributes to ApexCharts in React, wrap the Chart component in a container div with the appropriate ARIA attributes.
📚 Learning: in the owasp nest project's barchart component (frontend/src/components/barchart.tsx), the days and ...
Learnt from: ahmedxgouda
PR: OWASP/Nest#1703
File: frontend/src/components/BarChart.tsx:33-46
Timestamp: 2025-07-03T03:08:03.290Z
Learning: In the OWASP Nest project's BarChart component (frontend/src/components/BarChart.tsx), the days and requirements arrays are guaranteed to always have the same length in their use cases, so input validation for array length matching is not needed.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: the react-apexcharts chart component does not support aria attributes like aria-label and role as di...
Learnt from: ahmedxgouda
PR: OWASP/Nest#1633
File: frontend/src/components/GradientRadialChart.tsx:67-116
Timestamp: 2025-06-21T12:21:32.372Z
Learning: The react-apexcharts Chart component does not support ARIA attributes like aria-label and role as direct props. To add accessibility attributes to ApexCharts in React, wrap the Chart component in a container div with the appropriate ARIA attributes.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: when testing react page components that use mocked form components, validation logic should be teste...
Learnt from: Rajgupta36
PR: OWASP/Nest#1717
File: frontend/__tests__/unit/pages/createProgram.test.tsx:70-86
Timestamp: 2025-07-12T17:36:57.255Z
Learning: When testing React page components that use mocked form components, validation logic should be tested at the form component level, not the page level. Page-level tests should focus on authentication, role checking, submission handling, and navigation logic.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: the owasp nest application has logging disabled, so avoid suggesting console.log, console.error, or ...
Learnt from: Rajgupta36
PR: OWASP/Nest#1634
File: frontend/src/app/api/auth/[...nextauth]/route.ts:30-55
Timestamp: 2025-06-18T20:00:23.899Z
Learning: The OWASP Nest application has logging disabled, so avoid suggesting console.log, console.error, or any other logging statements in code review suggestions.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: when implementing dropdown menus or similar interactive components, always include proper accessibil...
Learnt from: codic-yeeshu
PR: OWASP/Nest#1444
File: frontend/src/components/NavDropDown.tsx:0-0
Timestamp: 2025-04-30T13:41:20.846Z
Learning: When implementing dropdown menus or similar interactive components, always include proper accessibility features: ARIA attributes (aria-expanded, aria-haspopup, aria-controls), keyboard navigation support (Enter, Space, Escape keys), and mechanisms to close dropdowns when clicking outside.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
📚 Learning: use react's useid() hook rather than manually generating random strings when creating accessibility ...
Learnt from: codic-yeeshu
PR: OWASP/Nest#1444
File: frontend/src/components/NavDropDown.tsx:0-0
Timestamp: 2025-04-30T13:41:20.846Z
Learning: Use React's useId() hook rather than manually generating random strings when creating accessibility identifiers for UI components. This creates stable, unique IDs without causing hydration mismatches.

Applied to files:

  • frontend/__tests__/unit/components/BarChart.test.tsx
🔇 Additional comments (8)
frontend/__tests__/unit/components/BarChart.test.tsx (8)

10-72: Well-structured mock setup

The mocking strategy effectively isolates the BarChart component by providing test doubles for all external dependencies. The mocks are comprehensive and follow testing best practices.


77-83: Good implementation of the renderWithTheme helper

The helper function correctly returns the render result and is synchronous, which addresses the previous review feedback effectively.


121-139: Comprehensive theme testing

The tests effectively verify theme-specific colors and settings for both light and dark modes, ensuring the component responds correctly to theme changes.


141-199: Thorough validation of chart configuration and data structure

These tests provide excellent coverage of the chart's configuration options and validate the complete data structure including goals, stroke properties, and data point mappings.


458-484: Good edge case coverage

These tests effectively verify that the component handles empty data and mismatched array lengths gracefully without crashing.


486-504: Well-implemented theme switching test

This test properly validates theme changes by using rerender and checking the updated options without conditional logic.


601-663: Excellent coverage of numeric edge cases

These tests comprehensively cover various numeric scenarios including zero, negative, decimal, large numbers, and mixed values. The tests are deterministic and well-structured.

Also applies to: 722-767


93-768: Summary: Address conditional assertions throughout the test suite

While this test suite provides excellent coverage of the BarChart component, it needs refactoring to remove all conditional expect statements as requested in the PR feedback. The main areas requiring updates are:

  1. Color function tests (lines 201-277, 279-373, 506-592, 704-720)
  2. Data label formatter tests (lines 375-456, 675-702)

Each test should contain deterministic assertions without if conditions wrapping the expect statements.

@kasya
Copy link
Collaborator

kasya commented Aug 3, 2025

Hi @kasya ,

If you feel the effort and partial improvements are worth accepting, I’d sincerely appreciate it. If not, I completely understand and respect your standards. Either way, I'm genuinely thankful for the opportunity — I’ve learned a lot through this process.

Thanks again, Mohd Waqar

Hi @MohdWaqar98!
Thanks for being honest about it and not abandoning the PR. I'll fix some things that are failing right now (like multiple dynamic expect - this is not allowed) and then will merge in as is. We'll then have an extra issue to get this component's test coverage to higher numbers by someone else.

@MohdWaqar98 MohdWaqar98 requested a review from kasya August 7, 2025 12:33
@MohdWaqar98 MohdWaqar98 requested a review from arkid15r August 7, 2025 12:33
@sonarqubecloud
Copy link

Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MohdWaqar98 Thank you for working on this issue! I know it took time to figure out the test cases and even thought the coverage was low, I appreciate the enthusiasm.

I added more tests and it should be at 100% now for the component 👍🏼

@kasya kasya enabled auto-merge August 16, 2025 00:46
@kasya kasya added this pull request to the merge queue Aug 16, 2025
Merged via the queue into OWASP:main with commit 256ff10 Aug 16, 2025
24 checks passed
Dhirajsharma2060 pushed a commit to Dhirajsharma2060/Nest that referenced this pull request Aug 16, 2025
* Add unit tests for BarChart component

- Added comprehensive test cases for BarChart component
- Tests cover rendering, data handling, and prop validation
- Follows project testing standards

* Add unit tests for BarChart component

* Add unit tests for BarChart component

* Fix linting issues

* Fixed unit tests for BarChart component

* Fixed unit tests for BarChart component By CodeRabbit

* Fixed unit tests for BarChart component By CodeRabbit

* Fix tests and make check issues

* Fixed unit tests for BarChart component

* Fix issues and add more tests

---------

Co-authored-by: Kate Golovanova <[email protected]>
@MohdWaqar98 MohdWaqar98 deleted the test/bar-chart branch August 21, 2025 07:02
github-merge-queue bot pushed a commit that referenced this pull request Aug 28, 2025
* test: add unit tests for SortBy component

* test: update SortBy component tests for prop naming and accessibility

* test: import React in SortBy component tests for consistency

* made some chnages

* test: update SortBy component tests for improved accessibility and clarity

* test: ensure order toggle button functionality in SortBy component tests

* feat: add has_full_name filter to top contributors query and model

* fix: update regex for user name filtering in RepositoryContributor queryset

* Update code

* test: enhance RepositoryContributor tests with full name filter validations

* refactor: use class constants for regex pattern and mock data in RepositoryContributor tests

* test: fix regex filter call in has_full_name filter validation

* Update code

* Update tests

* Update code

* Update tests

* Update test

* feat: periodic job to sync OWASP Employee badges (#1762)

* fix: optimize badge assignment logic and improve test coverage for sync_user_badges command

* refactor: clean up comments in sync_user_badges test cases for clarity

* refactor: remove unused mock_badge fixture from sync_user_badges test

* feat: add management command to sync OWASP Staff badges and corresponding tests

* refactor: optimize badge assignment logic for OWASP Staff badge sync

* Update code

* feat: add badges field to User model and update badge sync logic for OWASP staff

feat:add badges field to User model and updated badge sync logic OWASP staff

* feat: add badges field to User model and update related tests for badge synchronization

* test: ensure no badge operations are performed when no employees are eligible

* test: enhance user filter logic and improve badge assignment messages in tests suggested by coderabbit

* test: refine user filter logic for badge assignment and enhance handling of keyword and positional arguments

* test: refactor user filter logic in badge assignment tests for improved clarity and functionality

* test: simplify user filter logic in badge assignment tests for improved readability and maintainability

* test: simplify user filter logic by extracting helper functions for improved clarity and maintainability

* test: update patch paths for badge and user objects in sync_user_badges tests for consistency

* Update code

* test: update patch paths for badge and user objects in TestSyncUserBadgesCommand for consistency

* Fix #1912: Added test for SecondaryCard component (#2069)

* Fix #1912: Added test for SecondaryCard component

* Added newline at end of SecondaryCard.test.tsx

* Fix make check

---------

Co-authored-by: Kate Golovanova <[email protected]>

* test: add unit tests for GeneralCompliantComponent (#2018)

* test: add unit tests for GeneralCompliantComponent

* fix(#1835): Refactor tests based on reviewer feedback

* Fix make check and revert unnecessary changes

* Fix issues

---------

Co-authored-by: Kate Golovanova <[email protected]>

* Added Light Theme Support for Contribution HeatMap (#2072)

* Added Light Theme Support for Contribution HeatMap

* Added Light Theme Support for Contribution HeatMap (Updated)

* Added Light Theme Support for Contribution HeatMap (Updated)

* Update color scheme for the heatmap

* Update code

---------

Co-authored-by: Kate Golovanova <[email protected]>
Co-authored-by: Arkadii Yakovets <[email protected]>
Co-authored-by: Arkadii Yakovets <[email protected]>

* feat: add comprehensive unit tests for DisplayIcon component (#2048)

* feat: add comprehensive unit tests for DisplayIcon component

- 30+ test cases covering rendering, props, edge cases, and accessibility
- Mock all dependencies and ensure SonarQube compliance
- Test both snake_case and camelCase property conventions

* Fixed issues flagged by the bot

* Fixed issues flagged by the bot

* Fixed issues flagged by the bot and added unhover word in cspell/custom-dict.txt

---------

Co-authored-by: Kate Golovanova <[email protected]>

* enhance:change-hover-color-action-button (#1978)

* enhance:change-hover-color-action-button

* Update colors and tests

* Add comprehensive hover state check

---------

Co-authored-by: Kate <[email protected]>

* Test: add unit tests for BarChart component #1801 (#1904)

* Add unit tests for BarChart component

- Added comprehensive test cases for BarChart component
- Tests cover rendering, data handling, and prop validation
- Follows project testing standards

* Add unit tests for BarChart component

* Add unit tests for BarChart component

* Fix linting issues

* Fixed unit tests for BarChart component

* Fixed unit tests for BarChart component By CodeRabbit

* Fixed unit tests for BarChart component By CodeRabbit

* Fix tests and make check issues

* Fixed unit tests for BarChart component

* Fix issues and add more tests

---------

Co-authored-by: Kate Golovanova <[email protected]>

* Project Dasbored Drop Down Test case has been made (#2052)

* Project Dasbored Drop Down Test case has been made

* Changes made

* Made the changes for the code check and test cases

* Changes has been made so that it works with eslint

* Fix make check issues

---------

Co-authored-by: Kate Golovanova <[email protected]>

* fix: update command references in badge management tests

* Update code

* fix: update badge management command to correctly filter users by badge relationship

* style: format code for better readability in badge assignment logic

* fix: update badge assignment logic to use UserBadge model and remove unnecessary user management calls

* fix: include owasp Makefile in backend Makefile

* fix: improve badge removal logic for non-OWASP employees

* fix: add unique constraint for user and badge in UserBadge model

* Update code

* Revert volumes

* feat: add is_active field to UserBadge model and update badge assignment logic

* style: format migration file for userbadge is_active field

* test: mock return value for UserBadge get_or_create in badge sync tests

* fix: correct docstring for nest_update_badges management command tests

* Update code

---------

Co-authored-by: Arkadii Yakovets <[email protected]>
Co-authored-by: Arkadii Yakovets <[email protected]>
Co-authored-by: rasesh <[email protected]>
Co-authored-by: Kate Golovanova <[email protected]>
Co-authored-by: Karmjeet Chauhan <[email protected]>
Co-authored-by: Abhay Bahuguna <[email protected]>
Co-authored-by: Rizwaan Ansari <[email protected]>
Co-authored-by: Vijesh Shetty <[email protected]>
Co-authored-by: Mohd Waqar Ahemed <[email protected]>
Co-authored-by: SOHAMPAL23 <[email protected]>
Dishant1804 pushed a commit to Dishant1804/Nest that referenced this pull request Sep 6, 2025
* test: add unit tests for SortBy component

* test: update SortBy component tests for prop naming and accessibility

* test: import React in SortBy component tests for consistency

* made some chnages

* test: update SortBy component tests for improved accessibility and clarity

* test: ensure order toggle button functionality in SortBy component tests

* feat: add has_full_name filter to top contributors query and model

* fix: update regex for user name filtering in RepositoryContributor queryset

* Update code

* test: enhance RepositoryContributor tests with full name filter validations

* refactor: use class constants for regex pattern and mock data in RepositoryContributor tests

* test: fix regex filter call in has_full_name filter validation

* Update code

* Update tests

* Update code

* Update tests

* Update test

* feat: periodic job to sync OWASP Employee badges (OWASP#1762)

* fix: optimize badge assignment logic and improve test coverage for sync_user_badges command

* refactor: clean up comments in sync_user_badges test cases for clarity

* refactor: remove unused mock_badge fixture from sync_user_badges test

* feat: add management command to sync OWASP Staff badges and corresponding tests

* refactor: optimize badge assignment logic for OWASP Staff badge sync

* Update code

* feat: add badges field to User model and update badge sync logic for OWASP staff

feat:add badges field to User model and updated badge sync logic OWASP staff

* feat: add badges field to User model and update related tests for badge synchronization

* test: ensure no badge operations are performed when no employees are eligible

* test: enhance user filter logic and improve badge assignment messages in tests suggested by coderabbit

* test: refine user filter logic for badge assignment and enhance handling of keyword and positional arguments

* test: refactor user filter logic in badge assignment tests for improved clarity and functionality

* test: simplify user filter logic in badge assignment tests for improved readability and maintainability

* test: simplify user filter logic by extracting helper functions for improved clarity and maintainability

* test: update patch paths for badge and user objects in sync_user_badges tests for consistency

* Update code

* test: update patch paths for badge and user objects in TestSyncUserBadgesCommand for consistency

* Fix OWASP#1912: Added test for SecondaryCard component (OWASP#2069)

* Fix OWASP#1912: Added test for SecondaryCard component

* Added newline at end of SecondaryCard.test.tsx

* Fix make check

---------

Co-authored-by: Kate Golovanova <[email protected]>

* test: add unit tests for GeneralCompliantComponent (OWASP#2018)

* test: add unit tests for GeneralCompliantComponent

* fix(OWASP#1835): Refactor tests based on reviewer feedback

* Fix make check and revert unnecessary changes

* Fix issues

---------

Co-authored-by: Kate Golovanova <[email protected]>

* Added Light Theme Support for Contribution HeatMap (OWASP#2072)

* Added Light Theme Support for Contribution HeatMap

* Added Light Theme Support for Contribution HeatMap (Updated)

* Added Light Theme Support for Contribution HeatMap (Updated)

* Update color scheme for the heatmap

* Update code

---------

Co-authored-by: Kate Golovanova <[email protected]>
Co-authored-by: Arkadii Yakovets <[email protected]>
Co-authored-by: Arkadii Yakovets <[email protected]>

* feat: add comprehensive unit tests for DisplayIcon component (OWASP#2048)

* feat: add comprehensive unit tests for DisplayIcon component

- 30+ test cases covering rendering, props, edge cases, and accessibility
- Mock all dependencies and ensure SonarQube compliance
- Test both snake_case and camelCase property conventions

* Fixed issues flagged by the bot

* Fixed issues flagged by the bot

* Fixed issues flagged by the bot and added unhover word in cspell/custom-dict.txt

---------

Co-authored-by: Kate Golovanova <[email protected]>

* enhance:change-hover-color-action-button (OWASP#1978)

* enhance:change-hover-color-action-button

* Update colors and tests

* Add comprehensive hover state check

---------

Co-authored-by: Kate <[email protected]>

* Test: add unit tests for BarChart component OWASP#1801 (OWASP#1904)

* Add unit tests for BarChart component

- Added comprehensive test cases for BarChart component
- Tests cover rendering, data handling, and prop validation
- Follows project testing standards

* Add unit tests for BarChart component

* Add unit tests for BarChart component

* Fix linting issues

* Fixed unit tests for BarChart component

* Fixed unit tests for BarChart component By CodeRabbit

* Fixed unit tests for BarChart component By CodeRabbit

* Fix tests and make check issues

* Fixed unit tests for BarChart component

* Fix issues and add more tests

---------

Co-authored-by: Kate Golovanova <[email protected]>

* Project Dasbored Drop Down Test case has been made (OWASP#2052)

* Project Dasbored Drop Down Test case has been made

* Changes made

* Made the changes for the code check and test cases

* Changes has been made so that it works with eslint

* Fix make check issues

---------

Co-authored-by: Kate Golovanova <[email protected]>

* fix: update command references in badge management tests

* Update code

* fix: update badge management command to correctly filter users by badge relationship

* style: format code for better readability in badge assignment logic

* fix: update badge assignment logic to use UserBadge model and remove unnecessary user management calls

* fix: include owasp Makefile in backend Makefile

* fix: improve badge removal logic for non-OWASP employees

* fix: add unique constraint for user and badge in UserBadge model

* Update code

* Revert volumes

* feat: add is_active field to UserBadge model and update badge assignment logic

* style: format migration file for userbadge is_active field

* test: mock return value for UserBadge get_or_create in badge sync tests

* fix: correct docstring for nest_update_badges management command tests

* Update code

---------

Co-authored-by: Arkadii Yakovets <[email protected]>
Co-authored-by: Arkadii Yakovets <[email protected]>
Co-authored-by: rasesh <[email protected]>
Co-authored-by: Kate Golovanova <[email protected]>
Co-authored-by: Karmjeet Chauhan <[email protected]>
Co-authored-by: Abhay Bahuguna <[email protected]>
Co-authored-by: Rizwaan Ansari <[email protected]>
Co-authored-by: Vijesh Shetty <[email protected]>
Co-authored-by: Mohd Waqar Ahemed <[email protected]>
Co-authored-by: SOHAMPAL23 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for <BarChart> component

3 participants