import { describe, expect, it } from 'vitest';
import { appRoutes } from '@/app/appRoutes';
import { MODULES } from '@/shared/constants/appData';
import { APP_ROUTE_PATHS } from '@/shared/constants/routes';

describe('app routes', () => {
  it('declares the required top-level routes through object config', () => {
    expect(appRoutes.map((route) => route.path)).toEqual([
      undefined, // AuthGuard wrapper (no path)
      APP_ROUTE_PATHS.login,
      APP_ROUTE_PATHS.notFound,
    ]);
  });

  it('declares one shell child route for every product module route', () => {
    // AuthGuard is the first route, shell is nested inside it
    const authGuardRoute = appRoutes[0];
    const shellRoute = authGuardRoute?.children?.find(
      (route) => route.path === APP_ROUTE_PATHS.home,
    );
    const childPaths = shellRoute?.children
      ?.map((route) => route.path)
      .filter((path): path is string => typeof path === 'string');

    expect(childPaths).toEqual(MODULES.map((module) => module.routePath.slice(1)));
  });

  it('redirects the shell index route to the dashboard route', () => {
    const authGuardRoute = appRoutes[0];
    const shellRoute = authGuardRoute?.children?.find(
      (route) => route.path === APP_ROUTE_PATHS.home,
    );
    const indexRoute = shellRoute?.children?.find((route) => route.index);

    expect(indexRoute).toBeDefined();
    expect(indexRoute?.element).toBeDefined();
  });
});
