mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-10 13:22:14 +00:00
fix(settings): show a read failure on the share-link list, not an empty state
The share-link query had no error or loading handling, so a failed read collapsed to an empty list and rendered the "no active share links" copy — on a clinical sharing surface a load failure was indistinguishable from "you have shared nothing". Gate the list on the query state: QueryErrorCard with retry on failure, a skeleton while loading, the lists only once the data is in. The added test was watched fail first against the old fall-through before this fix made it pass.
This commit is contained in:
1 parent
6e3965146c
commit
53a463f11b
2 files changed
+242
-168
No files matched your search
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* A read failure on the owner share-link surface must not read as "no active
|
||||
* links". `useQuery` is forced into its error state; the card has to render the
|
||||
* `query-error-card` slot with a retry affordance and must never fall through
|
||||
* to the empty-state copy — that fall-through is the §6-forbidden case a
|
||||
* clinical sharing surface cannot afford (a failed read is indistinguishable
|
||||
* from "you have shared nothing").
|
||||
*
|
||||
* SSR-static render, matching the sibling sharing-section test.
|
||||
*/
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
vi.mock("@/hooks/use-auth", () => ({
|
||||
useAuth: () => ({
|
||||
user: { id: "u1", role: "USER" },
|
||||
isAuthenticated: true,
|
||||
isLoading: false,
|
||||
refetch: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@tanstack/react-query", () => ({
|
||||
useQuery: () => ({
|
||||
data: undefined,
|
||||
isError: true,
|
||||
isLoading: false,
|
||||
refetch: vi.fn(),
|
||||
}),
|
||||
useMutation: () => ({ mutate: vi.fn(), isPending: false }),
|
||||
useQueryClient: () => ({ invalidateQueries: vi.fn() }),
|
||||
}));
|
||||
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
import { SharingSection } from "../sharing-section";
|
||||
|
||||
function render() {
|
||||
return renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en">
|
||||
<SharingSection />
|
||||
</I18nProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("<SharingSection> — a read failure is honest, not empty", () => {
|
||||
it("renders the query-error card with retry and never the empty state", () => {
|
||||
const html = render();
|
||||
expect(html).toContain('data-slot="query-error-card"');
|
||||
expect(html).toContain('data-slot="query-error-retry"');
|
||||
// The empty-state must not appear: a failed read is not "no active links".
|
||||
expect(html).not.toContain('data-testid="share-active-empty"');
|
||||
expect(html).not.toContain("No active share links");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user