callumalpass_tasknotes/tests/helpers
Callum Alpass bf11e1206f Refactor Types, Mocks, and Test Helpers for Improved Type Safety and Consistency
Commit Description:
• Update Typescript Interfaces:
  - In src/types.ts, extend TaskCreationData to include an optional "folder" property for specifying the folder path during task file creation.
  - In TimeEntry, add a "duration" property (number, in minutes) to support both calculated and manually entered time durations.

• Improve Utility Mocks:
  - Modify the debounce mock in tests/__mocks__/utils.ts to use a more precise function signature (...args: any[]) => any, increasing type-safety.

• Enhance Integration Helpers:
  - In tests/helpers/integration-helpers.ts, add a getMockApp() method for easier access to the mock app instance.
  - Update the filename generation logic to handle cases where the task title is undefined, defaulting to "untitled".
  - Refine method signatures in spies (e.g. generateTaskFilename and generateTaskBodyFromTemplate) with explicit any types for taskData and settings.
  - Change the getTaskByPath method to a private getTaskByPathFromFileSystem to clarify its purpose and usage.

• Strengthen Mock Factories:
  - In tests/helpers/mock-factories.ts, add explicit type annotations to mapping functions (contexts, tags, due) and define type for due (string | null).
  - Specify the statusMap as a Record<string, string> for clarity.

• Update Test Setup:
  - In tests/test-setup.ts, cast the global window and document objects using (global as any) to improve compatibility with mocked environments.
  - Enhance the createMockElement function by updating method signatures (createEl, createDiv, createSpan, setText, addClass, removeClass, toggleClass) with appropriate types.
  - Extend mocks for global objects such as IntersectionObserver and URL to include additional methods (takeRecords, createObjectURL, revokeObjectURL).

• Revise Modal Unit Tests:
  - In BaseTaskModal and TaskCreationModal tests, introduce a helper (createMockApp) to safely cast the mock App to the expected Obsidan App type, and update initialization accordingly.
  - Address TypeScript warnings with proper @ts-ignore comments and ensure modal initialization and method calls (including initializeFormData) adhere to expected types.

• Update Helpers Unit Tests:
  - In tests/unit/utils/helpers.test.ts, remove redundant mapping definitions from the mockFieldMapper and refine the mapToFrontmatter and toUserField function signatures, ensuring explicit type annotations.

This refactor enhances type safety, improves test reliability, and ensures consistency in the way tasks and utility mocks are handled across the codebase.
2025-06-24 22:07:31 +10:00
..
assertion-helpers.ts Refactor types and test mocks for improved consistency and clarity 2025-06-24 07:46:47 +10:00
integration-helpers.ts Refactor Types, Mocks, and Test Helpers for Improved Type Safety and Consistency 2025-06-24 22:07:31 +10:00
mock-factories.ts Refactor Types, Mocks, and Test Helpers for Improved Type Safety and Consistency 2025-06-24 22:07:31 +10:00