|
| 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 | +}); |
0 commit comments