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

* 补充部分单元测试

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

47 lines
1.1 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:inputYear click', async () => {
const {container, findByText} = render(
amisRender(
{
type: 'form',
api: '/api/xxx',
body: [
{
type: 'input-year',
name: 'year',
label: '年'
}
],
title: 'The form',
actions: []
},
{},
makeEnv({})
)
);
const inputDate = await findByText('请选择年');
fireEvent.click(inputDate);
const thisYearText = moment().format('YYYY');
const thisYear = await findByText(thisYearText);
fireEvent.click(thisYear);
const value = document.querySelector(
'.cxd-DatePicker-value'
) as HTMLSpanElement;
expect(value.innerHTML).toEqual(thisYearText);
});