amis/__tests__/renderers/Form/iconPicker.test.tsx
liaoxuezhi 9a3d1f43c2
chore: 自动补的 input[type=submit] 放到开头, 影响原有 last-child 的 css 样式 (#2601)
* chore: 自动补的 input[type=submit] 放到开头, 影响原有 last-child 的 css 样式

* 更新 snapshot
2021-09-23 13:28:30 +08:00

62 lines
1.5 KiB
TypeScript

import React = require('react');
import {fireEvent, render} from '@testing-library/react';
import '../../../src/themes/default';
import {render as amisRender, setIconVendor} from '../../../src/index';
import {makeEnv} from '../../helper';
test('Renderer:icon-picker', async () => {
const vendors = [
{
name: 'Font Awesome 4.7',
prefix: 'fa fa-',
icons: ['address-book', 'address-book-o', 'address-card']
},
{
name: 'Glyphicons',
prefix: 'glyphicon glyphicon-',
icons: ['asterisk', 'plus', 'euro', 'eur', 'minus']
}
];
setIconVendor(vendors);
const {container, getByText, getByTitle} = render(
amisRender(
{
type: 'form',
api: '/api/xxx',
controls: [
{
type: 'icon-picker',
name: 'a',
label: 'icon-picker',
value: 'address-card'
}
],
title: 'The form',
actions: []
},
{},
makeEnv({})
)
);
const faIcon = container.querySelector('.cxd-IconPickerControl-value');
expect(faIcon?.innerHTML.replace(/<\s*i[^>]*><\s*\/\s*i>/g, '')).toEqual(
'address-card'
);
const input = container.querySelector('input[name="a"]') as any;
input?.focus();
fireEvent.click(getByText(/Glyphicons/));
fireEvent.change(input!, {
target: {
value: 'glyphicon glyphicon-plus'
}
});
fireEvent.click(getByTitle('glyphicon glyphicon-plus'));
expect(container).toMatchSnapshot();
});