Implement standardized skeleton loading placeholders to reduce perceived loading time and prevent layout shift during data fetches. These components match actual content dimensions exactly, improving perceived responsiveness. New skeleton components in src/components/skeletons/: - SkeletonTable: Table/grid loading with customizable rows and cells - SkeletonTableRow: Individual animated skeleton row - SkeletonChart: Chart/graph loading with bars matching dimensions - SkeletonStat: Stat card loading with label and value - SkeletonFormField: Form input loading placeholder - PageLoadingSkeleton: Convenience wrapper for page-level loading states Implementation details: - All skeletons use global 'skeleton-pulse' animation (2s cycle) - Dimensions match real content to prevent layout shift on arrival - Marked with aria-hidden and role=presentation for accessibility - Theme-aware colors using Fluent UI tokens - Respects prefers-reduced-motion setting Updates: - ChartStateWrapper: Uses SkeletonChart instead of spinner - PageFeedback: Added PageLoadingSkeleton component - App.tsx: Injects skeleton styles at startup - Web-Design.md: Added § 8a with loading UX guidance and usage examples All components tested (22 tests, 100% passing) and linted. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
/**
|
|
* Tests for SkeletonStat component.
|
|
*/
|
|
|
|
import { render } from "@testing-library/react";
|
|
import { describe, expect, it } from "vitest";
|
|
import { SkeletonStat } from "../SkeletonStat";
|
|
|
|
describe("SkeletonStat", () => {
|
|
it("renders label by default", () => {
|
|
const { container } = render(<SkeletonStat />);
|
|
const elements = container.querySelectorAll('[role="presentation"] > div');
|
|
expect(elements).toHaveLength(2);
|
|
});
|
|
|
|
it("hides label when showLabel is false", () => {
|
|
const { container } = render(<SkeletonStat showLabel={false} />);
|
|
const elements = container.querySelectorAll('[role="presentation"] > div');
|
|
expect(elements).toHaveLength(1);
|
|
});
|
|
|
|
it("marks elements as aria-hidden", () => {
|
|
const { container } = render(<SkeletonStat />);
|
|
const hidden = container.querySelectorAll('[aria-hidden="true"]');
|
|
expect(hidden.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("has proper accessibility attributes", () => {
|
|
const { container } = render(<SkeletonStat />);
|
|
const stat = container.querySelector('[role="presentation"]');
|
|
expect(stat).toBeInTheDocument();
|
|
});
|
|
});
|