diff --git a/src/list/ListGuesser.spec.tsx b/src/list/ListGuesser.spec.tsx new file mode 100644 index 00000000..64c061dc --- /dev/null +++ b/src/list/ListGuesser.spec.tsx @@ -0,0 +1,67 @@ +import * as React from 'react'; +import { Resource } from '@api-platform/api-doc-parser'; +import { render } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { AdminContext } from 'react-admin'; +import type { GetListResult, GetManyResult } from 'react-admin'; +import ListGuesser from './ListGuesser'; +import SchemaAnalyzerContext from '../introspection/SchemaAnalyzerContext.js'; +import schemaAnalyzer from '../hydra/schemaAnalyzer.js'; +import type { + ApiPlatformAdminDataProvider, + ApiPlatformAdminRecord, +} from '../types.js'; +import { API_FIELDS_DATA } from '../__fixtures__/parsedData.js'; + +const dataProvider: ApiPlatformAdminDataProvider = { + getList: () => + Promise.resolve({ data: [], total: 0 } as GetListResult), + getMany: () => + Promise.resolve({ data: [] } as GetManyResult), + getManyReference: () => + Promise.resolve({ data: [], total: 0 } as GetManyResult), + update: () => + Promise.resolve({ data: { id: 'id' } } as { data: RecordType }), + updateMany: () => Promise.resolve({ data: [] }), + create: () => + Promise.resolve({ data: { id: 'id' } } as { data: RecordType }), + delete: () => + Promise.resolve({ data: { id: 'id' } } as { data: RecordType }), + deleteMany: () => Promise.resolve({ data: [] }), + getOne: () => + Promise.resolve({ data: { id: 'id' } } as { data: RecordType }), + introspect: () => + Promise.resolve({ + data: { + entrypoint: 'entrypoint', + resources: [ + new Resource('books', '/books', { + fields: API_FIELDS_DATA, + readableFields: API_FIELDS_DATA, + writableFields: API_FIELDS_DATA, + parameters: [], + }), + ], + }, + }), + subscribe: () => Promise.resolve({ data: null }), + unsubscribe: () => Promise.resolve({ data: null }), +}; + +// eslint-disable-next-line tree-shaking/no-side-effects-in-initialization +describe('ListGuesser', () => { + it('renders datagrid empty on empty data and no filters', async () => { + const { findByText } = render( + + + No results} + /> + + , + ); + expect(await findByText('No results')).toBeInTheDocument(); + }); +}); diff --git a/src/list/ListGuesser.tsx b/src/list/ListGuesser.tsx index 64a67602..04923384 100644 --- a/src/list/ListGuesser.tsx +++ b/src/list/ListGuesser.tsx @@ -75,6 +75,7 @@ export const IntrospectedListGuesser = ({ isRowExpandable, body = DatagridBodyWithMercure, header, + listEmpty, empty, hover, expand, @@ -119,7 +120,7 @@ export const IntrospectedListGuesser = ({ } return ( - + , - 'children' + 'children' | 'empty' > & { datagridSx?: SxProps; + listEmpty?: ListProps['empty']; + empty?: DatagridProps['empty']; children?: ReactNode; };