amis2/__tests__/event-action/disabled.test.tsx
hsm-lv 2e229d07b1
fix:修复disabled失效问题 (#4329)
* fix:修复disabled失效问题

* test:补充事件动作测试用例
2022-05-12 22:29:17 +08:00

102 lines
2.4 KiB
TypeScript

import {fireEvent, render} from '@testing-library/react';
import '../../src/themes/default';
import {render as amisRender} from '../../src/index';
import {makeEnv} from '../helper';
test('EventAction:disabled', async () => {
const {getByText, container}: any = render(
amisRender(
{
type: 'page',
data: {
btnDisabled: true,
btnNotDisabled: false
},
body: [
{
type: 'action',
label: '按钮1',
disabledOn: '${btnDisabled}'
},
{
type: 'action',
label: '按钮2',
disabledOn: '${btnNotDisabled}',
onEvent: {
click: {
actions: [
{
actionType: 'disabled',
componentId: 'ui:button_test_3'
}
]
}
}
},
{
type: 'action',
label: '按钮3',
disabledOn: '${btnNotDisabled}',
id: 'ui:button_test_3'
},
{
type: 'action',
label: '按钮4',
disabledOn: '${btnNotDisabled}',
onEvent: {
click: {
actions: [
{
actionType: 'enabled',
componentId: 'ui:button_test_5'
}
]
}
}
},
{
type: 'action',
label: '按钮5',
disabled: true,
id: 'ui:button_test_5'
},
{
type: 'action',
label: '按钮6',
onEvent: {
click: {
actions: [
{
actionType: 'disabled',
componentId: 'ui:form_disable'
}
]
}
}
},
{
type: 'form',
id: 'ui:form_disable',
title: '表单',
body: [
{
type: 'button',
className: 'ml-2',
label: '我的状态变了'
}
]
}
]
},
{},
makeEnv({})
)
);
fireEvent.click(getByText(/按钮2/));
fireEvent.click(getByText(/按钮4/));
fireEvent.click(getByText(/按钮6/));
expect(container).toMatchSnapshot();
});