From eba3a1b562a1c04249f6cb6e6ce8202f2562ad20 Mon Sep 17 00:00:00 2001 From: ouyangxq <775153912@qq.com> Date: Fri, 30 Oct 2026 15:40:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8D=89=E7=A8=BF=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E5=A4=B1=E8=B4=A5=E6=8F=90=E9=86=92=E8=A2=AB=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E7=8A=B6=E6=80=81=E9=81=AE=E6=8C=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/js/chat.js | 3 ++- tests/frontend/chat.test.cjs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/static/js/chat.js b/static/js/chat.js index 41d511e..7b72c7d 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -13,7 +13,8 @@ function flushDraft(){ if(draftTimer !== null){ clearTimeout(draftTimer); draftTimer = null; } const saved = drafts.write(currentConvId, inputDom.value); drafts.active(currentConvId); - if(!saved && inputDom.value && !composerStatus.textContent) setComposerStatus(t('draftSaveFailed'), true); + if(!saved && inputDom.value && !composerStatus.classList.contains('is-error')) setComposerStatus(t('draftSaveFailed'), true); + else if(saved && composerStatus.textContent === t('draftSaveFailed')) setComposerStatus(''); } function restoreDraft(){ inputDom.value = drafts.read(currentConvId); diff --git a/tests/frontend/chat.test.cjs b/tests/frontend/chat.test.cjs index 3fa32c2..8a062d4 100644 --- a/tests/frontend/chat.test.cjs +++ b/tests/frontend/chat.test.cjs @@ -926,6 +926,21 @@ test('a new conversation draft restores after refresh and moves to the created c assert.equal(store.read(null),'');assert.equal(store.read(1),'');assert.equal(store.active(),'1'); }); +test('quota failure replaces a restored-draft notice and clears after storage recovers', async () => { + const history=[{id:9,title:'A',ctime:'now'}],app=await customerPage({human:false,history}); + await app.click(app.element('historyWrap').children[0]); + app.element('input-text').value='已保存草稿';app.element('input-text').listeners.input();await app.pageHide(); + const restored=await customerPage({human:false,history,storage:app.storage,tabStorage:app.tabStorage}); + assert.match(restored.element('composer-status').textContent,/已恢复/); + const setItem=restored.context.localStorage.setItem; + restored.context.localStorage.setItem=()=>{throw Error('quota');}; + restored.element('input-text').value='新的未保存输入';restored.element('input-text').listeners.input();await restored.runTimers(250); + assert.match(restored.element('composer-status').textContent,/无法保存/); + assert.equal(restored.element('input-text').value,'新的未保存输入'); + restored.context.localStorage.setItem=setItem;await restored.pageHide(); + assert.equal(restored.element('composer-status').textContent,''); +}); + test('restoring an old conversation cannot replace a newer user-selected draft', async () => { const app=await customerPage({human:false,history:[{id:9,title:'A',ctime:'now'}]}); await app.click(app.element('historyWrap').children[0]);