import { cleanup, fireEvent, render, screen } from '@testing-library/react' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import PluginAuthInDataSourceNode from './plugin-auth-in-datasource-node' vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => { const map: Record = { 'integrations.connect': 'Connect', } return map[key] || key }, }), })) vi.mock('@remixicon/react', () => ({ RiAddLine: () => , })) describe('PluginAuthInDataSourceNode', () => { const mockOnJump = vi.fn() beforeEach(() => { vi.clearAllMocks() }) afterEach(() => { cleanup() }) it('renders connect button when not authorized', () => { render() expect(screen.getByText('Connect')).toBeInTheDocument() expect(screen.getByTestId('add-icon')).toBeInTheDocument() }) it('renders connect button', () => { render() expect(screen.getByRole('button', { name: /Connect/ })).toBeInTheDocument() }) it('calls onJumpToDataSourcePage when connect button is clicked', () => { render() fireEvent.click(screen.getByRole('button', { name: /Connect/ })) expect(mockOnJump).toHaveBeenCalledTimes(1) }) it('hides connect button and shows children when authorized', () => { render(
Data Source Connected
, ) expect(screen.queryByText('Connect')).not.toBeInTheDocument() expect(screen.getByTestId('child-content')).toBeInTheDocument() }) it('shows connect button when isAuthorized is false', () => { render(
Data Source Connected
, ) expect(screen.getByText('Connect')).toBeInTheDocument() expect(screen.queryByTestId('child-content')).not.toBeInTheDocument() }) })