import { mount } from '@vue/test-utils' import { describe, it, expect, vi } from 'vitest' import FooterBar from '@/components/FooterBar/FooterBar.vue' import { locales } from '@/components/FooterBar/locales' import { A11yComplianceEnum } from '@/components/FooterBar/A11yCompliance' import { LogoSize } from '@/components/Logo/LogoSize' import { nextTick } from 'vue' describe('FooterBar', () => { const getComponentType = (item: { href: unknown }) => { return item.href ? 'a' : 'RouterLink' } const testFunction = (complianceLabel: unknown) => { return typeof complianceLabel === 'string' ? locales.a11yLabel(complianceLabel) : '' } it('renders correctly', async () => { const wrapper = mount(FooterBar) expect(FooterBar).toBeTruthy() expect(wrapper.html()).toMatchSnapshot() }) it('renders default props correctly', () => { const wrapper = mount(FooterBar) expect(wrapper.props().a11yCompliance).toBe('non-compliant') expect(wrapper.props().linkItems).toBeNull() expect(wrapper.props().sitemapRoute).toEqual({ name: 'sitemap' }) expect(wrapper.props().hideSitemapLink).toBe(false) }) it('renders custom props correctly', () => { const customProps = { a11yCompliance: A11yComplianceEnum['fully-compliant'], linkItems: [{ text: 'Custom Link', to: '/custom' }], hideSitemapLink: true, } const wrapper = mount(FooterBar, { props: customProps }) expect(wrapper.props().a11yCompliance).toBe(A11yComplianceEnum['fully-compliant']) expect(wrapper.props().linkItems).toEqual(customProps.linkItems) expect(wrapper.props().hideSitemapLink).toBe(true) }) it('renders footer links correctly', () => { const wrapper = mount(FooterBar) const links = wrapper.findAll('.vd-footer-bar-links li') expect(links.length).toBeGreaterThan(0) }) it('hides links based on props', () => { const wrapper = mount(FooterBar, { props: { hideSitemapLink: true, hideCguLink: true, hideCookiesLink: true, hideLegalNoticeLink: true, hideA11yLink: true, }, }) const links = wrapper.findAll('.vd-footer-bar-links li') expect(links.length).toBe(0) }) it('renders version if provided', () => { const version = '1.0.0' const wrapper = mount(FooterBar, { props: { version } }) expect(wrapper.text()).toContain(`${locales.versionLabel} ${version}`) }) it('computes logoSize correctly for desktop screens', () => { const wrapper = mount(FooterBar) expect(wrapper.vm.$.exposed?.logoSize.value).toBe(LogoSize.NORMAL) }) it('computes logoSize correctly for small screens', async () => { const wrapper = mount(FooterBar) Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 400, }) window.dispatchEvent(new Event('resize')) await nextTick() expect(wrapper.vm.$.exposed?.logoSize.value).toBe(LogoSize.SMALL) }) it('renders the scroll to top button and triggers scrollToTop', async () => { // Passer un slot ou forcer une condition pour activer le mode étendu const wrapper = mount(FooterBar, { slots: { default: '