mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 02:58:05 +08:00
chore: Link 组件单元测试补充 (#6170)
This commit is contained in:
parent
b2338922e4
commit
4b01ece327
@ -1,4 +1,13 @@
|
||||
import React = require('react');
|
||||
/**
|
||||
* 组件名称:Link 链接
|
||||
* 单测内容:
|
||||
* 1. 基础使用
|
||||
* 2. href & blank & htmlTarget
|
||||
* 3. disabled
|
||||
* 4. title & icon & rightIcon
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import {render} from '@testing-library/react';
|
||||
import '../../src';
|
||||
import {render as amisRender} from '../../src';
|
||||
@ -21,3 +30,73 @@ test('Renderer:link', async () => {
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('Renderer:link with href & blank & htmlTarget', async () => {
|
||||
const schema = {
|
||||
type: 'link',
|
||||
href: 'https://www.baidu.com',
|
||||
body: '百度一下',
|
||||
blank: true
|
||||
};
|
||||
const {container, rerender} = render(amisRender(schema));
|
||||
|
||||
const link = container.querySelector('.cxd-Link');
|
||||
expect(link).toHaveAttribute('href', 'https://www.baidu.com');
|
||||
expect(link).toHaveAttribute('target', '_blank');
|
||||
|
||||
rerender(
|
||||
amisRender({
|
||||
...schema,
|
||||
htmlTarget: '_self'
|
||||
})
|
||||
);
|
||||
|
||||
expect(link).toHaveAttribute('target', '_self');
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('Renderer:link with disabled', async () => {
|
||||
const {container} = render(
|
||||
amisRender(
|
||||
{
|
||||
type: 'link',
|
||||
href: 'https://www.baidu.com',
|
||||
body: '百度一下',
|
||||
disabled: true
|
||||
},
|
||||
{},
|
||||
makeEnv({})
|
||||
)
|
||||
);
|
||||
|
||||
const link = container.querySelector('.cxd-Link');
|
||||
expect(link).toHaveClass('is-disabled');
|
||||
expect(link).toHaveTextContent('百度一下');
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('Renderer:link with title & icon & rightIcon', async () => {
|
||||
const {container} = render(
|
||||
amisRender({
|
||||
type: 'link',
|
||||
href: 'https://www.baidu.com',
|
||||
body: '百度一下',
|
||||
title: 'linkTitleForTest',
|
||||
icon: 'fa fa-search',
|
||||
rightIcon: 'fa fa-cloud'
|
||||
})
|
||||
);
|
||||
|
||||
const link = container.querySelector('.cxd-Link');
|
||||
expect(link).toHaveAttribute('title', 'linkTitleForTest');
|
||||
|
||||
const icons = container.querySelectorAll('.cxd-Link-icon');
|
||||
|
||||
expect(icons!.length).toBe(2);
|
||||
expect(icons[0]).toHaveClass('fa-search');
|
||||
expect(icons[1]).toHaveClass('fa-cloud');
|
||||
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
@ -11,3 +11,64 @@ exports[`Renderer:link 1`] = `
|
||||
</a>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`Renderer:link with disabled 1`] = `
|
||||
<div>
|
||||
<a
|
||||
class="cxd-Link is-disabled"
|
||||
href="https://www.baidu.com"
|
||||
target="_blank"
|
||||
>
|
||||
<span
|
||||
class="cxd-TplField"
|
||||
>
|
||||
<span>
|
||||
百度一下
|
||||
</span>
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`Renderer:link with href & blank & htmlTarget 1`] = `
|
||||
<div>
|
||||
<a
|
||||
class="cxd-Link"
|
||||
href="https://www.baidu.com"
|
||||
target="_self"
|
||||
>
|
||||
<span
|
||||
class="cxd-TplField"
|
||||
>
|
||||
<span>
|
||||
百度一下
|
||||
</span>
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`Renderer:link with title & icon & rightIcon 1`] = `
|
||||
<div>
|
||||
<a
|
||||
class="cxd-Link"
|
||||
href="https://www.baidu.com"
|
||||
target="_blank"
|
||||
title="linkTitleForTest"
|
||||
>
|
||||
<i
|
||||
class="cxd-Link-icon fa fa-search"
|
||||
/>
|
||||
<span
|
||||
class="cxd-TplField"
|
||||
>
|
||||
<span>
|
||||
百度一下
|
||||
</span>
|
||||
</span>
|
||||
<i
|
||||
class="cxd-Link-icon fa fa-cloud"
|
||||
/>
|
||||
</a>
|
||||
</div>
|
||||
`;
|
||||
|
Loading…
Reference in New Issue
Block a user