import { render, screen, fireEvent } from '@testing-library/react'; import { describe, it, expect, vi } from 'vitest'; import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, } from './dropdown-menu'; import React from 'react'; // Mocking Portal vi.mock('@radix-ui/react-dropdown-menu', async () => { const actual = await vi.importActual('@radix-ui/react-dropdown-menu'); return { ...actual, Portal: ({ children }: { children: React.ReactNode }) => (
{children}
), }; }); describe('DropdownMenu', () => { it('renders correctly', () => { render( Open My Account Profile Settings ); expect(screen.getByText('Open')).toBeInTheDocument(); }); it('shows content when open is true', () => { render( Open Option 1 ); expect(screen.getByText('Option 1')).toBeInTheDocument(); }); it('has correct data-slot attributes', () => { const { container } = render( Open ); expect(container.querySelector('[data-slot="dropdown-menu-trigger"]')).toBeInTheDocument(); }); });