import React from 'react';
import '@testing-library/jest-dom';
import { render, screen, fireEvent } from '@testing-library/react';
import { ConfirmProvider } from './confirm';
import { PromptProvider, usePrompt } from './prompt';

function RenameDemo() {
  const { prompt } = usePrompt();
  return (
    <button onClick={() => void prompt({ title: 'Rename attachment', message: 'Choose a new name', defaultValue: 'resume.pdf', confirmLabel: 'Rename' })}>
      Rename attachment
    </button>
  );
}

test('prompt dialog opens with default rename value', async () => {
  render(
    <ConfirmProvider>
      <PromptProvider>
        <RenameDemo />
      </PromptProvider>
    </ConfirmProvider>,
  );

  fireEvent.click(screen.getByRole('button', { name: /rename attachment/i }));

  expect(await screen.findByDisplayValue('resume.pdf')).toBeInTheDocument();
  expect(screen.getByText(/choose a new name/i)).toBeInTheDocument();
  expect(screen.getByText(/10\/180/i)).toBeInTheDocument();
});
