chore: Link 组件单元测试补充 (#6170)

This commit is contained in:
sansiro 2023-02-16 19:06:29 +08:00 committed by GitHub
parent b2338922e4
commit 4b01ece327
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 141 additions and 1 deletions

View File

@ -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();
});

View File

@ -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>
`;