feat: add accessible Skip to Content link
- Add SkipLink component with off-screen styling - Add translation keys for skip link text - Integrate SkipLink in App.tsx and wrap content in #main-content - Add unit tests for SkipLink Co-authored-by: ragusa-it <196988693+ragusa-it@users.noreply.github.com>
This commit is contained in:
34
src/components/ui/__tests__/SkipLink.test.tsx
Normal file
34
src/components/ui/__tests__/SkipLink.test.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
// @vitest-environment jsdom
|
||||
import { render, screen, cleanup } from '@testing-library/react';
|
||||
import { describe, it, expect, afterEach, vi } from 'vitest';
|
||||
import { SkipLink } from '../SkipLink';
|
||||
|
||||
// Mock i18n
|
||||
vi.mock('../../../i18n', () => ({
|
||||
useTranslation: () => ({
|
||||
t: {
|
||||
nav: {
|
||||
skipToContent: 'Skip to content',
|
||||
},
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
describe('SkipLink', () => {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
it('renders a link with correct href and text', () => {
|
||||
render(<SkipLink />);
|
||||
const link = screen.getByRole('link', { name: /skip to content/i });
|
||||
expect(link).toBeTruthy();
|
||||
expect(link.getAttribute('href')).toBe('#main-content');
|
||||
});
|
||||
|
||||
it('has class attribute for styling', () => {
|
||||
render(<SkipLink />);
|
||||
const link = screen.getByRole('link');
|
||||
expect(link.getAttribute('class')).toBeTruthy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user