Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions __tests__/loading-skeleton-animations.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Issue #278 – Incorporate CSS micro-animations on loading_spinner_skeleton elements
*
* Verifies that LoadingSkeleton fades in smoothly on mount (state change)
* and that its internal bars pulse with a staggered delay rather than all
* animating in perfect unison.
*/
import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import LoadingSkeleton from "@/app/components/LoadingSkeleton";

describe("LoadingSkeleton – micro-animations (issue #278)", () => {
it("fades in on mount via animate-fade-in", () => {
render(<LoadingSkeleton />);
expect(screen.getByTestId("loading-skeleton")).toHaveClass("animate-fade-in");
});

it("stat placeholders pulse", () => {
render(<LoadingSkeleton />);
expect(screen.getByTestId("loading-skeleton-stat-0")).toHaveClass("animate-pulse");
expect(screen.getByTestId("loading-skeleton-stat-1")).toHaveClass("animate-pulse");
expect(screen.getByTestId("loading-skeleton-stat-2")).toHaveClass("animate-pulse");
});

it("stat placeholders pulse with staggered, distinct animation delays", () => {
render(<LoadingSkeleton />);
const delays = [
screen.getByTestId("loading-skeleton-stat-0"),
screen.getByTestId("loading-skeleton-stat-1"),
screen.getByTestId("loading-skeleton-stat-2"),
].map((el) => el.className.match(/\[animation-delay:(\d+)ms\]/)?.[1]);

expect(delays).toEqual(["100", "175", "250"]);
expect(new Set(delays).size).toBe(3);
});

it("row placeholders pulse with staggered, distinct animation delays", () => {
render(<LoadingSkeleton />);
const row0 = screen.getByTestId("loading-skeleton-row-0");
const row1 = screen.getByTestId("loading-skeleton-row-1");
expect(row0).toHaveClass("animate-pulse");
expect(row1).toHaveClass("animate-pulse");
expect(row0).toHaveClass("[animation-delay:325ms]");
expect(row1).toHaveClass("[animation-delay:400ms]");
});

it("keeps the accessible loading announcement intact", () => {
render(<LoadingSkeleton />);
expect(screen.getByRole("status")).toHaveAttribute("aria-live", "polite");
expect(screen.getByText("Loading job data…")).toBeInTheDocument();
});

it("decorative skeleton markup stays hidden from assistive tech", () => {
render(<LoadingSkeleton />);
expect(screen.getByTestId("loading-skeleton-card")).toHaveAttribute("aria-hidden", "true");
});
});
46 changes: 35 additions & 11 deletions app/components/LoadingSkeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,58 @@
export default function LoadingSkeleton() {
return (
<div className="animate-pulse" role="status" aria-live="polite">
<div
className="animate-fade-in"
role="status"
aria-live="polite"
data-testid="loading-skeleton"
>
<span className="sr-only">Loading job data…</span>
<div className="border border-gray-800 rounded-xl bg-gray-900 p-6 space-y-6" aria-hidden="true">
<div
className="border border-gray-800 rounded-xl bg-gray-900 p-6 space-y-6"
aria-hidden="true"
data-testid="loading-skeleton-card"
>
<div className="flex items-center justify-between mb-6">
<div>
<div className="h-6 w-32 bg-gray-800 rounded mb-2"></div>
<div className="h-4 w-24 bg-gray-800 rounded"></div>
<div className="animate-pulse h-6 w-32 bg-gray-800 rounded mb-2"></div>
<div className="animate-pulse h-4 w-24 bg-gray-800 rounded [animation-delay:75ms]"></div>
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
<div className="bg-gray-800 rounded-lg p-3">
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6" data-testid="loading-skeleton-stats">
<div
className="animate-pulse bg-gray-800 rounded-lg p-3 [animation-delay:100ms]"
data-testid="loading-skeleton-stat-0"
>
<div className="h-4 w-12 bg-gray-700 rounded mb-2"></div>
<div className="h-4 w-28 bg-gray-700 rounded"></div>
</div>
<div className="bg-gray-800 rounded-lg p-3">
<div
className="animate-pulse bg-gray-800 rounded-lg p-3 [animation-delay:175ms]"
data-testid="loading-skeleton-stat-1"
>
<div className="h-4 w-12 bg-gray-700 rounded mb-2"></div>
<div className="h-4 w-28 bg-gray-700 rounded"></div>
</div>
<div className="bg-gray-800 rounded-lg p-3">
<div
className="animate-pulse bg-gray-800 rounded-lg p-3 [animation-delay:250ms]"
data-testid="loading-skeleton-stat-2"
>
<div className="h-4 w-12 bg-gray-700 rounded mb-2"></div>
<div className="h-4 w-28 bg-gray-700 rounded"></div>
</div>
</div>
<div className="space-y-4">
<div className="border border-gray-800 rounded-lg p-4 bg-gray-900">
<div className="space-y-4" data-testid="loading-skeleton-rows">
<div
className="animate-pulse border border-gray-800 rounded-lg p-4 bg-gray-900 [animation-delay:325ms]"
data-testid="loading-skeleton-row-0"
>
<div className="h-4 w-24 bg-gray-800 rounded mb-2"></div>
<div className="h-4 w-32 bg-gray-800 rounded"></div>
</div>
<div className="border border-gray-800 rounded-lg p-4 bg-gray-900">
<div
className="animate-pulse border border-gray-800 rounded-lg p-4 bg-gray-900 [animation-delay:400ms]"
data-testid="loading-skeleton-row-1"
>
<div className="h-4 w-24 bg-gray-800 rounded mb-2"></div>
<div className="h-4 w-32 bg-gray-800 rounded"></div>
</div>
Expand Down