mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-05 05:18:34 +08:00
feat: crud新增双击行事件
This commit is contained in:
parent
d763d2e88b
commit
88a9ce1685
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
70
packages/amis/__tests__/renderers/CRUD2.test.tsx
Normal file
70
packages/amis/__tests__/renderers/CRUD2.test.tsx
Normal file
@ -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<RenderOptions>) =>
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
@ -361,6 +361,7 @@ const INNER_EVENTS: Array<CRUDRendererEvent> = [
|
||||
'columnToggled',
|
||||
'orderChange',
|
||||
'rowClick',
|
||||
'rowDbClick',
|
||||
'rowMouseEnter',
|
||||
'rowMouseLeave',
|
||||
'selected'
|
||||
|
@ -212,6 +212,7 @@ const INNER_EVENTS: Array<CRUDRendererEvent> = [
|
||||
'columnToggled',
|
||||
'orderChange',
|
||||
'rowClick',
|
||||
'rowDbClick',
|
||||
'rowMouseEnter',
|
||||
'rowMouseLeave',
|
||||
'selected'
|
||||
|
@ -415,6 +415,7 @@ export type TableRendererEvent =
|
||||
| 'columnToggled'
|
||||
| 'orderChange'
|
||||
| 'rowClick'
|
||||
| 'rowDbClick'
|
||||
| 'rowMouseEnter'
|
||||
| 'rowMouseLeave';
|
||||
|
||||
|
@ -389,6 +389,7 @@ export type Table2RendererEvent =
|
||||
| 'columnToggled'
|
||||
| 'orderChange'
|
||||
| 'rowClick'
|
||||
| 'rowDbClick'
|
||||
| 'rowMouseEnter'
|
||||
| 'rowMouseLeave';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user