diff --git a/packages/amis/__tests__/renderers/CRUD.test.tsx b/packages/amis/__tests__/renderers/CRUD.test.tsx index 77a0c3729..ce76b9575 100644 --- a/packages/amis/__tests__/renderers/CRUD.test.tsx +++ b/packages/amis/__tests__/renderers/CRUD.test.tsx @@ -23,7 +23,7 @@ import { fireEvent, render, waitFor, - waitForElementToBeRemoved + screen } from '@testing-library/react'; import '../../src'; import {clearStoresCache, render as amisRender} from '../../src'; @@ -997,3 +997,42 @@ test('Renderer: crud searchable sortable filterable', async () => { // 弹窗中没有 排序 expect(container.querySelectorAll('[data-role="form-item"]').length).toBe(1); }); + +describe('inner events', () => { + test('should call the callback function if provided while double clicking a row of the crud', async () => { + const mockFn = jest.fn(); + render( + amisRender( + { + type: 'crud', + data: { + items: rows + }, + columns: [ + { + name: 'engine', + label: 'Rendering engine' + } + ], + onEvent: { + rowDbClick: { + actions: [ + { + actionType: 'custom', + script: mockFn + } + ] + } + } + }, + {} + ) + ); + + await waitFor(() => { + const ele = screen.getAllByText('Trident'); + fireEvent.dblClick(ele[0]); + expect(mockFn).toBeCalledTimes(1); + }); + }); +}); diff --git a/packages/amis/__tests__/renderers/CRUD2.test.tsx b/packages/amis/__tests__/renderers/CRUD2.test.tsx new file mode 100644 index 000000000..946405f69 --- /dev/null +++ b/packages/amis/__tests__/renderers/CRUD2.test.tsx @@ -0,0 +1,70 @@ +/* + * @Author: ZhangBaiSen + * @since: 2023-06-02 15:46:01 + * @LastEditors: ZhangBaiSen + * @LastEditTime: 2023-06-02 15:46:54 + * @desc:290057637@qq.com + * @文件相对于项目的路径: /fork-amis/packages/amis/__tests__/renderers/CRUD2.test.tsx + */ +import { + cleanup, + fireEvent, + render, + waitFor, + screen +} from '@testing-library/react'; +import '../../src'; +import {clearStoresCache, render as amisRender} from '../../src'; +import {makeEnv as makeEnvRaw, wait} from '../helper'; +import rows from '../mockData/rows'; +import type {RenderOptions} from '../../src'; + +afterEach(() => { + cleanup(); + clearStoresCache(); + jest.useRealTimers(); +}); + +/** 避免updateLocation里的console.error */ +const makeEnv = (env?: Partial) => + makeEnvRaw({updateLocation: () => {}, ...env}); + +describe('inner events', () => { + test('should call the callback function if provided while double clicking a row of the crud2', async () => { + const mockFn = jest.fn(); + render( + amisRender( + { + type: 'crud2', + mode: 'table', + data: { + items: rows + }, + columns: [ + { + name: 'engine', + label: 'Rendering engine' + } + ], + onEvent: { + rowDbClick: { + actions: [ + { + actionType: 'custom', + script: mockFn + } + ] + } + } + }, + {} + ) + ); + + await waitFor(() => { + const ele = screen.getAllByText('Trident'); + fireEvent.dblClick(ele[0]); + expect(mockFn).toBeCalledTimes(1); + }); + }); +}); diff --git a/packages/amis/src/renderers/CRUD.tsx b/packages/amis/src/renderers/CRUD.tsx index 6d1f6e0d2..472da28a4 100644 --- a/packages/amis/src/renderers/CRUD.tsx +++ b/packages/amis/src/renderers/CRUD.tsx @@ -361,6 +361,7 @@ const INNER_EVENTS: Array = [ 'columnToggled', 'orderChange', 'rowClick', + 'rowDbClick', 'rowMouseEnter', 'rowMouseLeave', 'selected' diff --git a/packages/amis/src/renderers/CRUD2.tsx b/packages/amis/src/renderers/CRUD2.tsx index 68efe3194..2c5d176cf 100644 --- a/packages/amis/src/renderers/CRUD2.tsx +++ b/packages/amis/src/renderers/CRUD2.tsx @@ -212,6 +212,7 @@ const INNER_EVENTS: Array = [ 'columnToggled', 'orderChange', 'rowClick', + 'rowDbClick', 'rowMouseEnter', 'rowMouseLeave', 'selected' diff --git a/packages/amis/src/renderers/Table/index.tsx b/packages/amis/src/renderers/Table/index.tsx index ed436781b..f239e5048 100644 --- a/packages/amis/src/renderers/Table/index.tsx +++ b/packages/amis/src/renderers/Table/index.tsx @@ -415,6 +415,7 @@ export type TableRendererEvent = | 'columnToggled' | 'orderChange' | 'rowClick' + | 'rowDbClick' | 'rowMouseEnter' | 'rowMouseLeave'; diff --git a/packages/amis/src/renderers/Table2/index.tsx b/packages/amis/src/renderers/Table2/index.tsx index a76e85abe..7970216ea 100644 --- a/packages/amis/src/renderers/Table2/index.tsx +++ b/packages/amis/src/renderers/Table2/index.tsx @@ -389,6 +389,7 @@ export type Table2RendererEvent = | 'columnToggled' | 'orderChange' | 'rowClick' + | 'rowDbClick' | 'rowMouseEnter' | 'rowMouseLeave';