Skip to content

Add comprehensive tests for cleanup store - #8

Merged
k8ika0s merged 1 commit into
mainfrom
feature/cleanup-component-tests
Jan 19, 2026
Merged

Add comprehensive tests for cleanup store#8
k8ika0s merged 1 commit into
mainfrom
feature/cleanup-component-tests

Conversation

@k8ika0s

@k8ika0s k8ika0s commented Jan 19, 2026

Copy link
Copy Markdown
Owner

Summary

Adds comprehensive unit tests for the cleanupStore, significantly improving code coverage and test quality for the storage cleanup feature.

Changes Made

1. New Test File

  • File: frontend/src/store/cleanupStore.test.ts (598 lines)
    • 26 comprehensive unit tests covering all store functionality
    • Tests organized by feature area with clear descriptions
    • Proper mocking of API calls and async operations
    • State reset between tests for isolation

2. Test Coverage by Category

Initial State (4 tests)

  • Validates default state values
  • Ensures proper initialization of all state properties

Scan Operations (6 tests)

  • scanOrphanedUploads: Success, error, and loading states
  • scanCorruptObjects: Full scan workflow
  • scanOrphanedVersions: Version scanning
  • scanEmptyObjects: Empty object detection

Cleanup Operations (2 tests)

  • cleanupOrphanedUploads: Cleanup execution
  • cleanupOldVersions: Version cleanup with retention

Job Management (7 tests)

  • loadJobs: Success, error, and empty states
  • getJobStatus: Status retrieval
  • cancelJob: Job cancellation
  • refreshActiveJob: Active job updates with polling

Analytics & Diagnostics (3 tests)

  • loadAnalytics: Storage analytics loading
  • loadDiagnostics: System diagnostics retrieval

Utility Actions (4 tests)

  • clearScanResults: Result clearing
  • clearJobs: Job list clearing
  • resetState: Complete state reset
  • setActiveTab: Tab navigation

3. Configuration Updates

  • File: frontend/vitest.config.ts
    • Removed cleanupStore.ts from coverage exclusions
    • Store now included in coverage calculations

Coverage Improvements

Before

  • cleanupStore.ts: 0% coverage (excluded)

After

  • cleanupStore.ts: 84.5% statements, 70.21% branches, 100% functions
  • All 26 tests passing
  • Uncovered lines are primarily error handling edge cases

Overall Project Coverage

  • Statements: 87.9% (exceeds 85% threshold)
  • Functions: 75.28% (meets 75% threshold)
  • All tests: 1,422 passing

Testing Performed

  • ✅ All 26 new tests passing
  • ✅ Full test suite passing (1,422 tests)
  • ✅ Coverage thresholds met
  • ✅ No regressions in existing tests
  • ✅ Proper async operation handling
  • ✅ Mock cleanup between tests

Test Patterns Used

Mock Setup

vi.mock('../lib/api', () => ({
  api: {
    cleanup: {
      scanOrphanedUploads: vi.fn(),
      // ... other methods
    },
  },
}));

State Reset

beforeEach(() => {
  useCleanupStore.setState({
    scanResults: { /* initial state */ },
    // ... other state
  });
  vi.clearAllMocks();
});

Async Testing

it('should handle async operations', async () => {
  vi.mocked(api.cleanup.method).mockResolvedValue(data);
  await action();
  expect(state.result).toEqual(expected);
});

Breaking Changes

None - this is purely additive testing.

Dependencies

No new dependencies added.

Checklist

  • Code follows project style guidelines
  • Tests added and passing (26 new tests)
  • Coverage improved significantly
  • No breaking changes
  • Commit messages follow convention
  • Branch is up to date with main

Related Issues

Part of cleanup component testing initiative (follow-up to PR #7).

Next Steps

After this PR is merged, the next phase will add tests for:

  1. CleanupDashboard component
  2. ScanResults component
  3. JobMonitor component
  4. StorageAnalytics component

Deployment Notes

No deployment changes required - testing only.

Add 26 unit tests for cleanupStore covering all functionality:
- Initial state validation
- Scan operations (orphaned uploads, corrupt objects, versions, empty objects)
- Cleanup operations (orphaned uploads, old versions)
- Job management (load, status, cancel, refresh)
- Analytics and diagnostics loading
- Utility actions (clear results, reset state)

Coverage improvements:
- cleanupStore: 84.5% statements, 100% functions
- All 26 tests passing
- Removed cleanupStore from coverage exclusions

Part of cleanup component testing initiative.
@k8ika0s
k8ika0s merged commit 36b8d32 into main Jan 19, 2026
7 checks passed
@k8ika0s
k8ika0s deleted the feature/cleanup-component-tests branch January 19, 2026 20:33
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