2022-11-08 10:26:20 +08:00
|
|
|
|
/**
|
|
|
|
|
* 组件名称:InputQuarterRange 季度范围
|
2023-08-02 19:53:56 +08:00
|
|
|
|
*
|
2022-11-08 10:26:20 +08:00
|
|
|
|
* 备注:InputQuarterRange 与 dateRange 等日期范围使用的是同一个组件,所以只测试不同的地方即可
|
2023-08-02 19:53:56 +08:00
|
|
|
|
*
|
2022-11-08 10:26:20 +08:00
|
|
|
|
* 单测内容:
|
|
|
|
|
1. 点击选择
|
|
|
|
|
2. 内嵌模式
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
render,
|
|
|
|
|
fireEvent,
|
|
|
|
|
within,
|
|
|
|
|
cleanup,
|
|
|
|
|
waitFor
|
|
|
|
|
} from '@testing-library/react';
|
|
|
|
|
import '../../../src';
|
|
|
|
|
import {render as amisRender} from '../../../src';
|
|
|
|
|
import {makeEnv, wait} from '../../helper';
|
|
|
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
|
|
// 1. 点击选择
|
|
|
|
|
test('Renderer:InputQuarterRange click', async () => {
|
|
|
|
|
const {container, findByPlaceholderText, getByText} = render(
|
|
|
|
|
amisRender(
|
|
|
|
|
{
|
|
|
|
|
type: 'form',
|
|
|
|
|
api: '/api/xxx',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'input-quarter-range',
|
|
|
|
|
name: 'a',
|
|
|
|
|
label: '季度范围'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
title: 'The form',
|
|
|
|
|
actions: []
|
|
|
|
|
},
|
|
|
|
|
{},
|
|
|
|
|
makeEnv({})
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const inputs = document.querySelectorAll('.cxd-DateRangePicker-input')!;
|
|
|
|
|
|
|
|
|
|
fireEvent.click(inputs[0]!);
|
|
|
|
|
|
|
|
|
|
fireEvent.click(
|
|
|
|
|
await within(
|
|
|
|
|
document.querySelector('.cxd-DateRangePicker-start')!
|
2023-01-03 10:13:25 +08:00
|
|
|
|
).findByText('Q1')
|
2022-11-08 10:26:20 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
fireEvent.click(
|
|
|
|
|
await within(
|
2022-12-01 19:41:16 +08:00
|
|
|
|
document.querySelector('.cxd-DateRangePicker-start')!
|
2022-11-08 10:26:20 +08:00
|
|
|
|
).findByText('Q4')
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
fireEvent.click(getByText('确认'));
|
|
|
|
|
|
|
|
|
|
const thisYear = moment().format('YYYY');
|
|
|
|
|
|
2023-01-03 10:13:25 +08:00
|
|
|
|
expect((inputs[0] as HTMLInputElement).value).toEqual(`${thisYear}-Q1`);
|
2022-11-08 10:26:20 +08:00
|
|
|
|
expect((inputs[1] as HTMLInputElement).value).toEqual(`${thisYear}-Q4`);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 2. 内嵌模式
|
|
|
|
|
test('Renderer:InputQuarterRange with embed', async () => {
|
|
|
|
|
const onSubmit = jest.fn();
|
|
|
|
|
const {container} = render(
|
|
|
|
|
amisRender(
|
|
|
|
|
{
|
|
|
|
|
type: 'form',
|
|
|
|
|
api: '/api/xxx',
|
|
|
|
|
submitText: 'Submit',
|
|
|
|
|
body: [
|
|
|
|
|
{
|
|
|
|
|
type: 'input-quarter-range',
|
|
|
|
|
name: 'a',
|
|
|
|
|
label: '季度范围',
|
|
|
|
|
embed: true,
|
2023-08-02 19:53:56 +08:00
|
|
|
|
valueFormat: 'YYYY-MM',
|
|
|
|
|
displayFormat: 'YYYY/MM',
|
2022-12-01 19:41:16 +08:00
|
|
|
|
value: '2021-10,2021-12'
|
2022-11-08 10:26:20 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{onSubmit},
|
|
|
|
|
makeEnv({})
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
container.querySelector(
|
|
|
|
|
'.cxd-DateRangePicker-start .rdtQuarter.rdtActive span'
|
|
|
|
|
)!.innerHTML
|
|
|
|
|
).toBe('Q4');
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
container.querySelector(
|
|
|
|
|
'.cxd-DateRangePicker-end .rdtQuarter.rdtActive span'
|
|
|
|
|
)!.innerHTML
|
|
|
|
|
).toBe('Q4');
|
|
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
|
});
|