Files
fusion/packages/dashboard/app/hooks/__tests__/useGitHubStarPrompt.test.ts
gsxdsm 962b97ce84 FN-5967: add first-task GitHub star prompt
Show a one-time GitHub star prompt after a task first reaches done.

- detect task status transitions into done and trigger the prompt only in project view
- add a dismissible GitHub star prompt component plus localStorage-backed persistence hook
- cover the new prompt behavior with component, hook, and transition helper tests
- document the prompt behavior and styling guidance in the dashboard guide

Files changed:
 docs/dashboard-guide.md                            |  3 +
 packages/dashboard/app/App.tsx                     | 21 +++++-
 .../dashboard/app/components/GitHubStarPrompt.css  | 76 ++++++++++++++++++++++
 .../dashboard/app/components/GitHubStarPrompt.tsx  | 53 +++++++++++++++
 .../app/components/__tests__/App.test.tsx          | 12 +++-
 .../components/__tests__/GitHubStarPrompt.test.tsx | 40 ++++++++++++
 .../hooks/__tests__/useGitHubStarPrompt.test.ts    | 64 ++++++++++++++++++
 .../dashboard/app/hooks/useGitHubStarPrompt.ts     | 46 +++++++++++++
 8 files changed, 313 insertions(+), 2 deletions(-)

Fusion-Task-Id: FN-5967

Fusion-Task-Lineage: 5fffdf4d-61d8-4ac8-bcf4-8b453b639b28
2026-06-03 22:35:28 -07:00

65 lines
1.8 KiB
TypeScript

import { act, renderHook } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { markGitHubStarPromptShown, useGitHubStarPromptShown } from "../useGitHubStarPrompt";
describe("useGitHubStarPromptShown", () => {
beforeEach(() => {
localStorage.clear();
vi.restoreAllMocks();
});
it("returns false by default", () => {
const { result } = renderHook(() => useGitHubStarPromptShown());
expect(result.current).toBe(false);
});
it("marks the prompt shown and persists the flag", () => {
const { result } = renderHook(() => useGitHubStarPromptShown());
act(() => {
markGitHubStarPromptShown();
});
expect(result.current).toBe(true);
expect(localStorage.getItem("fusion:github-star-prompt-shown")).toBe("1");
});
it("survives a remount after persistence", () => {
const { unmount } = renderHook(() => useGitHubStarPromptShown());
act(() => {
markGitHubStarPromptShown();
});
unmount();
const { result } = renderHook(() => useGitHubStarPromptShown());
expect(result.current).toBe(true);
});
it("returns false when localStorage reads fail", () => {
const getItemSpy = vi.spyOn(window.localStorage, "getItem").mockImplementation(() => {
throw new Error("get failed");
});
const { result } = renderHook(() => useGitHubStarPromptShown());
expect(result.current).toBe(false);
expect(getItemSpy).toHaveBeenCalled();
});
it("swallows localStorage write errors safely", () => {
const setItemSpy = vi.spyOn(window.localStorage, "setItem").mockImplementation(() => {
throw new Error("set failed");
});
expect(() => {
act(() => {
markGitHubStarPromptShown();
});
}).not.toThrow();
expect(setItemSpy).toHaveBeenCalled();
});
});