/**
* In-Page Navigation Story Validation Tests
*
* These tests validate that the Storybook stories have consistent
* navigation items and content sections to prevent broken links.
*/
import { describe, it, expect } from 'vitest';
import type { InPageNavItem } from './usa-in-page-navigation.js';
import {
validateNavigationTargets,
validateHeadingSelector,
generateValidationReport,
} from '../../../__tests__/story-validation-utils.js';
// Import the sample data and helper functions from stories
const testSampleItems: InPageNavItem[] = [
{
id: 'overview',
text: 'Overview',
href: '#overview',
level: 2,
},
{
id: 'eligibility',
text: 'Eligibility Requirements',
href: '#eligibility',
level: 2,
children: [
{
id: 'basic-requirements',
text: 'Basic Requirements',
href: '#basic-requirements',
level: 3,
},
{
id: 'documentation',
text: 'Required Documentation',
href: '#documentation',
level: 3,
},
],
},
{
id: 'application-process',
text: 'Application Process',
href: '#application-process',
level: 2,
},
{
id: 'after-you-apply',
text: 'After You Apply',
href: '#after-you-apply',
level: 2,
children: [
{
id: 'review-timeline',
text: 'Review Timeline',
href: '#review-timeline',
level: 3,
},
{
id: 'status-updates',
text: 'Status Updates',
href: '#status-updates',
level: 3,
},
],
},
{
id: 'contact-information',
text: 'Contact Information',
href: '#contact-information',
level: 2,
},
];
const createContentSections = () => `
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
Details about basic requirements for eligibility. Information about required documentation.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Information about the review timeline process. Details about how you'll receive status updates.
Contact details and support information for additional assistance.
Welcome to our simple guide. Here we explain the step-by-step process. This section outlines all the requirements. Summary and final thoughts.Overview
Eligibility Requirements
Basic Requirements
Required Documentation
Application Process
After You Apply
Review Timeline
Status Updates
Contact Information
Introduction
Process
Requirements
Conclusion
This section was automatically detected.
This is a subsection that was also automatically detected.
The component scans for h2 and h3 elements.
Nested navigation items are created for h3 elements.
`; // For auto-generation, we validate that the content has the expected structure const parser = new DOMParser(); const doc = parser.parseFromString(autoGenContent, 'text/html'); const h2Elements = doc.querySelectorAll('h2'); const h3Elements = doc.querySelectorAll('h3'); expect(h2Elements.length).toBeGreaterThan(0); expect(h3Elements.length).toBeGreaterThan(0); // Verify all headings have IDs (required for navigation) const allHeadings = [...h2Elements, ...h3Elements]; allHeadings.forEach((heading) => { expect(heading.id).toBeTruthy(); }); }); }); describe('Event Handler Stories Validation', () => { it('should validate event handler story navigation items', () => { const eventItems = [ { id: 'event-section-1', text: 'Section 1', href: '#event-section-1', level: 2 }, { id: 'event-section-2', text: 'Section 2', href: '#event-section-2', level: 2 }, { id: 'event-section-3', text: 'Section 3', href: '#event-section-3', level: 2 }, ]; const eventContent = `This is the first section.
This is the second section.
This is the third section.
This section demonstrates custom scroll offset behavior.
The scroll offset setting is particularly useful for sites with fixed navigation headers.
Smooth scrolling provides a better user experience.
This section exists.