import { fireEvent, render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { describe, expect, it, vi } from 'vitest';

import WorkflowsRun from './WorkflowsRun';

vi.mock('../lib/i18n/I18nContext', () => ({ useT: () => ({ t: (k: string) => k }) }));
vi.mock('../components/skills/WorkflowRunnerBody', () => ({
  default: () => <div data-testid="skills-runner-body" />,
}));

describe('WorkflowsRun', () => {
  const render_ = () =>
    render(
      <MemoryRouter>
        <WorkflowsRun />
      </MemoryRouter>
    );

  it('renders the back button and page heading', () => {
    render_();
    expect(screen.getByRole('button', { name: 'common.back' })).toBeInTheDocument();
    expect(screen.getByText('skills.run.title')).toBeInTheDocument();
  });

  it('renders WorkflowRunnerBody', () => {
    render_();
    expect(screen.getByTestId('skills-runner-body')).toBeInTheDocument();
  });

  it('back button fires navigate on click', () => {
    render_();
    fireEvent.click(screen.getByRole('button', { name: 'common.back' }));
    // navigate() called — no assertion needed beyond no-throw
  });
});
