fix: use panel Python common catalog and track install jobs
This commit is contained in:
1 parent
248badd33e
commit
d7c007adc4
12 files changed
+202
-22
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import '@testing-library/jest-dom/vitest';
|
||||
import {cleanup,fireEvent,render,screen,waitFor} from '@testing-library/react';
|
||||
import {afterEach,expect,it,vi} from 'vitest';
|
||||
import {api,type RuntimeEnvironment} from './api';
|
||||
import {EnvironmentConfiguration} from './components/EnvironmentConfiguration';
|
||||
|
||||
vi.mock('./components/RuntimeMaintenancePanel',()=>({RuntimeMaintenancePanel:()=>null}));
|
||||
afterEach(()=>{cleanup();vi.restoreAllMocks()});
|
||||
|
||||
it('correlates the selected Python version with its actual Sea vHost task',async()=>{
|
||||
const python:RuntimeEnvironment={name:'Python',componentTitle:'Python 项目管理器',componentStatus:'installed',componentInstallable:false,installed:[],available:['3.14.9','3.13.17'],installing:[],recommended:'3.14.9'};
|
||||
vi.spyOn(api,'runtimeEnvironments').mockResolvedValue({environments:[python]});
|
||||
const install=vi.spyOn(api,'installRuntimeEnvironment').mockResolvedValue({ok:true,jobId:38});
|
||||
render(<EnvironmentConfiguration nodeId={1}/>);
|
||||
expect(await screen.findByRole('combobox',{name:'Python 待安装版本'})).toHaveValue('3.14.9');
|
||||
fireEvent.click(screen.getByRole('button',{name:'安装版本'}));
|
||||
expect(screen.getByRole('alertdialog')).toHaveTextContent('Python 3.14.9');
|
||||
fireEvent.click(screen.getByRole('button',{name:'确认继续'}));
|
||||
await waitFor(()=>expect(install).toHaveBeenCalledWith('Python','3.14.9',1));
|
||||
expect(await screen.findByText(/Python 3.14.9 已提交 Sea vHost 任务 #38/)).toBeInTheDocument();
|
||||
});
|
||||
@@ -14,6 +14,24 @@ it('opens real host configuration controls with administrator-assigned limits',(
|
||||
fireEvent.click(screen.getByRole('button',{name:'设置运行目录'}));expect(onRunPath).toHaveBeenCalledWith(initialProjects[0]);
|
||||
fireEvent.click(screen.getByRole('button',{name:'网站管理'}));expect(onSites).toHaveBeenCalledWith(initialProjects[0]);
|
||||
});
|
||||
it('switches all host management actions to the selected host',()=>{
|
||||
const onSites=vi.fn(),onFiles=vi.fn(),onCredentials=vi.fn(),onRunPath=vi.fn(),onToggle=vi.fn();
|
||||
render(<HostDetails projects={initialProjects} plan={demoPlan} usage={demoUsage} live={false} onSites={onSites} onFiles={onFiles} onCredentials={onCredentials} onRunPath={onRunPath} onToggle={onToggle}/>);
|
||||
const target=initialProjects[1];
|
||||
fireEvent.change(screen.getByRole('combobox',{name:'选择虚拟主机'}),{target:{value:String(target.id)}});
|
||||
expect(screen.getByRole('heading',{name:target.hostName})).toBeInTheDocument();
|
||||
expect(screen.getByRole('link',{name:target.domain})).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button',{name:'网站管理'}));expect(onSites).toHaveBeenCalledWith(target);
|
||||
fireEvent.click(screen.getByRole('button',{name:'设置运行目录'}));expect(onRunPath).toHaveBeenCalledWith(target);
|
||||
fireEvent.click(screen.getByRole('button',{name:'文件管理'}));expect(onFiles).toHaveBeenCalledWith(target.id);
|
||||
fireEvent.click(screen.getByRole('button',{name:'访问凭据'}));expect(onCredentials).toHaveBeenCalledWith(target);
|
||||
fireEvent.click(screen.getByRole('button',{name:'停止主站'}));expect(onToggle).toHaveBeenCalledWith(target.id);
|
||||
});
|
||||
it('does not show a host switcher for a single-host login',()=>{
|
||||
render(<HostDetails projects={initialProjects.slice(0,1)} plan={demoPlan} usage={demoUsage} live={false} hostScoped onSites={vi.fn()} onFiles={vi.fn()} onCredentials={vi.fn()} onRunPath={vi.fn()}/>);
|
||||
expect(screen.queryByRole('combobox',{name:'选择虚拟主机'})).not.toBeInTheDocument();
|
||||
expect(screen.getByRole('heading',{name:initialProjects[0].hostName})).toBeInTheDocument();
|
||||
});
|
||||
it('loads and refreshes logs scoped to the signed-in host',async()=>{
|
||||
const load=vi.spyOn(api,'activities').mockResolvedValue({activities:[{id:91,projectId:initialProjects[0].id,actor:'用户',action:'update',resourceType:'run_path',detail:'用户更新当前主机目录',success:true,createdAt:'2026-10-26T00:00:00Z'}]});
|
||||
render(<ResourceCenter page="logs" projects={initialProjects.slice(0,1)} activities={[]} hostScoped live domainApproval onCredentials={vi.fn()} onNotify={vi.fn()}/>);
|
||||
|
||||
+1
-1
@@ -235,7 +235,7 @@ export const api = {
|
||||
migrateSiteRuntime: (siteID: number, version: string, allowBranchChange = false, entryFile = '') => request<{ jobId: number }>(`/api/v1/admin/runtime-maintenance/sites/${siteID}`, { method: 'POST', body: JSON.stringify({ version, allowBranchChange, entryFile }) }),
|
||||
resumeRuntimeMaintenance: (id: number,nodeId?:number) => request<{ ok: boolean }>(`/api/v1/admin/runtime-maintenance/jobs/${id}/resume`+nodeQuery(nodeId), { method: 'POST' }),
|
||||
installRuntimeComponent: (runtime: string,nodeId?:number) => request<{ ok: boolean }>(`/api/v1/admin/runtime-components/${encodeURIComponent(runtime)}/install`+nodeQuery(nodeId), { method: 'POST' }),
|
||||
installRuntimeEnvironment: (runtime: string, version: string,nodeId?:number) => request<{ ok: boolean }>(`/api/v1/admin/runtime-environments/${encodeURIComponent(runtime)}/install`+nodeQuery(nodeId), { method: 'POST', body: JSON.stringify({ version }) }),
|
||||
installRuntimeEnvironment: (runtime: string, version: string,nodeId?:number) => request<{ ok: boolean; jobId?:number }>(`/api/v1/admin/runtime-environments/${encodeURIComponent(runtime)}/install`+nodeQuery(nodeId), { method: 'POST', body: JSON.stringify({ version }) }),
|
||||
adoptPanelSite: (id: number, input: { tenantId: number; name: string; runtime: string; version: string; runPath: string; autoSSL: boolean;planId:number },nodeId?:number) => request<{ project: APIProject; credentials: Credentials }>(`/api/v1/admin/panel-sites/${id}/adopt`+nodeQuery(nodeId), { method: 'POST', body: JSON.stringify(input) }),
|
||||
updateDomainMetadata: (id: number, input: Record<string, unknown>) => request<void>(`/api/v1/admin/domains/${id}/metadata`, { method: 'PUT', body: JSON.stringify(input) }),
|
||||
provisionDomainDNS: (id: number, admin = false) => request<{ domain: DomainResource }>(`${admin ? '/api/v1/admin' : '/api/v1'}/domains/${id}/dns`, { method: 'POST' }),
|
||||
|
||||
@@ -66,8 +66,8 @@ export function EnvironmentConfiguration({nodeId,nodeSelector,hideHeading=false,
|
||||
if (!version || !await confirm(`安装 ${item.name} ${version}?现有项目和已安装版本不会被删除。${sourceNotice}`)) return;
|
||||
setBusy(`${item.name}:${version}`); setError(''); setNotice('');
|
||||
try {
|
||||
await api.installRuntimeEnvironment(item.name, version,nodeId);
|
||||
setNotice(`${item.name} ${version} 安装任务已提交。`);
|
||||
const result=await api.installRuntimeEnvironment(item.name, version,nodeId);
|
||||
setNotice(`${item.name} ${version} 已提交 Sea vHost 任务${result.jobId?` #${result.jobId}`:''},请在下方维护任务记录查看结果。`);
|
||||
await load();
|
||||
} catch (installError) { setError(safeError(installError)); }
|
||||
finally { setBusy(''); }
|
||||
|
||||
Reference in new issue
Block a user