import React, { ReactNode, RefObject, Suspense } from 'react'; import { WixPatternsTestProvider } from '../components'; import { Page, WixStyleReactEnvironmentProvider } from '@wix/design-system'; import { WixPatternsContainerProvider } from '@wix/bex-core/react'; import { WixPatternsContainerDriver } from '@wix/bex-core/testkit/internal'; import { EssentialsProvider } from '@wix/fe-essentials/react'; import { EntityPageState } from '../state'; import { CollectionPageState } from '@wix/bex-core'; import { EntityPage } from '../components/EntityPage'; import { CollectionPage } from '../components/CollectionPageNew'; import { PageWrapper } from '../components/PageWrapper/PageWrapper'; import { History } from 'history'; const CairoTestAppRouter = React.lazy(() => import('./CairoTestAppRouter').then((module) => ({ default: module.CairoTestAppRouter, })), ); import { CollectionPageHeaderProps } from '../components/CollectionPageHeaderNew'; export interface CairoTestAppProps { driver: WixPatternsContainerDriver; children?: ReactNode; page?: | 'none' | 'wsr' | 'entity' | 'entity-page' | 'collection-page' | 'router'; scrollElement?: RefObject; entityPageState?: EntityPageState; collectionPageState?: CollectionPageState; routerParams?: { history: History }; collectionPageHeaderProps?: Partial; } export function CairoTestApp({ children, driver, page, scrollElement, entityPageState, collectionPageState, routerParams, collectionPageHeaderProps, }: CairoTestAppProps) { let child = children; switch (page) { case 'wsr': child = ( {children} ); break; case 'entity': child = ( {children} ); break; case 'none': child = (
{child}
); break; case 'entity-page': if (!entityPageState) { throw new Error('Page state was not initialized'); } child = ( {children} ); break; case 'collection-page': if (!collectionPageState) { throw new Error('Page state was not initialized'); } child = ( {children} ); break; case 'router': if (!routerParams) { throw new Error('Router params were not initialized'); } child = ( Loading router...}> {children} ); break; default: child = ( {children} ); break; } return ( {child} ); }