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:
parent
0b6ee8cc84
commit
454c90d17e
17 changed files with 1167 additions and 33 deletions
|
|
@ -136,7 +136,9 @@ const TaskpaneApp: React.FC<{ demo?: "untracked" | "tracking" }> = ({ demo }) =>
|
|||
const [saveError, setSaveError] = useState<string | null>(null);
|
||||
/** FR-17 — banner เตือนเมื่อ auto-save ล้ม (ไม่บล็อก แต่ไม่ปล่อยเงียบ) */
|
||||
const [autoSaveError, setAutoSaveError] = useState<string | null>(null);
|
||||
/** FR-3 — periodic tick เห็นการแก้ไขหลัง version ล่าสุด (แสดงเฉพาะตอน tracking) */
|
||||
/** FR-3 — เห็นการแก้ไขจริงหลัง version ล่าสุด: clean→dirty ของ periodic tick หรือ
|
||||
* notifyDocumentChanged ของ service ที่แก้เอกสาร (แสดงเฉพาะตอน tracking — ไฟล์ที่เปิดมา
|
||||
* dirty ตั้งแต่แรกไม่นับ เก็บไว้ที่ autoSaveService) */
|
||||
const [hasUncommitted, setHasUncommitted] = useState(false);
|
||||
|
||||
/** AuthRequiredError (ticket หมดอายุ/token ขอไม่ได้ หลัง renew-retry ของ apiClient)
|
||||
|
|
@ -227,7 +229,8 @@ const TaskpaneApp: React.FC<{ demo?: "untracked" | "tracking" }> = ({ demo }) =>
|
|||
}, [demo, detect]);
|
||||
|
||||
/** FR-17 — เริ่ม auto-save ตั้งแต่ mount ไม่ผูกกับ phase (ข้ามใน demo กัน error banner จาก Word ที่ไม่มี)
|
||||
* ผูก listener ให้ React state: error → banner, dirty→save → flag FR-3 */
|
||||
* ผูก listener ให้ React state: error → banner, แก้ไขจริง (clean→dirty / notifyDocumentChanged)
|
||||
* → flag FR-3 */
|
||||
useEffect(() => {
|
||||
autoSaveService.onError = (error) =>
|
||||
setAutoSaveError(getErrorMessage(error, "บันทึกอัตโนมัติไม่สำเร็จ — ลองกด \"บันทึก\" ด้วยตนเอง"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue