feat: import Sea vHost single-server testing release

This commit is contained in:
canglan committed 2026-10-30 08:39:10 +08:00
commit 248badd33e
441 files changed
+63221

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
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 WebsiteSettings} from './api';
import {SiteTools} from './components/SiteTools';
import type {Site} from './types';
afterEach(()=>{cleanup();vi.restoreAllMocks()});
const site:Site={id:9,projectId:3,name:'php',runPath:'/public',domain:'site.vhost.ser888.cn',runtime:'PHP',version:'8.4',status:'running',sslStatus:'active',autoSSL:true,processLimit:10,primary:true,createdAt:''};
const settings:WebsiteSettings={rewrite:'wordpress',redirectURL:'',redirectCode:301,forceHTTPS:true,index:['index.php'],error404:'404.html',error503:'',maintenance:false};
it('blocks default settings after a failed read and saves the recovered configuration',async()=>{
vi.spyOn(api,'websiteSettings').mockRejectedValueOnce(new Error('网站设置读取失败')).mockResolvedValue({settings});
const save=vi.spyOn(api,'saveWebsiteSettings').mockResolvedValue(undefined);
render(<SiteTools site={site} projectId={3} live onClose={()=>undefined}/>);
expect(await screen.findByRole('alert')).toHaveTextContent('网站设置读取失败');
expect(screen.getByRole('button',{name:'保存网站设置'})).toBeDisabled();expect(save).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole('button',{name:'重新读取设置'}));
await waitFor(()=>expect(screen.getByLabelText('默认首页(逗号分隔)')).toBeEnabled());
expect(screen.getByLabelText('强制 HTTPS(需有效证书)')).toBeChecked();
fireEvent.click(screen.getByRole('button',{name:'保存网站设置'}));
await waitFor(()=>expect(save).toHaveBeenCalledWith(3,9,settings));
});
it('renders separate log lines and prevents exporting stale lines after a read error',async()=>{
vi.spyOn(api,'websiteSettings').mockResolvedValue({settings});
vi.spyOn(api,'siteLog').mockResolvedValueOnce({lines:['first log line','second log line'],available:true}).mockRejectedValue(new Error('日志读取失败'));
render(<SiteTools site={site} projectId={3} live onClose={()=>undefined}/>);
fireEvent.click(screen.getByRole('button',{name:'网站日志'}));
await waitFor(()=>expect(document.querySelector('.site-log-view')?.textContent).toBe('first log line\nsecond log line'));
fireEvent.change(screen.getByLabelText('日志类型'),{target:{value:'access'}});
expect(await screen.findByRole('alert')).toHaveTextContent('日志读取失败');
expect(screen.queryByText('first log line',{exact:false})).not.toBeInTheDocument();
expect(screen.getByRole('button',{name:'下载日志 JSON'})).toBeDisabled();
});