mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-03 13:09:47 +08:00
🐛 fix(connect): 修复首次启动数据库连接偶发失败
This commit is contained in:
26
frontend/src/utils/startupReadiness.test.ts
Normal file
26
frontend/src/utils/startupReadiness.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { getConnectionWorkbenchState } from './startupReadiness';
|
||||
|
||||
describe('startup readiness helpers', () => {
|
||||
it('blocks sidebar interactions before local store hydration completes', () => {
|
||||
expect(getConnectionWorkbenchState(false, false)).toEqual({
|
||||
ready: false,
|
||||
message: '正在加载本地配置...',
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps sidebar blocked until initial global proxy sync finishes', () => {
|
||||
expect(getConnectionWorkbenchState(true, false)).toEqual({
|
||||
ready: false,
|
||||
message: '正在同步全局代理配置...',
|
||||
});
|
||||
});
|
||||
|
||||
it('unblocks sidebar after startup configuration is fully applied', () => {
|
||||
expect(getConnectionWorkbenchState(true, true)).toEqual({
|
||||
ready: true,
|
||||
message: '',
|
||||
});
|
||||
});
|
||||
});
|
||||
26
frontend/src/utils/startupReadiness.ts
Normal file
26
frontend/src/utils/startupReadiness.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
export interface ConnectionWorkbenchState {
|
||||
ready: boolean;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export function getConnectionWorkbenchState(
|
||||
isStoreHydrated: boolean,
|
||||
hasAppliedInitialGlobalProxy: boolean
|
||||
): ConnectionWorkbenchState {
|
||||
if (!isStoreHydrated) {
|
||||
return {
|
||||
ready: false,
|
||||
message: '正在加载本地配置...',
|
||||
};
|
||||
}
|
||||
if (!hasAppliedInitialGlobalProxy) {
|
||||
return {
|
||||
ready: false,
|
||||
message: '正在同步全局代理配置...',
|
||||
};
|
||||
}
|
||||
return {
|
||||
ready: true,
|
||||
message: '',
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user