Add unit tests for autoSaveService to handle document dirty states and periodic saves

- Implement tests for various scenarios including user edits, initial dirty state, and document changes.
- Ensure proper flagging of uncommitted changes and silent saves for documents opened in a dirty state.
- Test debounce behavior for document change notifications and version clearing functionality.
- Validate suspension and resumption of auto-saving during versioning processes.
This commit is contained in:
Suphonchai Phoonsawat 2026-11-03 13:34:21 +07:00
parent 0b6ee8cc84
commit 454c90d17e
17 changed files with 1167 additions and 33 deletions

View file

@ -59,30 +59,23 @@ MINIO_SECRET_KEY=minioadmin
(เทียบกับ `.env.example`)
### 4. สร้างตารางในฐานข้อมูล
```bash
npx drizzle-kit push
```
### 5. Seed ไฟล์ตัวอย่าง
ไฟล์ตัวอย่างอยู่ที่ `public/note/samples/` แล้ว — sync ลงตาราง `files` (idempotent รันซ้ำได้) — รองรับทั้ง `.pdf` และรูปภาพ `.jpg/.jpeg/.png/.tif/.tiff` (N3):
```bash
npm run seed-samples
```
> บน production ไม่ต้องรันมือ — script เดียวกัน (`scripts/seed-samples.mjs`) รันอัตโนมัติตอน container start ต่อจาก migration ไฟล์ที่หายจาก `public/note/samples/` จะถูกลบ row พร้อม annotation ที่ผูกอยู่ (CASCADE)
### 6. รัน dev server
### 4. รัน dev server — สร้างตาราง + seed ให้เองอัตโนมัติ
```bash
npm run dev
```
คำสั่งเดียวจบ (ทุกขั้น idempotent รันซ้ำได้): `docker compose up -d --wait` (สตาร์ท container ให้ถ้ายังไม่รัน รอ healthy) → `scripts/migrate.mjs` (สร้าง database ถ้ายังไม่มี + apply ไฟล์ `drizzle/*.sql` ที่ยังไม่ได้ apply — ชุดเดียวกับที่ production ใช้ตอน container start) → `scripts/seed-samples.mjs` (sync ไฟล์ตัวอย่างจาก `public/note/samples/` ลงตาราง `files` — รองรับ `.pdf` และรูปภาพ `.jpg/.jpeg/.png/.tif/.tiff`; ไฟล์ที่หายจาก disk จะถูกลบ row พร้อม annotation ที่ผูกอยู่ CASCADE) → `next dev`
เปิด http://localhost:3000/docedit/note — คลิกไฟล์เพื่อเข้าหน้า annotate หรืออัปโหลดไฟล์ใหม่ (PDF/รูปภาพ ≤ 100MB) ผ่านฟอร์มบนหน้ารายการ (N4 — ไฟล์เก็บที่ `public/note/uploads/`)
**คำสั่งเสริม**
- `npm run dev:server` — รันแค่ `next dev` ไม่แตะ DB/container (ใช้เมื่อแก้โค้ดล้วน ๆ ไม่อยากรอ migrate)
- `npm run db:prepare` — เตรียม DB เท่านั้น (compose up + migrate + seed) ไม่รัน dev server
- `npm run db:reset` — **ล้างข้อมูลเริ่มใหม่ทั้งหมด**: ลบ volume PostgreSQL + MinIO ของโปรเจกต์ แล้วสร้างใหม่ + migrate + seed (ข้อมูลหายถาวร — ระวัง)
- แก้ `db/schema.ts` → รัน `npx drizzle-kit generate` สร้างไฟล์ SQL ใหม่ใน `drizzle/` แล้วรัน `npm run dev` อีกครั้งเพื่อ apply — **เลี่ยง `drizzle-kit push` ตรง ๆ** เพราะ production apply จากไฟล์ใน `drizzle/` เท่านั้น ถ้า dev push เดินนำไฟล์ migration สองฝั่งจะเพี้ยนกัน
## การใช้งานบนหน้า annotate
| ปุ่ม | พฤติกรรม |