import React from 'react'; import { renderToStaticMarkup } from 'react-dom/server'; import { describe, expect, it, vi } from 'vitest'; import JVMResourceBrowser from './JVMResourceBrowser'; vi.mock('@monaco-editor/react', () => ({ default: ({ language, value }: { language?: string; value?: string }) => (
{value}
), })); vi.mock('../store', () => ({ useStore: (selector: (state: any) => any) => selector({ connections: [ { id: 'conn-jvm-1', name: 'localhost', config: { host: 'localhost', jvm: { preferredMode: 'jmx', readOnly: true, }, }, }, { id: 'conn-jvm-2', name: 'writable-jvm', config: { host: 'localhost', jvm: { preferredMode: 'jmx', readOnly: false, }, }, }, ], addTab: vi.fn(), aiPanelVisible: false, setAIPanelVisible: vi.fn(), }), })); vi.mock('./jvm/JVMModeBadge', () => ({ default: ({ mode }: { mode: string }) => {mode}, })); vi.mock('./jvm/JVMChangePreviewModal', () => ({ default: () => null, })); describe('JVMResourceBrowser layout', () => { it('renders a dedicated vertical scroll shell for tall snapshot content', () => { const markup = renderToStaticMarkup( , ); expect(markup).toContain('data-jvm-resource-browser-scroll-shell="true"'); expect(markup).toContain('data-jvm-workspace-shell="true"'); expect(markup).toContain('data-jvm-workspace-hero="true"'); expect(markup).toContain('data-jvm-resource-workbench="true"'); expect(markup).toContain('height:100%'); expect(markup).toContain('overflow-y:auto'); expect(markup).toContain('grid-template-columns:minmax(0, 1fr) minmax(360px, 440px)'); }); it('shows the draft action field with a Chinese label', () => { const markup = renderToStaticMarkup( , ); expect(markup).toContain('动作'); expect(markup).not.toContain('>Action<'); }); it('hides the change draft form entirely for read-only JVM connections', () => { const markup = renderToStaticMarkup( , ); expect(markup).not.toContain('变更草稿'); expect(markup).not.toContain('预览变更'); expect(markup).not.toContain('Payload(JSON)'); }); });