统一全系统资源加载、轻量趋势与缓存恢复
This commit is contained in:
@@ -17,10 +17,11 @@ function policyFixture(api, validate) {
|
||||
const actions=panel.slice(panel.indexOf(' const save ='),panel.indexOf(' const scopeCounts'));
|
||||
return new Function('api','validate',transpile(`
|
||||
let userId,policy=null,effective=null,scopePreview=null,previewBusy=false,loading=false,saving=false,error='',fields={};
|
||||
const active=true,policyRequest={current:null},policyRead={run:async work=>{loading=true;try{return await work();}finally{loading=false;}}};
|
||||
const selectedUser={current:undefined},policyGeneration={current:0},savingRef={current:false},mounted={current:true};
|
||||
const obj=v=>v,text=(v,f)=>v??f,onUnauthorized=()=>false,message={success(){},error(){}};
|
||||
const useCallback=fn=>fn,obj=v=>v,text=(v,f)=>v??f,onUnauthorized=()=>false,message={success(){},error(){}};
|
||||
class ApiError extends Error{}
|
||||
const form={resetFields(){fields={};},setFieldsValue(v){fields={...fields,...v};},async validateFields(){return validate?validate():{...fields,reason:'fixture reason'};}};
|
||||
const form={isFieldsTouched:()=>false,resetFields(){fields={};},setFieldsValue(v){fields={...fields,...v};},async validateFields(){return validate?validate():{...fields,reason:'fixture reason'};}};
|
||||
const setUserId=v=>userId=v,setPolicy=v=>policy=v,setEffective=v=>effective=v,setScopePreview=v=>scopePreview=v,
|
||||
setPreviewBusy=v=>previewBusy=v,setLoading=v=>loading=v,setSaving=v=>saving=v,setError=v=>error=v;
|
||||
${selection}${load}${actions}
|
||||
@@ -104,7 +105,9 @@ function drawerFixture() {
|
||||
const requests=[],exports=[];let downloaded=0,refreshKey=0;
|
||||
const props={open:true,row:null,stage:'black',onStage(){},onClose(){},query:freezeSourceRecordsQuery(baseQuery,'release-A','overall',null),onUnauthorized:()=>false};
|
||||
const renderer=hookRenderer(hooks=>new Function('React','hooks','api',transpile(`
|
||||
const {useState,useRef,useMemo,useEffect}=hooks;const usePageCache=()=>({refreshKey:api.refreshKey()});const TABLE_PAGE_SIZE=20,MONTHS=Array.from({length:12},(_,i)=>i+1+'月');
|
||||
const {useState,useRef,useMemo,useEffect}=hooks;const useLayoutEffect=useEffect;const usePageCache=()=>({active:true,refreshKey:api.refreshKey()});
|
||||
const useDelayedIndicator=value=>value;
|
||||
${read('QueryResultMotion.tsx').slice(read('QueryResultMotion.tsx').indexOf('export function useRetainedResult'),read('QueryResultMotion.tsx').indexOf('function numericText')).replace('export function','function')}const TABLE_PAGE_SIZE=20,MONTHS=Array.from({length:12},(_,i)=>i+1+'月');
|
||||
const Drawer='Drawer',Segmented='Segmented',Select='Select',Button='Button',Alert='Alert',Spin='Spin',Table='Table',Pagination='Pagination',SearchOutlined='SearchOutlined',DownloadOutlined='DownloadOutlined';
|
||||
const Input='Input',readableSelectPopup={},Empty=Object.assign(()=>null,{PRESENTED_IMAGE_SIMPLE:'empty'}),App={useApp:()=>({message:{success(){},error(){}}})};
|
||||
const isSystemVersionField=()=>false,chooseError=e=>e.message,withoutSystemVersionFields=v=>v;
|
||||
@@ -115,11 +118,11 @@ function drawerFixture() {
|
||||
return {requests,exports,props,render:()=>renderer.render(props),unmount:()=>renderer.unmount(),invalidate(){refreshKey++;},get downloaded(){return downloaded;}};
|
||||
}
|
||||
|
||||
test('actual drawer clears prior rows during page load/failure and offers retry on the same frozen release',async()=>{
|
||||
test('actual drawer retains prior rows without enabling stale actions and retries the same frozen release',async()=>{
|
||||
const ui=drawerFixture();ui.render();assert.equal(ui.requests[0].params.page,1);assert.equal(ui.requests[0].params.releaseId,'release-A');
|
||||
ui.requests[0].resolve({rows:[{id:'A-1',raw:{field:'value'}}],total:45,pageSize:20,page:1});await tick();let tree=ui.render();
|
||||
assert.equal(find(tree,n=>n.type==='Table').props.dataSource[0].id,'A-1');find(tree,n=>n.type==='Pagination').props.onChange(2);tree=ui.render();
|
||||
assert.equal(find(tree,n=>n.type==='Table'),undefined);ui.requests[1].reject(Error('page failed'));await tick();tree=ui.render();assert.equal(find(tree,n=>n.type==='Table'),undefined);
|
||||
assert.equal(find(tree,n=>n.type==='Table').props.dataSource[0].id,'A-1');assert.equal(find(tree,n=>n.props?.['aria-busy']===true).props.inert,true);ui.requests[1].reject(Error('page failed'));await tick();tree=ui.render();assert.equal(find(tree,n=>n.type==='Table').props.dataSource[0].id,'A-1');assert.equal(find(tree,n=>n.type==='Button'&&textOf(n)==='导出明细 Excel').props.disabled,true);
|
||||
const alert=find(tree,n=>n.type==='Alert');assert.equal(alert.props.description,'page failed');alert.props.action.props.onClick();ui.render();
|
||||
assert.equal(ui.requests[2].params.page,2);assert.equal(ui.requests[2].params.releaseId,'release-A');ui.unmount();assert.equal(ui.requests[2].signal.aborted,true);
|
||||
});
|
||||
@@ -143,11 +146,12 @@ test('closing and reopening a different month remounts page/search state and ign
|
||||
test('reopening the same frozen drawer reuses its page until the workspace revision changes',async()=>{
|
||||
const ui=drawerFixture();ui.render();ui.requests[0].resolve({rows:[{id:'cached'}],total:1,pageSize:20,page:1});await tick();ui.render();
|
||||
ui.props.open=false;ui.render();ui.props.open=true;let tree=ui.render();assert.equal(ui.requests.length,1);assert.equal(find(tree,n=>n.type==='Table').props.dataSource[0].id,'cached');
|
||||
ui.invalidate();tree=ui.render();assert.equal(ui.requests.length,2);assert.equal(find(tree,n=>n.type==='Table'),undefined);ui.unmount();
|
||||
ui.invalidate();tree=ui.render();assert.equal(ui.requests.length,2);assert.equal(find(tree,n=>n.type==='Table').props.dataSource[0].id,'cached');assert.equal(find(tree,n=>n.props?.['aria-busy']===true).props.inert,true);ui.unmount();
|
||||
});
|
||||
|
||||
test('export from the actual drawer keeps the clicked release even after current publication changes',async()=>{
|
||||
const ui=drawerFixture();ui.render();const tree=ui.render();
|
||||
const ui=drawerFixture();ui.render();ui.requests[0].resolve({rows:[{id:'export-ready'}],total:1,pageSize:20,page:1});await tick();const tree=ui.render();
|
||||
assert.equal(find(tree,n=>n.type==='Button'&&textOf(n)==='导出明细 Excel').props.disabled,false);
|
||||
await find(tree,n=>n.type==='Button'&&textOf(n)==='导出明细 Excel').props.onClick();
|
||||
assert.equal(ui.exports[0].params.releaseId,'release-A');assert.equal(ui.exports[0].params.month,1);assert.equal(ui.downloaded,1);ui.unmount();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user