import {fireEvent, render, screen, waitFor} from '@testing-library/react' import {describe, expect, test, vi} from 'vitest' import {CloudFormationCreatePanel} from './CloudFormationCreatePanel' describe('CloudFormationCreatePanel', () => { test('loads a YAML template file into the template editor', async () => { render() const input = document.querySelector('input[type="file"]') as HTMLInputElement fireEvent.change(input, {target: {files: [new File(['Resources:\n Queue:\n Type: AWS::SQS::Queue\n'], 'queue.yaml', {type: 'text/yaml'})]}}) await waitFor(() => expect(screen.getByLabelText('Template')).toHaveValue('Resources:\n Queue:\n Type: AWS::SQS::Queue\n')) expect(screen.getByText('Loaded queue.yaml')).toBeInTheDocument() }) test('submits a stack with an S3 template URL without inline content', () => { const onSubmit = vi.fn() render() fireEvent.change(screen.getByPlaceholderText('orders-stack'), {target: {value: 'orders-stack'}}) fireEvent.change(screen.getByLabelText('Template S3 URL'), {target: {value: 'http://templates.localhost:4566/orders.yaml'}}) fireEvent.click(screen.getByRole('button', {name: 'Create stack'})) expect(onSubmit).toHaveBeenCalledWith({stackName: 'orders-stack', templateBody: '', templateUrl: 'http://templates.localhost:4566/orders.yaml', parameters: '{}', capabilities: ''}) }) })