Skip to content

test: add coverage for reading analytics hooks#2098

Open
SujalMahapatra wants to merge 2 commits into
SB2318:mainfrom
SujalMahapatra:test/reading-analytics-hooks
Open

test: add coverage for reading analytics hooks#2098
SujalMahapatra wants to merge 2 commits into
SB2318:mainfrom
SujalMahapatra:test/reading-analytics-hooks

Conversation

@SujalMahapatra

@SujalMahapatra SujalMahapatra commented Jul 8, 2026

Copy link
Copy Markdown

PR Description

This PR adds automated test coverage for the reading analytics hooks used throughout the analytics dashboard.

Changes Made

  • Added tests for useGetTotalReads
  • Added tests for useGetTotalLikeViewStatus
  • Added tests for useGetMonthlyReadReport
  • Added tests for useGetYearlyReadReport
  • Followed the existing hook testing pattern already used in the repository
  • Verified successful execution of all newly added test cases

These tests help improve reliability of analytics-related functionality and provide a foundation for detecting regressions in future updates.

Type of Change

  • New Feature (Change which adds functionality)

Select your work-area

  • Frontend

Related Issue

Issue assigned by maintainer regarding testing and validation of reading analytics functionality.

Add your Work Example

📷 Attached screenshots showing all analytics hook tests passing successfully.
Screenshot 2026-07-08 223256
Screenshot 2026-07-08 223554

Fixes (mention the issue number which this fixes)

#closes #2093

Checklist

  • I have updated my branch and synced it with the project's 'develop' branch before making this PR.
  • I have optimized the file changes.
  • I have added a snapshot of my work example.
  • I have made a PR to the project's develop branch.

Undertaking

  • My code follows the style guidelines of this project.

  • I have performed a self-review of my code.

  • I have commented my code, particularly in hard-to-understand areas.

  • I have made corresponding changes to the documentation.

  • I have checked for plagiarism and assure its authenticity.

  • I have read and followed the code of conduct for this repository. I understand that violation of this undertaking may have legal consequences.

  • I Agree

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Thank you @, for creating the PR and contributing to our UltimateHealth project 💗.
Our team will review the PR and will reach out to you soon! 😇
Make sure that you have marked all the tasks that you are done with ✅.
Thank you for your patience! 😀

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Automated Review Feedback

Provide actionable comments grouped by severity:

Important

  • Insufficient Test Assertions: The current tests primarily verify that the hooks render and return a query object, but they lack assertions on the actual data returned, loading/error states, or specific behavior when axios.get is mocked. This significantly reduces their value in catching regressions or ensuring correctness of the hook's logic.
    • Actionable: For each hook, mock axios.get to return specific data and then assert that result.current.data matches the mocked data, and that result.current.isSuccess becomes true. Also, add tests for isLoading and isError states by mocking axios.get to reject.
  • Incomplete Conditional Fetching Tests: For useGetMonthlyReadReport and useGetYearlyReadReport, the tests for selectedMonth = -1 and selectedYear = -1 only check if the hook renders. They do not verify that an API call is not made in these scenarios (assuming the hooks are designed to prevent calls for invalid inputs). Similarly, test cases for isConnected: false should verify no API call is made.
    • Actionable: For these edge cases (e.g., selectedMonth: -1, isConnected: false), assert that axios.get was not.toHaveBeenCalled(). You might need to use jest.spyOn(axios, 'get') or clear the mock before each test ((axios.get as jest.Mock).mockClear();) to accurately track calls.

Suggestions

  • Correct PR Type: The PR description incorrectly states "Type of Change: Documentation update". This PR adds tests, so the correct type should be type:testing. Please update the PR description to reflect the actual changes.
  • Add afterEach Cleanup: Although renderHook handles some cleanup, explicitly calling queryClient.clear() in an afterEach block within makeWrapper or the describe block can prevent test pollution between runs, especially when dealing with @tanstack/react-query's cache.

Maintainer Note:

Once the initial automated feedback has been addressed, maintainer @SB2318 will review the pull request for final evaluation.

@SujalMahapatra

Copy link
Copy Markdown
Author

Addressed the automated review feedback:

Added assertions for successful API responses and returned data.
Added coverage for conditional fetch scenarios (selectedMonth = -1, selectedYear = -1, and disconnected state).
Verified all analytics hook tests pass locally.

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.

[TESTING] : Add Unit Tests for Reading Analytics Hooks

1 participant