import { render, screen } from '@testing-library/react' import * as React from 'react' import { beforeEach, describe, expect, it, vi } from 'vitest' vi.mock('../../../base/modal', () => ({ default: ({ children, title, isShow }: { children: React.ReactNode, title: string, isShow: boolean }) => ( isShow ? (
{title}
{children}
) : null ), })) vi.mock('../../base/key-value-item', () => ({ default: ({ label, value }: { label: string, value: string }) => (
{label} {value}
), })) vi.mock('../../install-plugin/utils', () => ({ convertRepoToUrl: (repo: string) => `https://github.com/${repo}`, })) describe('PlugInfo', () => { let PlugInfo: (typeof import('../plugin-info'))['default'] beforeEach(async () => { vi.clearAllMocks() const mod = await import('../plugin-info') PlugInfo = mod.default }) it('should render modal with title', () => { render() expect(screen.getByTestId('modal')).toBeInTheDocument() expect(screen.getByTestId('modal-title')).toHaveTextContent('plugin.pluginInfoModal.title') }) it('should display repository info', () => { render() const kvItems = screen.getAllByTestId('key-value-item') expect(kvItems.length).toBeGreaterThanOrEqual(1) const values = screen.getAllByTestId('kv-value') expect(values.some(v => v.textContent?.includes('https://github.com/org/plugin'))).toBe(true) }) it('should display release info', () => { render() const values = screen.getAllByTestId('kv-value') expect(values.some(v => v.textContent === 'v1.0.0')).toBe(true) }) it('should display package name', () => { render() const values = screen.getAllByTestId('kv-value') expect(values.some(v => v.textContent === 'my-plugin.difypkg')).toBe(true) }) it('should not show items for undefined props', () => { render() expect(screen.queryAllByTestId('key-value-item')).toHaveLength(0) }) })