mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-05 05:18:34 +08:00
ed69ac05aa
* 补充部分单测 * 补充部分单元测试 * 补充部分组件的单元测试
107 lines
2.2 KiB
TypeScript
107 lines
2.2 KiB
TypeScript
import React = require('react');
|
|
import {render, screen, fireEvent} from '@testing-library/react';
|
|
import '../../../src/themes/default';
|
|
import {render as amisRender} from '../../../src/index';
|
|
import {makeEnv} from '../../helper';
|
|
|
|
test('Renderer:input table', () => {
|
|
const {container} = render(
|
|
amisRender(
|
|
{
|
|
type: 'page',
|
|
body: {
|
|
type: 'form',
|
|
debug: 'true',
|
|
data: {
|
|
table: [
|
|
{
|
|
a: 'a1',
|
|
b: 'b1'
|
|
},
|
|
{
|
|
a: 'a2',
|
|
b: 'b2'
|
|
},
|
|
{
|
|
a: 'a3',
|
|
b: 'b3'
|
|
}
|
|
]
|
|
},
|
|
api: '/api/mock2/form/saveForm',
|
|
body: [
|
|
{
|
|
type: 'input-table',
|
|
name: 'table',
|
|
columns: [
|
|
{
|
|
name: 'a',
|
|
label: 'A'
|
|
},
|
|
{
|
|
name: 'b',
|
|
label: 'B'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{},
|
|
makeEnv({})
|
|
)
|
|
);
|
|
|
|
expect(container).toMatchSnapshot();
|
|
});
|
|
|
|
test('Renderer:input table add', async () => {
|
|
const {container, findByText} = render(
|
|
amisRender(
|
|
{
|
|
type: 'form',
|
|
api: '/api/mock2/form/saveForm',
|
|
debug: true,
|
|
body: [
|
|
{
|
|
type: 'input-table',
|
|
name: 'table',
|
|
addable: true,
|
|
editable: true,
|
|
columns: [
|
|
{
|
|
name: 'a',
|
|
label: 'A'
|
|
},
|
|
{
|
|
name: 'b',
|
|
label: 'B'
|
|
}
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{},
|
|
makeEnv({})
|
|
)
|
|
);
|
|
|
|
const add = await findByText(/新增/);
|
|
|
|
fireEvent.click(add);
|
|
|
|
const inputs = document.querySelectorAll('td input');
|
|
|
|
fireEvent.change(inputs[0], {target: {value: 'aa'}});
|
|
|
|
fireEvent.change(inputs[1], {target: {value: 'bb'}});
|
|
|
|
const save = document.querySelector('.cxd-OperationField button');
|
|
|
|
fireEvent.click(save!);
|
|
|
|
// TODO: 这里不对,难道是点击出错了
|
|
|
|
// expect(container).toMatchSnapshot();
|
|
});
|