import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { Footer, type FooterProps } from '../footer';
const renderLink: FooterProps['renderLink'] = ({ href, children, className }) => (
{children}
);
const defaultProps: FooterProps = {
brand: 'GoodGo',
description: 'Nền tảng bất động sản',
copyright: '© 2024 GoodGo',
linkGroups: [
{
title: 'Sản phẩm',
links: [
{ label: 'Bán', href: '/ban' },
{ label: 'Thuê', href: '/thue' },
],
},
],
renderLink,
};
describe('Footer', () => {
it('renders brand name', () => {
render();
expect(screen.getByText('GoodGo')).toBeInTheDocument();
});
it('renders description', () => {
render();
expect(screen.getByText('Nền tảng bất động sản')).toBeInTheDocument();
});
it('renders copyright text', () => {
render();
expect(screen.getByText('© 2024 GoodGo')).toBeInTheDocument();
});
it('renders link group title', () => {
render();
expect(screen.getByText('Sản phẩm')).toBeInTheDocument();
});
it('renders link group links', () => {
render();
expect(screen.getByText('Bán')).toBeInTheDocument();
expect(screen.getByText('Thuê')).toBeInTheDocument();
});
it('renders contact address when provided', () => {
render(
,
);
expect(screen.getByText('123 Nguyễn Huệ, TP.HCM')).toBeInTheDocument();
});
it('renders contact phone with tel link', () => {
render();
expect(screen.getByRole('link', { name: '0901234567' })).toHaveAttribute(
'href',
'tel:0901234567',
);
});
it('renders contact email with mailto link', () => {
render();
expect(screen.getByRole('link', { name: 'hello@goodgo.vn' })).toHaveAttribute(
'href',
'mailto:hello@goodgo.vn',
);
});
it('renders footer element with role="contentinfo"', () => {
render();
expect(screen.getByRole('contentinfo')).toBeInTheDocument();
});
it('does not render contact section when omitted', () => {
render();
expect(screen.queryByText(/Nguyễn Huệ/)).toBeNull();
});
});