diff --git a/packages/ra-core/src/core/CoreAdmin.spec.tsx b/packages/ra-core/src/core/CoreAdmin.spec.tsx new file mode 100644 index 00000000000..e85dc9f4e53 --- /dev/null +++ b/packages/ra-core/src/core/CoreAdmin.spec.tsx @@ -0,0 +1,85 @@ +import * as React from 'react'; +import { render, screen } from '@testing-library/react'; + +import { CoreAdmin } from './CoreAdmin'; +import { Resource } from './Resource'; + +describe('CoreAdmin', () => { + describe('children', () => { + it('should accept Resources as children', async () => { + const Foo = () =>
Foo
; + const App = () => ( + + + + + ); + render(); + await screen.findByText('Foo'); + }); + it('should accept a function returning an array of Resources as children', async () => { + const Foo = () =>
Foo
; + const App = () => ( + + {() => [ + , + , + ]} + + ); + render(); + await screen.findByText('Foo'); + }); + it('should accept a function returning a fragment of Resources as children', async () => { + const Foo = () =>
Foo
; + const App = () => ( + + {() => ( + <> + + + + )} + + ); + render(); + await screen.findByText('Foo'); + }); + it('should accept a function returning a promise for an array of Resources as children', async () => { + const Foo = () =>
Foo
; + const App = () => ( + + {() => + Promise.resolve([ + , + , + ]) + } + + ); + render(); + await screen.findByText('Foo'); + }); + it('should accept a function returning a promise for a fragment of Resources as children', async () => { + const Foo = () =>
Foo
; + const App = () => ( + + {() => + Promise.resolve( + <> + + + + ) + } + + ); + render(); + await screen.findByText('Foo'); + }); + }); +}); diff --git a/packages/ra-core/src/types.ts b/packages/ra-core/src/types.ts index 965b1deca67..cdcdb63ff06 100644 --- a/packages/ra-core/src/types.ts +++ b/packages/ra-core/src/types.ts @@ -278,7 +278,11 @@ export type Dispatch = T extends (...args: infer A) => any export type ResourceElement = ReactElement; export type RenderResourcesFunction = ( permissions: any -) => ResourceElement[] | Promise; +) => + | ReactNode // (permissions) => <> + | Promise // (permissions) => fetch().then(() => <>) + | ResourceElement[] // // (permissions) => [, , ] + | Promise; // (permissions) => fetch().then(() => [, , ]) export type AdminChildren = RenderResourcesFunction | ReactNode; export type TitleComponent = string | ReactElement;