Skip to content

Commit 645d6e9

Browse files
authored
update footer test case (#727)
* feat: udpate mobile footer style * feat(footer): update logo position * test(footer): update test case * chore: update snapshot * feat(footer): update logo position in footer * chore: update test case
1 parent 918f8c7 commit 645d6e9

File tree

7 files changed

+262
-86
lines changed

7 files changed

+262
-86
lines changed

site/test-coverage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = {
2020
dropdownMenu: { statements: '12%', branches: '0%', functions: '0%', lines: '12.85%' },
2121
empty: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
2222
fab: { statements: '5.4%', branches: '0%', functions: '0%', lines: '5.4%' },
23-
footer: { statements: '40%', branches: '0%', functions: '0%', lines: '40%' },
23+
footer: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
2424
form: { statements: '2.8%', branches: '0%', functions: '0%', lines: '2.96%' },
2525
grid: { statements: '100%', branches: '100%', functions: '100%', lines: '100%' },
2626
guide: { statements: '3.46%', branches: '0%', functions: '0%', lines: '3.77%' },

src/footer/Footer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ export interface FooterProps extends TdFooterProps, StyledProps {}
1111
const Footer: React.FC<FooterProps> = (originProps) => {
1212
const props = useDefaultProps(originProps, footerDefaultProps);
1313

14-
const { links, text, logo } = props;
14+
const { links, text, logo, className, style } = props;
1515

1616
const footerClass = usePrefixClass('footer');
1717
const footerLinkClass = usePrefixClass('footer__link');
1818

1919
return (
20-
<div className={`${footerClass}`}>
20+
<div className={`${footerClass} ${className || ''}`} style={style}>
2121
{logo && (
2222
<a className={`${footerClass}__logo`} href={logo.url} target={logo.target}>
23-
{logo.icon && <TImage className={`${footerClass}__icon`} src={logo.icon} />}
23+
{logo.icon && <TImage className={`${footerClass}__${logo.title ? 'icon' : 'title-url'}`} src={logo.icon} />}
2424
{logo.title && <span className={`${footerClass}__title`}>{logo.title}</span>}
2525
</a>
2626
)}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { render } from '@test/utils';
2+
import { describe, test, expect } from 'vitest';
3+
import React from 'react';
4+
import Footer from '../Footer';
5+
6+
describe('Footer', () => {
7+
describe('props', () => {
8+
test(': text', () => {
9+
const text = 'Hello. TDesign Footer.';
10+
const { container } = render(<Footer text={text} />);
11+
const textElement = container.querySelector('.t-footer__text');
12+
expect(textElement).toBeTruthy();
13+
expect(textElement.innerHTML).toBe(text);
14+
});
15+
16+
test('logo with title', () => {
17+
const logo = {
18+
icon: 'https://tdesign.gtimg.com/mobile/demos/logo2.png',
19+
title: '品牌名称',
20+
};
21+
const { container } = render(<Footer logo={logo} />);
22+
const imgElement = container.querySelector('.t-footer__icon img');
23+
expect(imgElement).toBeTruthy();
24+
expect(imgElement.getAttribute('src')).toBe(logo.icon);
25+
const logoTitleElement = container.querySelector('.t-footer__title');
26+
expect(logoTitleElement).toBeTruthy();
27+
expect(logoTitleElement.innerHTML).toBe(logo.title);
28+
});
29+
30+
test('logo without title', () => {
31+
const logo = {
32+
icon: 'https://tdesign.gtimg.com/mobile/demos/logo2.png',
33+
};
34+
const { container } = render(<Footer logo={logo} />);
35+
const imgElement = container.querySelector('.t-footer__title-url');
36+
expect(imgElement).toBeTruthy();
37+
});
38+
39+
test(': links', () => {
40+
const links = [
41+
{
42+
name: '底部链接A',
43+
url: 'https://a',
44+
},
45+
{
46+
name: '底部链接B',
47+
url: 'https://b',
48+
},
49+
];
50+
const { container } = render(<Footer links={links} />);
51+
expect(container.querySelector('.t-footer__link-list')).toBeTruthy();
52+
const itemsElement = container.querySelectorAll('.t-footer__link-item');
53+
expect(itemsElement.length).toBe(links.length);
54+
expect(itemsElement[0].innerHTML).toBe(links[0].name);
55+
});
56+
57+
test(': className', () => {
58+
const { container } = render(<Footer text="hello" className="custom-class" />);
59+
expect(container.querySelector('.t-footer.custom-class')).toBeTruthy();
60+
});
61+
62+
test(': style', () => {
63+
const { container } = render(<Footer text="hello" style={{ fontSize: '100px' }} />);
64+
expect(window.getComputedStyle(container.querySelector('.t-footer')).fontSize).toBe('100px');
65+
});
66+
});
67+
});

src/footer/_example/links.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { Footer } from 'tdesign-mobile-react';
33

4-
const text = 'Copyright © 2021-2031 TD.All Rights Reserved.';
4+
const text = 'Copyright © 2019-2023 TDesign.All Rights Reserved.';
55

66
const links = [
77
[

src/footer/_example/logo.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@ import React from 'react';
22
import { Footer } from 'tdesign-mobile-react';
33

44
const logo = {
5-
icon: 'https://tdesign.gtimg.com/mobile/demos/logo2.png',
6-
title: '品牌名称',
5+
icon: 'https://tdesign.gtimg.com/mobile/demos/logo1.png',
76
};
7+
const text = 'Copyright © 2019-2023 TDesign.All Rights Reserved.';
88

99
export default function LogoDemo() {
10-
return <Footer logo={logo} />;
10+
return (
11+
<>
12+
<div className="footer-example">
13+
<Footer logo={logo} text={text} />
14+
</div>
15+
<div className="footer-example">
16+
<Footer logo={logo} />
17+
</div>
18+
</>
19+
);
1120
}

0 commit comments

Comments
 (0)