test: add frontend testing infrastructure with vitest

- Introduce Vitest + React Testing Library + jsdom environment
- Add useDragSort hook unit tests covering:
  * Sorting logic (sortIndex → createdAt → name)
  * Successful drag operation (API call + cache invalidation)
  * Failed drag operation (error toast display)
  * Edge case (no valid target, no API call)
- Configure global test setup (i18n mock, auto cleanup)
- Update TypeScript configs to include tests/ directory
- Add test development plan documentation

Test Coverage:
  ✓ Provider drag-and-drop sorting core logic
  ✓ React Query cache refresh
  ✓ Toast notification display
  ✓ Boundary condition handling

Test Results: 4/4 passed (671ms)
Next Steps: Sprint 2 - component tests with MSW mock layer
This commit is contained in:
Jason
2025-10-25 10:08:06 +08:00
parent 7325edff35
commit bbf830a1da
8 changed files with 1232 additions and 18 deletions

20
vitest.config.ts Normal file
View File

@@ -0,0 +1,20 @@
import path from "node:path";
import { defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
test: {
environment: "jsdom",
setupFiles: ["./tests/setupTests.ts"],
globals: true,
coverage: {
reporter: ["text", "lcov"],
},
},
});