amis/__tests__/renderers/Form/inputMonth.test.tsx
吴多益 ed69ac05aa
chore: 补充部分组件的单测,行覆盖率到 56% (#3567)
* 补充部分单测

* 补充部分单元测试

* 补充部分组件的单元测试
2022-02-11 19:36:45 +08:00

54 lines
1.3 KiB
TypeScript

import React = require('react');
import PageRenderer from '../../../src/renderers/Form';
import * as renderer from 'react-test-renderer';
import {render, fireEvent, cleanup, getByText} from '@testing-library/react';
import '../../../src/themes/default';
import {render as amisRender} from '../../../src/index';
import {makeEnv} from '../../helper';
import moment from 'moment';
test('Renderer:inputMonth click', async () => {
const {container, findByText} = render(
amisRender(
{
type: 'form',
api: '/api/xxx',
body: [
{
type: 'input-month',
name: 'month',
label: '时间'
}
],
title: 'The form',
actions: []
},
{},
makeEnv({})
)
);
const inputDate = await findByText('请选择月份');
fireEvent.click(inputDate);
// 点击前一年
(
document.querySelector('.cxd-DatePicker-popover .rdtPrev') as HTMLElement
).click();
const firstMonth = await findByText('1月');
fireEvent.click(firstMonth);
const lastYearMonth = moment().subtract(1, 'year').format('YYYY') + '-01';
await findByText(lastYearMonth);
const value = document.querySelector(
'.cxd-DatePicker-value'
) as HTMLSpanElement;
expect(value.innerHTML).toEqual(lastYearMonth);
});