Skip to content

Commit

Permalink
AdminGuesserProps - missing admin prop type (api-platform#558)
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelSuwinski authored May 28, 2024
1 parent 5782f76 commit e0c087f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/AdminGuesser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React from 'react';
import { AdminUI, AuthContext } from 'react-admin';
import type { AdminProps, AuthProvider } from 'react-admin';
import ReactTestRenderer from 'react-test-renderer/shallow';
import { AdminResourcesGuesser } from './AdminGuesser.js';
import AdminGuesser, { AdminResourcesGuesser } from './AdminGuesser.js';
import ResourceGuesser from './ResourceGuesser.js';
import schemaAnalyzer from './hydra/schemaAnalyzer.js';
import resources from './__fixtures__/resources.js';
import { API_DATA } from './__fixtures__/parsedData.js';
import type {
Expand Down Expand Up @@ -83,4 +86,36 @@ describe('<AdminGuesser />', () => {

expect(renderer.getRenderOutput()).toMatchSnapshot();
});

test('renders with admin element', () => {
const authProvider: AuthProvider = {
getPermissions: () => Promise.resolve(['user']),
getIdentity: () =>
Promise.resolve({
id: '/users/2',
fullName: 'Test User',
avatar: undefined,
}),
login: () => Promise.resolve(),
logout: () => Promise.resolve(),
checkAuth: () => Promise.resolve(),
checkError: () => Promise.resolve(),
};

const AdminEl = (props: AdminProps) => (
<AuthContext.Provider value={authProvider}>
<AdminUI {...props} />
</AuthContext.Provider>
);

renderer.render(
<AdminGuesser
admin={AdminEl}
dataProvider={dataProvider}
schemaAnalyzer={schemaAnalyzer()}
/>,
);

expect(renderer.getRenderOutput()).not.toBeNull();
});
});
2 changes: 2 additions & 0 deletions src/AdminGuesser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import useDisplayOverrideCode from './useDisplayOverrideCode.js';
import type { ApiPlatformAdminDataProvider, SchemaAnalyzer } from './types.js';

export interface AdminGuesserProps extends AdminProps {
admin?: ComponentType<AdminProps>;
dataProvider: ApiPlatformAdminDataProvider;
schemaAnalyzer: SchemaAnalyzer;
includeDeprecated?: boolean;
Expand Down Expand Up @@ -214,6 +215,7 @@ AdminGuesser.propTypes = {
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
theme: PropTypes.object,
includeDeprecated: PropTypes.bool,
admin: PropTypes.elementType,
};
/* eslint-enable tree-shaking/no-side-effects-in-initialization */

Expand Down

0 comments on commit e0c087f

Please sign in to comment.