fix: verify cloud image flow and clarify save feedback
This commit is contained in:
@@ -30,3 +30,46 @@ test('owner is visibly distinct from family and super administrators',()=>{
|
||||
assert.equal(c.label({id:'backup',role:'family_admin'}),'家庭管理员');
|
||||
assert.equal(c.label({id:'root',role:'admin'}),'超级管理员');
|
||||
});
|
||||
|
||||
function saveHarness({saveError,refreshError}={}){
|
||||
const events=[],error={textContent:''},elements=[{disabled:false},{disabled:true}];
|
||||
elements.id={value:'home'};elements.profileRevision={value:0};
|
||||
const form={elements,querySelector:()=>error,closest:()=>({close:()=>events.push('closed')})};
|
||||
let submit;
|
||||
const state={households:[{id:'home',name:'原档案'}]};
|
||||
const c=vm.createContext({coverSaving:false,coverDraft:'data:image/png;base64,test',sessionGeneration:1,
|
||||
$:()=>({addEventListener:(_type,fn)=>{submit=fn;}}),imageJobPending:()=>false,imageJobs:new Map(),
|
||||
formValues:()=>({id:'home',name:'已保存'}),state,
|
||||
api:async()=>{if(saveError)throw saveError;return {id:'home',name:'已保存',profileRevision:1,coverRevision:'new',coverRef:{fsId:'1'}};},
|
||||
renderHouseholds:()=>events.push('rendered'),toast:t=>events.push(t),
|
||||
refresh:async()=>{events.push('refresh');if(refreshError)throw refreshError;}});
|
||||
vm.runInContext(part(homes,"$('#household-form').addEventListener('submit'",'document.addEventListener'),c);
|
||||
return {run:()=>submit({preventDefault(){},currentTarget:form}),events,error,elements,state,c};
|
||||
}
|
||||
|
||||
test('saved cover stays committed and success is visible before a failed refresh',async()=>{
|
||||
const h=saveHarness({refreshError:Error('network')});await h.run();
|
||||
assert.equal(h.state.households[0].name,'已保存');assert.equal(h.elements.profileRevision.value,1);
|
||||
assert.match(h.state.households[0].coverUrl,/v=new/);
|
||||
assert.ok(h.events.indexOf('封面已存百度网盘,归属档案已保存')<h.events.indexOf('refresh'));
|
||||
assert.match(h.events.at(-1),/无需重复保存/);assert.ok(h.events.includes('closed'));
|
||||
assert.deepEqual(h.elements.map(e=>e.disabled),[false,true]);assert.equal(h.c.coverSaving,false);
|
||||
});
|
||||
|
||||
test('failed cover save keeps the draft open and does not claim success',async()=>{
|
||||
const h=saveHarness({saveError:Error('网盘暂时不可用')});await h.run();
|
||||
assert.equal(h.state.households[0].name,'原档案');assert.equal(h.error.textContent,'网盘暂时不可用');
|
||||
assert.deepEqual(h.events,[]);assert.equal(h.c.coverDraft,'data:image/png;base64,test');
|
||||
});
|
||||
|
||||
test('a stale post-save refresh does not show a new-session warning',async()=>{
|
||||
const h=saveHarness({refreshError:Object.assign(Error('stale'),{stale:true})});await h.run();
|
||||
assert.equal(h.events.at(-1),'refresh');assert.equal(h.state.households[0].name,'已保存');
|
||||
});
|
||||
|
||||
test('storage guide names cloud categories and avoids old all-local claims',()=>{
|
||||
const html=fs.readFileSync('web/index.html','utf8');
|
||||
assert.ok(html.includes('id="baidu-storage-guide"'));
|
||||
for(const label of ['家庭与场所:','平台外观:','个人记事:','数据库备份:'])assert.ok(html.includes(label));
|
||||
assert.ok(!html.includes('自有部署 · 本地存储'));assert.ok(!app.includes('数据存于本机'));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user