import {render, screen} from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import {describe, expect, it, vi} from 'vitest'; import GardenPicker from './GardenPicker'; vi.mock('./GardenFormModal', () => ({ default: ({onClose}) =>
, })); describe('GardenPicker', () => { it('shows the button', () => { render(); expect(screen.getByRole('button', {name: 'Add a garden'})).toHaveClass('big'); }); it('starts closed', () => { render(); expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); }); it('opens the new garden dialog', async () => { render(); await userEvent.click(screen.getByRole('button', {name: 'Add a garden'})); expect(screen.getByRole('dialog', {name: 'New garden'})).toBeInTheDocument(); }); it('closes it again', async () => { render(); await userEvent.click(screen.getByRole('button', {name: 'Add a garden'})); await userEvent.click(screen.getByRole('button', {name: 'Close'})); expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); }); });