le8i2digy: Add a refresh button to the Home feed header and singularize one comment
This commit is contained in:
+42
-2
@@ -1,9 +1,9 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createElement } from "react";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { FeedView, type FeedViewProps } from "@/components/FeedView";
|
||||
import { FeedView, RefreshButton, type FeedViewProps } from "@/components/FeedView";
|
||||
import { fetchFeedPage, FeedLoadError } from "@/lib/feed-client";
|
||||
import { formatDuration, mergePosts, relativeTime, toCardPost, toCardPosts, upgradeVideos } from "@/lib/feed-model";
|
||||
import { commentsLabel, formatDuration, mergePosts, relativeTime, toCardPost, toCardPosts, upgradeVideos } from "@/lib/feed-model";
|
||||
|
||||
const NOW = Date.parse("2026-10-19T12:00:00Z");
|
||||
const post = (id: string, publishedAt: string, extra: Record<string, unknown> = {}) => ({
|
||||
@@ -205,3 +205,43 @@ describe("video duration", () => {
|
||||
expect(dur({})).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("refresh button", () => {
|
||||
it("is in the Home feed header with its accessible name", () => {
|
||||
const html = render({ onRefresh: () => {} });
|
||||
expect(html).toContain('aria-label="Refresh feed"');
|
||||
expect(html.indexOf("Home feed")).toBeLessThan(html.indexOf("Refresh feed"));
|
||||
});
|
||||
|
||||
it("is absent without a handler", () => {
|
||||
expect(render({})).not.toContain("Refresh feed");
|
||||
});
|
||||
|
||||
it("triggers a reload when clicked", () => {
|
||||
const onRefresh = vi.fn();
|
||||
const el = RefreshButton({ onRefresh }) as { props: { onClick: () => void } };
|
||||
el.props.onClick();
|
||||
expect(onRefresh).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("is disabled and spinning while a reload runs", () => {
|
||||
const html = render({ onRefresh: () => {}, refreshing: true });
|
||||
expect(html).toMatch(/<button[^>]*disabled[^>]*aria-label="Refresh feed"|<button[^>]*aria-label="Refresh feed"[^>]*disabled/);
|
||||
expect(html).toContain("refresh-icon-spin");
|
||||
});
|
||||
});
|
||||
|
||||
describe("comments label", () => {
|
||||
it("is singular for 1 and plural otherwise", () => {
|
||||
expect(commentsLabel(1)).toBe("1 comment");
|
||||
expect(commentsLabel(0)).toBe("0 comments");
|
||||
expect(commentsLabel(2)).toBe("2 comments");
|
||||
});
|
||||
|
||||
it("renders singular on a one-comment post", () => {
|
||||
const posts = toCardPosts([{ ...post("1", "2026-10-19T11:00:00Z"), commentsCount: 1 }]);
|
||||
const html = render({ posts });
|
||||
expect(html).toContain("1 comment<");
|
||||
expect(html).not.toContain("1 comments");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user