Skip to content

test(Tasks): add unit tests for recur editing dialog and state transitions - #479

Open
Aspirant200715 wants to merge 1 commit into
CCExtractor:mainfrom
Aspirant200715:test/tasks-recur-editing
Open

Aspirant200715 wants to merge 1 commit into
CCExtractor:mainfrom
Aspirant200715:test/tasks-recur-editing

Conversation

@Aspirant200715

Copy link
Copy Markdown

Description

This PR adds unit test coverage for the Recurrence Editing workflow in the Tasks component, addressing the remaining checklist item in tracking issue #433.

Following the modular testing structure established in #461 and #467, these tests verify the interaction between Tasks.tsx, TaskDialog.tsx, and the shared test utilities (test-utils/setup.tsx and test-utils/helper.ts).

Technical Context & Component Workflow

1. Dialog & Selection (TaskDialog.tsx)

  • Entering edit mode on a task's recurrence row activates editState.isEditingRecur, mounting the mocked <Select> component.
  • Selecting an interval (daily, weekly, monthly, yearly, or none) updates editState.editedRecur.

2. Persistence Guard & Backend Dispatch (Tasks.tsx)

  • Clicking Save invokes handleRecurSaveClick(task, editState.editedRecur).
  • The handler implements an early-return guard: if editedRecur is 'none' or empty, it exits edit mode by setting isEditingRecur: false without triggering an unnecessary backend mutation.
  • For valid recurrence intervals, the handler:
    • Updates task.recur.
    • Registers the task UUID in unsyncedTaskUuids.
    • Dispatches handleEditTaskOnBackend.
    • Calls hooks.editTaskOnBackend with the updated Taskwarrior payload.

3. Cancel Transition

  • Clicking Cancel resets isEditingRecur and restores editedRecur to originalRecur.
  • No backend mutation is triggered.

Tests Implemented

Test file: frontend/src/components/HomeComponents/Tasks/__tests__/Tasks/Recur.test.tsx

Three test cases have been added:

  1. should save selected recur value to backend

    • Selects a recurrence interval (weekly) and clicks Save.
    • Verifies that hooks.editTaskOnBackend is called with recur: 'weekly' in the payload.
  2. should not call backend when none is selected

    • Selects 'none' and clicks Save.
    • Verifies that the early-return guard is triggered, edit mode is closed, and editTaskOnBackend is never called.
  3. should cancel editing recur without calling backend

    • Clicks Cancel during recurrence editing.
    • Verifies that the editing state is reverted to the original recurrence value without triggering a backend request.

Related issue: #433


Checklist

  • Added unit tests for the recurrence editing workflow.
  • Ran the dedicated test suite: npm test -- src/components/HomeComponents/Tasks/__tests__/Tasks/Recur.test.tsx (3 tests passed).
  • Ran the related test suites: npm test -- --runInBand src/components/HomeComponents/Tasks/__tests__/Tasks/ (6 tests passed).
  • Verified Prettier formatting through .githooks/pre-commit.
  • No production code modifications.

Test Plan & Verification

All tests were executed locally using Jest from the frontend/ directory.

PASS src/components/HomeComponents/Tasks/__tests__/Tasks/Recur.test.tsx

  Recur Editing
    ✓ should save selected recur value to backend
    ✓ should not call backend when none is selected
    ✓ should cancel editing recur without calling backend

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total

Summary

This PR focuses exclusively on testing the existing recurrence editing functionality without introducing production code changes.

It covers the successful persistence path, the 'none' recurrence guard, and the cancellation flow, ensuring that both state transitions and backend interactions behave as expected.

@github-actions

Copy link
Copy Markdown

Thank you for opening this PR!

Before a maintainer takes a look, it would be really helpful if you could walk through your changes using GitHub's review tools.

Please take a moment to:

  • Check the "Files changed" tab
  • Leave comments on any lines for functions, comments, etc. that are important, non-obvious, or may need attention
  • Clarify decisions you made or areas you might be unsure about and/or any future updates being considered.
  • Finally, submit all the comments!

More information on how to conduct a self review:
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/reviewing-proposed-changes-in-a-pull-request

This helps make the review process smoother and gives us a clearer understanding of your thought process.

Once you've added your self-review, we'll continue from our side. Thank you!

@Aspirant200715

Copy link
Copy Markdown
Author

Self-Review

  • Reused existing test utilities from test-utils/setup.tsx (selectMock, createMockProps) and helper.ts to maintain consistency with test(Tasks): Add Priority tests with shared test utilities #461.
  • Validated state transitions across isEditingRecur, editedRecur, and originalRecur.
  • Verified that all tests in src/components/HomeComponents/Tasks/__tests__/Tasks/ pass without regressions.
  • Confirmed that no production code was modified.

Ready for review. Thanks!

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant