Skip to content

test(Tasks): add unit tests for annotation editing flow and state transitions - #480

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

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

Conversation

@Aspirant200715

Copy link
Copy Markdown

Description

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

Following the modular testing pattern established in #461 and #479, these tests validate 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 & Input Management (TaskDialog.tsx)

  • Entering edit mode on a task's annotations row activates editState.isEditingAnnotations, mounting an input field with the placeholder "Add an annotation (press enter to add)".
  • When the user enters an annotation and presses Enter:
    • The component validates that the trimmed input is non-empty.
    • Creates an annotation object with a timestamp using new Date().toISOString().
    • Appends the annotation to editState.editedAnnotations.
    • Clears editState.annotationInput.
  • Each rendered annotation badge contains an inline removal button (✖), which removes the corresponding item from editState.editedAnnotations.

2. Persistence & Backend Dispatch (Tasks.tsx)

  • Clicking Save invokes handleSaveAnnotations(task, editState.editedAnnotations).
  • The handler:
    • Updates task.annotations.
    • Registers the task UUID in unsyncedTaskUuids.
    • Calls handleEditTaskOnBackend, forwarding the updated annotations array to hooks.editTaskOnBackend.
  • Clicking Cancel (Cancel editing annotations) resets isEditingAnnotations to false, restores editedAnnotations to task.annotations || [], and clears any uncommitted input without triggering a backend call.

Tests Implemented

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

Four test cases have been added:

  1. should add a new annotation and save to backend

    • Verifies that entering an annotation, pressing Enter, and clicking Save dispatches editTaskOnBackend with the new annotation in the payload.
  2. should remove an added annotation before saving

    • Verifies that clicking the removal button (✖) removes the annotation from editedAnnotations before the updated data is sent to the backend.
  3. should not add an annotation when input is empty or whitespace

    • Verifies that empty or whitespace-only input is ignored when Enter is pressed and does not create annotation badges.
  4. should cancel editing annotations without calling backend

    • Verifies that clicking Cancel dismisses the editor and restores the original annotation state without making an API call.

Related issue: #433


Checklist

  • Added unit tests covering annotation addition, removal, input validation, and cancellation.
  • Ran the dedicated test suite: npm test -- src/components/HomeComponents/Tasks/__tests__/Tasks/Annotation.test.tsx (4 tests passed).
  • Ran the complete Tasks test suite: npm test -- --runInBand src/components/HomeComponents/Tasks/__tests__/Tasks/ (9 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/Annotation.test.tsx

  Annotation Editing
    ✓ should add a new annotation and save to backend
    ✓ should remove an added annotation before saving
    ✓ should not add an annotation when input is empty or whitespace
    ✓ should cancel editing annotations without calling backend

Test Suites: 1 passed, 1 total
Tests:       4 passed, 4 total
Snapshots:   0 total
Time:        6.489 s

Summary

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

It covers annotation creation, removal, input validation, backend persistence, and cancellation to ensure the workflow behaves 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 (createMockProps) and helper.ts (openTaskDialog, getRowAndClickEdit) to maintain consistency with the existing test structure.
  • Added cleanup in beforeEach to prevent test-to-test state mutations in mockTasks.
  • Validated annotation badge addition, badge removal (✖), empty-input suppression, and cancellation behavior.
  • Verified that all tests across src/components/HomeComponents/Tasks/__tests__/Tasks/ pass without regressions.
  • Confirmed that no production code was modified.

Ready for review. Thanks!


Full Test Suite Results

The complete Tasks test suite has been executed successfully across all three test files.

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

Test Suites: 3 passed, 3 total
Tests:       10 passed, 10 total
Snapshots:   0 total
Time:        10.683 s

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