import { describe, expect, it } from 'vitest';
import { RouterProvider } from 'react-router';
import { render, screen } from '@testing-library/react';
import { createMemoryRouter } from 'react-router';
import routes from './routes';

const cases = [
  {
    description: 'should render the List',
    initialEntries: ['/list'],
    list: true,
    form: false,
    notFound: false,
  },
  {
    description: 'should render the Form',
    initialEntries: ['/form'],
    list: false,
    form: true,
    notFound: false,
  },
  {
    description: 'should provide a default route that points to /list',
    initialEntries: ['/'],
    list: true,
    form: false,
    notFound: false,
  },
  {
    description: 'should render the NotFound component for invalid paths',
    initialEntries: ['/xxx'],
    list: false,
    form: false,
    notFound: true,
  },
];

describe('App', () => {
  it.each(cases)('$description', ({ initialEntries, list, form, notFound }) => {
    const router = createMemoryRouter(routes, { initialEntries });

    render(<RouterProvider router={router} />);

    const listExpect = expect(screen.queryByText('List works!'));
    const formExpect = expect(screen.queryByText('Form works!'));
    const notFoundExpect = expect(
      screen.queryByText('Ups ... Etwas ist schiefgelaufen')
    );

    list ? listExpect.toBeInTheDocument() : listExpect.not.toBeInTheDocument();

    form ? formExpect.toBeInTheDocument() : formExpect.not.toBeInTheDocument();

    notFound
      ? notFoundExpect.toBeInTheDocument()
      : notFoundExpect.not.toBeInTheDocument();
  });
});
