{
choices: Record[];
error?: string;
loaded: boolean;
@@ -125,13 +127,16 @@ interface ChildrenFuncParams {
setFilter: (filter: any) => void;
setPagination: (pagination: PaginationPayload) => void;
setSort: (sort: SortPayload) => void;
+ setSortForList: (sort: string, order?: string) => void;
warning?: string;
}
interface ReferenceArrayInputControllerProps {
allowEmpty?: boolean;
basePath: string;
- children: (params: ChildrenFuncParams) => ReactElement;
+ children: (
+ params: ReferenceArrayInputControllerChildrenFuncParams
+ ) => ReactElement;
filter?: object;
filterToQuery?: (filter: {}) => any;
input?: any;
From 1991de73d7b9f8bf8137745595cebf18fe49cbed Mon Sep 17 00:00:00 2001
From: Gildas Garcia <1122076+djhi@users.noreply.github.com>
Date: Thu, 11 Feb 2021 15:18:55 +0100
Subject: [PATCH 11/16] Add tests
---
.../ReferenceArrayInputController.spec.tsx | 115 +++++++++++++++++-
.../src/input/ReferenceArrayInput.spec.js | 67 +++++++++-
2 files changed, 180 insertions(+), 2 deletions(-)
diff --git a/packages/ra-core/src/controller/input/ReferenceArrayInputController.spec.tsx b/packages/ra-core/src/controller/input/ReferenceArrayInputController.spec.tsx
index bd914af6986..47491d613ef 100644
--- a/packages/ra-core/src/controller/input/ReferenceArrayInputController.spec.tsx
+++ b/packages/ra-core/src/controller/input/ReferenceArrayInputController.spec.tsx
@@ -2,9 +2,12 @@ import * as React from 'react';
import expect from 'expect';
import { waitFor, fireEvent } from '@testing-library/react';
import { Form } from 'react-final-form';
-import ReferenceArrayInputController from './ReferenceArrayInputController';
import { renderWithRedux } from 'ra-test';
+import ReferenceArrayInputController, {
+ ReferenceArrayInputControllerChildrenFuncParams,
+} from './ReferenceArrayInputController';
import { CRUD_GET_MATCHING, CRUD_GET_MANY } from '../../../lib';
+import { SORT_ASC } from '../../reducer/admin/resource/list/queryReducer';
describe('', () => {
const defaultProps = {
@@ -771,4 +774,114 @@ describe('', () => {
).toEqual(1);
});
});
+
+ it('should props compatible with the ListContext', async () => {
+ const children = ({
+ setPage,
+ setPerPage,
+ setSortForList,
+ }: ReferenceArrayInputControllerChildrenFuncParams): React.ReactElement => {
+ const handleSetPage = () => {
+ setPage(2);
+ };
+ const handleSetPerPage = () => {
+ setPerPage(50);
+ };
+ const handleSetSort = () => {
+ setSortForList('name', SORT_ASC);
+ };
+
+ return (
+ <>
+
+
+
+ >
+ );
+ };
+
+ const { getByLabelText, dispatch } = renderWithRedux(
+