feat(web): localize and redesign operations console

This commit is contained in:
chick
2026-07-18 22:22:41 +08:00
parent d575ab4d9d
commit abfd07f8a3
34 changed files with 1536 additions and 1058 deletions
+43 -20
View File
@@ -21,7 +21,7 @@ const owner: InstanceContext = {
authentication: 'authenticated',
freshness: 'fresh',
};
const overviewCapability: InstanceCapabilityMap = {
const overviewCapabilities: InstanceCapabilityMap = {
overview: { state: 'supported' },
};
const snapshot: OverviewSnapshot = {
@@ -61,26 +61,51 @@ describe('Phase 6.1 Overview / System read slice', () => {
<AppShell
pathname="/instances/alpha/overview"
instance={owner}
capabilities={overviewCapability}
capabilities={overviewCapabilities}
overviewDataSource={pending.source}
/>,
);
expect(screen.getByRole('status', { name: 'Overview loading status' }).textContent).toContain(
'Loading overview',
expect(screen.getByRole('status', { name: '概览加载状态' }).textContent).toContain(
'正在加载概览',
);
expect(pending.load).toHaveBeenCalledWith('alpha', expect.any(AbortSignal));
pending.resolve(snapshot);
for (const heading of ['Device', 'SIM', 'Network', 'Statistics', 'CPU', 'Connectivity']) {
for (const heading of ['设备', 'SIM', '网络', '统计', 'CPU', '连接状态']) {
expect(await screen.findByRole('heading', { name: heading })).toBeTruthy();
}
expect(
within(screen.getByRole('region', { name: 'Device' })).getByText('SIMBox 8'),
).toBeTruthy();
expect(screen.getByText(/Observed 2026-07-17T10:00:00Z/)).toBeTruthy();
expect(within(screen.getByRole('region', { name: '设备' })).getByText('SIMBox 8')).toBeTruthy();
expect(screen.getByText(/观测时间:2026-07-17T10:00:00Z/)).toBeTruthy();
expect(screen.queryByRole('button', { name: /restart/i })).toBeNull();
expect(screen.getByText(/Restart is unavailable.*R3/i)).toBeTruthy();
expect(screen.getByText(/重启不可用.*R3/i)).toBeTruthy();
});
it('translates only known field names and values while preserving unknown safe data', async () => {
render(
<OverviewSystemPage
instance={owner}
dataSource={{
load: async () => ({
...snapshot,
device: { Model: 'SIMBox 8', Enabled: true, Mystery: 'vendor-value' },
network: { Registration: 'registered' },
connectivity: { State: 'connected' },
}),
}}
/>,
);
const device = await screen.findByRole('region', { name: '设备' });
expect(within(device).getByText('型号')).toBeTruthy();
expect(within(device).getByText('Enabled')).toBeTruthy();
expect(within(device).getByText('是')).toBeTruthy();
expect(within(device).getByText('Mystery')).toBeTruthy();
expect(within(device).getByText('vendor-value')).toBeTruthy();
expect(within(screen.getByRole('region', { name: '网络' })).getByText('已注册')).toBeTruthy();
expect(
within(screen.getByRole('region', { name: '连接状态' })).getByText('已连接'),
).toBeTruthy();
});
it('is honest when no safe read source is injected and never attempts a production endpoint', () => {
@@ -88,11 +113,11 @@ describe('Phase 6.1 Overview / System read slice', () => {
<AppShell
pathname="/instances/alpha/overview"
instance={owner}
capabilities={overviewCapability}
capabilities={overviewCapabilities}
/>,
);
expect(screen.getByRole('status', { name: 'Overview unavailable' }).textContent).toMatch(
/no safe overview read data source/i,
expect(screen.getByRole('status', { name: '概览不可用' }).textContent).toMatch(
/没有可用的安全概览只读数据源/i,
);
expect(screen.queryByRole('button', { name: /restart/i })).toBeNull();
});
@@ -114,7 +139,7 @@ describe('Phase 6.1 Overview / System read slice', () => {
dataSource={{ load }}
/>,
);
expect(screen.getByRole('alert').textContent).toMatch(/authentication is required/i);
expect(screen.getByRole('alert').textContent).toMatch(/需要先完成认证/i);
expect(screen.queryByText('SIMBox 8')).toBeNull();
expect(load).toHaveBeenCalledTimes(1);
});
@@ -126,8 +151,8 @@ describe('Phase 6.1 Overview / System read slice', () => {
dataSource={{ load: async () => snapshot }}
/>,
);
expect((await screen.findByRole('status', { name: 'Overview freshness' })).textContent).toMatch(
/stale/i,
expect((await screen.findByRole('status', { name: '概览数据新鲜度' })).textContent).toMatch(
/可能已过期/i,
);
expect(screen.getByText('SIMBox 8')).toBeTruthy();
});
@@ -140,10 +165,8 @@ describe('Phase 6.1 Overview / System read slice', () => {
.mockResolvedValueOnce(snapshot);
render(<OverviewSystemPage instance={owner} dataSource={{ load }} />);
expect((await screen.findByRole('alert')).textContent).toContain(
'Overview data could not be loaded.',
);
await user.click(screen.getByRole('button', { name: 'Retry loading overview' }));
expect((await screen.findByRole('alert')).textContent).toContain('无法加载概览数据。');
await user.click(screen.getByRole('button', { name: '重试加载概览' }));
expect(await screen.findByText('SIMBox 8')).toBeTruthy();
expect(load).toHaveBeenCalledTimes(2);
});