le8i2digy: Keep the posts and show an inline error when a refresh fails

This commit is contained in:
2026-10-20 08:09:51 -06:00
parent 69a11436f5
commit b3cfe94810
5 changed files with 41 additions and 5 deletions
+23 -1
View File
@@ -3,7 +3,7 @@ import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { FeedView, RefreshButton, type FeedViewProps } from "@/components/FeedView";
import { fetchFeedPage, FeedLoadError } from "@/lib/feed-client";
import { commentsLabel, formatDuration, mergePosts, relativeTime, toCardPost, toCardPosts, upgradeVideos } from "@/lib/feed-model";
import { commentsLabel, firstLoadFailure, 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> = {}) => ({
@@ -245,3 +245,25 @@ describe("comments label", () => {
expect(html).not.toContain("1 comments");
});
});
describe("failed refresh versus failed first load", () => {
it("a failed refresh keeps the posts and shows an inline error with a usable button", () => {
const posts = toCardPosts([post("1", "2026-10-19T11:00:00Z")]);
const html = render({ posts, onRefresh: () => {}, refreshFailed: true });
expect(html).toContain("Could not refresh. Try again.");
expect(html).toContain("text 1");
expect(html).not.toContain("The feed did not load.");
expect(html).not.toMatch(/<button[^>]*disabled[^>]*aria-label="Refresh feed"|<button[^>]*aria-label="Refresh feed"[^>]*disabled/);
});
it("a failed first load shows the full error state", () => {
const html = render({ status: "error", onRefresh: () => {} });
expect(html).toContain("The feed did not load.");
expect(html).not.toContain("Could not refresh");
});
it("the loader maps a failure to the right outcome", () => {
expect(firstLoadFailure(true)).toEqual({ fullError: false, refreshFailed: true });
expect(firstLoadFailure(false)).toEqual({ fullError: true, refreshFailed: false });
});
});