Skip to content

Add Pagination Unit Tests & Accessibility Tweaks (Closes #1864)#1879

Closed
suryansh-it wants to merge 3 commits intoOWASP:mainfrom
suryansh-it:main
Closed

Add Pagination Unit Tests & Accessibility Tweaks (Closes #1864)#1879
suryansh-it wants to merge 3 commits intoOWASP:mainfrom
suryansh-it:main

Conversation

@suryansh-it
Copy link
Contributor

Proposed change

Resolves #1864

This PR adds comprehensive unit tests for the <Pagination> component and applies three minimal, non‑functional tweaks to improve accessibility and test reliability:

  1. type="button" on all <Button> elements
    • Prevents default form submissions
    • Enables RTL’s getByRole('button') queries
  2. aria-current="page" on the active page button
    • Improves screen‑reader feedback
    • Simplifies identifying the active page in tests
  3. data-testid="ellipsis" and role="presentation" on each ellipsis <span>
    • Provides a stable hook for getAllByTestId('ellipsis')
    • Marks these spans as decorative

Additionally, this PR introduces __tests__/unit/components/Pagination.test.tsx with 11 test cases covering:

  • Conditional rendering (isLoaded=false, totalPages<=1)
  • Prev/Next enablement and disabled states
  • Correct page‑number generation (small/large sets)
  • Ellipsis logic and placement
  • Event callbacks (onPageChange)
  • Accessibility (aria-current)
  • Edge cases (currentPage at extremes, tiny totalPages)

Tests use afterEach(cleanup) and within(container) to scope queries per render.

Checklist

  • I've read and followed the contributing guidelines.
  • I've run make check-test locally; all checks and tests passed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 27, 2025

Summary by CodeRabbit

  • New Features

    • Added comprehensive tests for the pagination component, covering various scenarios and accessibility features.
  • Accessibility

    • Improved pagination controls with enhanced accessibility attributes, including explicit button types and ARIA labels.
  • Chores

    • Introduced a package configuration file specifying TypeScript as a project dependency.

Walkthrough

A new unit test suite for the <Pagination /> React component has been introduced, covering its rendering, behavior, accessibility, and edge cases. The component itself was updated to add explicit button types, accessibility attributes, and testability enhancements without changing its core logic.

Changes

Cohort / File(s) Change Summary
Pagination tests
frontend/__tests__/unit/components/Pagination.test.tsx
Added comprehensive unit tests for the <Pagination /> component, covering rendering, behavior, accessibility, and edge cases.
Pagination component updates
frontend/src/components/Pagination.tsx
Added type="button" to all buttons, aria-current for active page buttons, and accessibility attributes (role="presentation", aria-label) for ellipsis elements.
Project configuration
package.json
Added package.json with dependency on TypeScript v5.8.3+ to enable TypeScript support.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective Addressed Explanation
Renders successfully with minimal required props
Conditional rendering logic
Prop-based behavior – different props affect output
Event handling – simulate user actions and verify callbacks
State changes / internal logic
Default values and fallbacks
Text and content rendering
Handles edge cases and invalid inputs
Accessibility roles and labels
DOM structure / classNames / styles

Suggested reviewers

  • kasya
  • arkid15r

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c858a55 and d022ebd.

⛔ Files ignored due to path filters (139)
  • frontend/package-lock.json is excluded by !**/package-lock.json
  • node_modules/.bin/tsc is excluded by !**/node_modules/**
  • node_modules/.bin/tsc.cmd is excluded by !**/node_modules/**
  • node_modules/.bin/tsc.ps1 is excluded by !**/node_modules/**
  • node_modules/.bin/tsserver is excluded by !**/node_modules/**
  • node_modules/.bin/tsserver.cmd is excluded by !**/node_modules/**
  • node_modules/.bin/tsserver.ps1 is excluded by !**/node_modules/**
  • node_modules/.package-lock.json is excluded by !**/node_modules/**
  • node_modules/typescript/LICENSE.txt is excluded by !**/node_modules/**
  • node_modules/typescript/README.md is excluded by !**/node_modules/**
  • node_modules/typescript/SECURITY.md is excluded by !**/node_modules/**
  • node_modules/typescript/ThirdPartyNoticeText.txt is excluded by !**/node_modules/**
  • node_modules/typescript/bin/tsc is excluded by !**/node_modules/**
  • node_modules/typescript/bin/tsserver is excluded by !**/node_modules/**
  • node_modules/typescript/lib/_tsc.js is excluded by !**/node_modules/**
  • node_modules/typescript/lib/_tsserver.js is excluded by !**/node_modules/**
  • node_modules/typescript/lib/_typingsInstaller.js is excluded by !**/node_modules/**
  • node_modules/typescript/lib/cs/diagnosticMessages.generated.json is excluded by !**/node_modules/**
  • node_modules/typescript/lib/de/diagnosticMessages.generated.json is excluded by !**/node_modules/**
  • node_modules/typescript/lib/es/diagnosticMessages.generated.json is excluded by !**/node_modules/**
  • node_modules/typescript/lib/fr/diagnosticMessages.generated.json is excluded by !**/node_modules/**
  • node_modules/typescript/lib/it/diagnosticMessages.generated.json is excluded by !**/node_modules/**
  • node_modules/typescript/lib/ja/diagnosticMessages.generated.json is excluded by !**/node_modules/**
  • node_modules/typescript/lib/ko/diagnosticMessages.generated.json is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.decorators.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.decorators.legacy.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.dom.asynciterable.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.dom.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.dom.iterable.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2015.collection.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2015.core.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2015.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2015.generator.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2015.iterable.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2015.promise.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2015.proxy.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2015.reflect.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2015.symbol.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2016.array.include.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2016.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2016.full.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2016.intl.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2017.arraybuffer.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2017.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2017.date.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2017.full.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2017.intl.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2017.object.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2017.string.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2017.typedarrays.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2018.asynciterable.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2018.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2018.full.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2018.intl.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2018.promise.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2018.regexp.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2019.array.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2019.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2019.full.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2019.intl.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2019.object.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2019.string.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2019.symbol.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2020.bigint.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2020.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2020.date.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2020.full.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2020.intl.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2020.number.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2020.promise.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2020.string.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2021.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2021.full.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2021.intl.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2021.promise.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2021.string.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2021.weakref.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2022.array.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2022.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2022.error.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2022.full.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2022.intl.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2022.object.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2022.regexp.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2022.string.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2023.array.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2023.collection.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2023.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2023.full.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2023.intl.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2024.arraybuffer.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2024.collection.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2024.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2024.full.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2024.object.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2024.promise.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2024.regexp.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2024.sharedmemory.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es2024.string.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es5.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.es6.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.esnext.array.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.esnext.collection.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.esnext.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.esnext.decorators.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.esnext.disposable.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.esnext.float16.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.esnext.full.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.esnext.intl.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.esnext.iterator.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.esnext.promise.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.scripthost.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.webworker.asynciterable.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.webworker.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.webworker.importscripts.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/lib.webworker.iterable.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/pl/diagnosticMessages.generated.json is excluded by !**/node_modules/**
  • node_modules/typescript/lib/pt-br/diagnosticMessages.generated.json is excluded by !**/node_modules/**
  • node_modules/typescript/lib/ru/diagnosticMessages.generated.json is excluded by !**/node_modules/**
  • node_modules/typescript/lib/tr/diagnosticMessages.generated.json is excluded by !**/node_modules/**
  • node_modules/typescript/lib/tsc.js is excluded by !**/node_modules/**
  • node_modules/typescript/lib/tsserver.js is excluded by !**/node_modules/**
  • node_modules/typescript/lib/tsserverlibrary.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/tsserverlibrary.js is excluded by !**/node_modules/**
  • node_modules/typescript/lib/typesMap.json is excluded by !**/node_modules/**
  • node_modules/typescript/lib/typescript.d.ts is excluded by !**/node_modules/**
  • node_modules/typescript/lib/typescript.js is excluded by !**/node_modules/**
  • node_modules/typescript/lib/typingsInstaller.js is excluded by !**/node_modules/**
  • node_modules/typescript/lib/watchGuard.js is excluded by !**/node_modules/**
  • node_modules/typescript/lib/zh-cn/diagnosticMessages.generated.json is excluded by !**/node_modules/**
  • node_modules/typescript/lib/zh-tw/diagnosticMessages.generated.json is excluded by !**/node_modules/**
  • node_modules/typescript/package.json is excluded by !**/node_modules/**
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • frontend/__tests__/unit/components/Pagination.test.tsx (1 hunks)
  • frontend/src/components/Pagination.tsx (3 hunks)
  • package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/src/components/Pagination.tsx
  • frontend/tests/unit/components/Pagination.test.tsx
✨ 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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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.

Documentation and Community

  • 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: 0

🧹 Nitpick comments (1)
frontend/__tests__/unit/components/Pagination.test.tsx (1)

88-89: Simplify ellipsis detection using data-testid!

Since the component now includes data-testid="ellipsis" on ellipsis spans, you can simplify the detection:

-    const ellipses = screen.getAllByText((_, el) => el?.tagName === 'SPAN' && !el.textContent?.trim())
-    expect(ellipses.length).toBeGreaterThanOrEqual(2);
+    const ellipses = screen.getAllByTestId('ellipsis')
+    expect(ellipses).toHaveLength(2);

This approach is more reliable and takes advantage of the testability improvements made to the component.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d0153f and c858a55.

📒 Files selected for processing (2)
  • frontend/__tests__/unit/components/Pagination.test.tsx (1 hunks)
  • frontend/src/components/Pagination.tsx (3 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
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: Rajgupta36
PR: OWASP/Nest#1717
File: frontend/__tests__/unit/pages/ProgramDetails.test.tsx:35-0
Timestamp: 2025-07-12T17:12:25.807Z
Learning: In React applications, button elements should always have an explicit type attribute (type="button", type="submit", or type="reset") to prevent unintended form submission behavior, even when the button appears to be outside of a form context. The default type is "submit" which can cause unexpected behavior.
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.
frontend/src/components/Pagination.tsx (1)

Learnt from: Rajgupta36
PR: #1717
File: frontend/tests/unit/pages/ProgramDetails.test.tsx:35-0
Timestamp: 2025-07-12T17:12:25.807Z
Learning: In React applications, button elements should always have an explicit type attribute (type="button", type="submit", or type="reset") to prevent unintended form submission behavior, even when the button appears to be outside of a form context. The default type is "submit" which can cause unexpected behavior.

frontend/__tests__/unit/components/Pagination.test.tsx (1)

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 (8)
frontend/src/components/Pagination.tsx (3)

64-64: Excellent addition of explicit button types!

Adding type="button" to all Button components prevents unintended form submission behavior and aligns with React Testing Library's getByRole('button') queries. This follows established best practices for button elements.

Also applies to: 82-82, 97-97


83-83: Great accessibility enhancement for current page indication!

The conditional aria-current="page" attribute properly indicates the active page to screen readers, improving accessibility. Setting it to undefined when not current correctly removes the attribute.


74-77: Proper semantic markup for ellipsis elements!

Adding role="presentation" correctly marks the ellipsis spans as decorative elements, while data-testid="ellipsis" provides stable test hooks. This enhances both accessibility and testability.

frontend/__tests__/unit/components/Pagination.test.tsx (5)

1-26: Well-structured test setup with proper cleanup!

The test setup follows best practices with comprehensive imports, proper DOM cleanup using afterEach(cleanup), and a flexible renderComponent helper function. The mock clearing in beforeEach ensures test isolation.


28-36: Comprehensive coverage of conditional rendering!

These tests properly verify the component's early return conditions when isLoaded is false or totalPages is 1 or less. Using container.firstChild to check for null rendering is the correct approach.


38-77: Excellent coverage of core pagination functionality!

These tests thoroughly verify button rendering, proper enabling/disabling of navigation buttons at boundaries, and correct callback invocation with expected page numbers. The use of within(container) for scoped queries is a good practice.


100-108: Excellent accessibility testing!

This test properly validates both the visual styling (bg-[#83a6cc] class) and accessibility (aria-current="page" attribute) of the active page button, ensuring the component enhancements work as expected.


110-133: Comprehensive edge case coverage!

These tests effectively cover important edge cases including default prop values, current page positioning in large sets, and minimal page counts. The regex pattern for exact button matching is well-implemented.

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.

Thanks for working on this.
Added a comment in the code. Also, please run make check locally and push updated files - this is required before opening any PRs in OWASP Nest.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actual components should not have a data-testid set on the elements. Please check other test files to see how to address this.

@suryansh-it
Copy link
Contributor Author

suryansh-it commented Jul 27, 2025

@kasya Thanks for the feedback and Guidance! I’ll remove the "data-testid" from the component, add an appropriate "aria-label" to the ellipsis "span", update the test to use visible text for ellipses, and run "make check" locally before pushing the changes.

@github-actions github-actions bot added the docs Improvements or additions to documentation label Jul 28, 2025
@sonarqubecloud
Copy link

@suryansh-it
Copy link
Contributor Author

✅ Changes made as requested:

  • Removed data-testid, replaced with aria-label="More pages"
  • Updated tests to use getAllByLabelText('More pages')
  • Ran make check and resolved pre-commit issues

Let me know if any further updates are needed!

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.

Please remove the unrelated files from the PR

@suryansh-it
Copy link
Contributor Author

Please remove the unrelated files from the PR

@arkid15r thanks for catching that! I’ll prune the PR to only include the Pagination component and its tests, run make check, and push an updated commit soon.

@suryansh-it suryansh-it changed the base branch from main to dependabot/npm_and_yarn/frontend/main/heroui/react-2.8.2 July 29, 2025 07:42
@suryansh-it suryansh-it changed the base branch from dependabot/npm_and_yarn/frontend/main/heroui/react-2.8.2 to main July 29, 2025 07:46
@suryansh-it
Copy link
Contributor Author

I've created a clean version of this PR with only the relevant files as requested by @arkid15r. Please refer to the new PR: #1903

Closing this one to keep things tidy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation frontend frontend-tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for <Pagination> component

3 participants

Comments