Skip to content

Your lightweight open-source personal agent.

feat(webui): polish the GitHub star invitation

Xubin Ren57a465545198
diff --git a/docs/webui.md b/docs/webui.md
index 1c2bb11f2..1208fa777 100644
--- a/docs/webui.md
+++ b/docs/webui.md
@@ -95,6 +95,15 @@ This path avoids hand-editing `config.json` for normal setup. Use the reference
| Automations | Review, search, run, pause, edit, and delete scheduled and local-trigger agent turns |
| Settings | Adjust models, providers, image generation, voice, web tools, runtime, and safety options |
+### Optional GitHub invitation
+
+Returning users may see an illustrated invitation to star nanobot on GitHub.
+It follows the WebUI language and theme; the button's star animation also
+supports keyboard focus and respects reduced-motion preferences. **Maybe later**,
+the close button, or Escape dismisses it for now. **Don't ask again** or opening
+GitHub from the invitation stops future reminders for the gateway instance,
+including in other browsers. Starring is optional and never required to use nanobot.
+
## Topic Workspace
The sidebar is the topic switcher. Each topic keeps its own history, title,
diff --git a/webui/src/assets/star-invitation.webp b/webui/src/assets/star-invitation.webp
new file mode 100644
index 000000000..f44b90c84
Binary files /dev/null and b/webui/src/assets/star-invitation.webp differ
diff --git a/webui/src/components/StarPrompt.css b/webui/src/components/StarPrompt.css
new file mode 100644
index 000000000..920bc22d3
--- /dev/null
+++ b/webui/src/components/StarPrompt.css
@@ -0,0 +1,69 @@
+.star-prompt-decoration {
+ position: absolute;
+ top: -12px;
+ right: 16px;
+ width: 23px;
+ height: 23px;
+ pointer-events: none;
+ opacity: 0;
+ transform: translateY(12px) rotate(-125deg) scale(.25);
+ transform-origin: 50% 85%;
+ color: #f7c955;
+ transition: opacity 120ms ease-out, transform 180ms ease-out;
+}
+
+.star-prompt-star {
+ display: block;
+ stroke: #c68718;
+ filter: drop-shadow(0 2px 3px rgb(122 75 8 / .16));
+}
+
+.star-prompt-sparkle { position: absolute; opacity: 0; color: #efb840; }
+.star-prompt-sparkle-first { top: -6px; right: -9px; }
+.star-prompt-sparkle-second { bottom: -3px; left: -7px; }
+
+.star-prompt-action:focus-visible .star-prompt-decoration {
+ opacity: 1;
+ transform: rotate(8deg);
+ animation: star-prompt-pop 640ms cubic-bezier(.22, 1, .36, 1) both;
+}
+.star-prompt-action:focus-visible .star-prompt-sparkle {
+ animation: star-prompt-twinkle 420ms ease-out 250ms both;
+}
+.star-prompt-action:focus-visible .star-prompt-sparkle-second { animation-delay: 370ms; }
+
+@media (hover: hover) and (pointer: fine) {
+ .star-prompt-action:hover .star-prompt-decoration {
+ opacity: 1;
+ transform: rotate(8deg);
+ animation: star-prompt-pop 640ms cubic-bezier(.22, 1, .36, 1) both;
+ }
+ .star-prompt-action:hover .star-prompt-sparkle {
+ animation: star-prompt-twinkle 420ms ease-out 250ms both;
+ }
+ .star-prompt-action:hover .star-prompt-sparkle-second { animation-delay: 370ms; }
+}
+
+@keyframes star-prompt-pop {
+ 0% { opacity: 0; transform: translateY(12px) rotate(-125deg) scale(.25); }
+ 18% { opacity: 1; }
+ 48% { opacity: 1; transform: translateY(-6px) rotate(23deg) scale(1.18); }
+ 70% { transform: translateY(2px) rotate(-8deg) scale(.93); }
+ 86% { transform: translateY(-1px) rotate(11deg) scale(1.04); }
+ 100% { opacity: 1; transform: translateY(0) rotate(8deg) scale(1); }
+}
+
+@keyframes star-prompt-twinkle {
+ 0%, 100% { opacity: 0; transform: scale(.35) rotate(-15deg); }
+ 45% { opacity: 1; transform: scale(1.15) rotate(10deg); }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .star-prompt-action .star-prompt-decoration,
+ .star-prompt-action .star-prompt-sparkle {
+ animation: none;
+ transition: none;
+ transform: none;
+ }
+ .star-prompt-action .star-prompt-sparkle { display: none; }
+}
diff --git a/webui/src/components/StarPrompt.tsx b/webui/src/components/StarPrompt.tsx
index cf20b0691..dbb296945 100644
--- a/webui/src/components/StarPrompt.tsx
+++ b/webui/src/components/StarPrompt.tsx
@@ -1,13 +1,17 @@
import { useEffect, useRef, useState } from "react";
-import { ExternalLink, Star } from "lucide-react";
+import { ExternalLink, Sparkle, Star, X } from "lucide-react";
import { useTranslation } from "react-i18next";
+import starInvitation from "@/assets/star-invitation.webp";
import { Button } from "@/components/ui/button";
-import { Dialog, DialogContent, DialogDescription, DialogTitle } from "@/components/ui/dialog";
+import { Dialog, DialogClose, DialogContent, DialogDescription, DialogTitle } from "@/components/ui/dialog";
import { starPromptAction } from "@/lib/api";
import { useClient } from "@/providers/ClientProvider";
+import "./StarPrompt.css";
+
const REPOSITORY_URL = "https://github.com/HKUDS/nanobot";
+const actionClassName = "h-full min-h-[46px] min-w-0 !whitespace-normal px-3 py-2.5 text-center text-[15px] font-medium max-[480px]:text-sm";
export function StarLink({ onSaved, fullWidth = false }: {
onSaved?: () => void;
@@ -28,12 +32,18 @@ export function StarLink({ onSaved, fullWidth = false }: {
<span className="min-w-0">
{t(fullWidth ? "starPrompt.action" : "starPrompt.footerAction")}
</span>
- <ExternalLink className={fullWidth ? "ml-2 h-3.5 w-3.5 shrink-0" : "h-3.5 w-3.5 shrink-0 text-muted-foreground"} aria-hidden />
+ {fullWidth ? (
+ <span className="star-prompt-decoration" aria-hidden="true">
+ <Star className="star-prompt-star" size={23} strokeWidth={1.5} fill="currentColor" />
+ <Sparkle className="star-prompt-sparkle star-prompt-sparkle-first" size={10} strokeWidth={1.5} fill="currentColor" />
+ <Sparkle className="star-prompt-sparkle star-prompt-sparkle-second" size={7} strokeWidth={1.5} fill="currentColor" />
+ </span>
+ ) : <ExternalLink className="h-3.5 w-3.5 shrink-0 text-muted-foreground" aria-hidden />}
</a>
);
return (
<>
- {fullWidth ? <Button asChild className="h-full min-h-11 w-full !whitespace-normal px-3 py-2.5 text-center text-sm font-medium">{link}</Button> : link}
+ {fullWidth ? <Button asChild className={`star-prompt-action relative isolate w-full overflow-visible ${actionClassName}`}>{link}</Button> : link}
{error && <p role="alert" className="text-sm text-destructive">{t("starPrompt.saveError")}</p>}
</>
);
@@ -93,7 +103,8 @@ export function StarPrompt({ ready }: { ready: boolean }) {
return (
<Dialog open={open} onOpenChange={setOpen}>
- <DialogContent className="max-w-[440px] gap-0 p-6 text-center outline-none"
+ <DialogContent showCloseButton={false}
+ className="flex max-h-[calc(100dvh-32px)] max-w-[520px] flex-col gap-0 overflow-y-auto overscroll-contain p-5 pb-2.5 outline-none max-[480px]:p-4 max-[480px]:pb-2"
onOpenAutoFocus={(event) => {
event.preventDefault();
titleRef.current?.focus({ preventScroll: true });
@@ -101,22 +112,33 @@ export function StarPrompt({ ready }: { ready: boolean }) {
event.preventDefault();
previousFocus.current?.focus({ preventScroll: true });
}}>
- <img src="/brand/nanobot_mark.svg" alt="" className="mx-auto mb-4 h-10 w-10 select-none" draggable={false} />
- <DialogTitle ref={titleRef} tabIndex={-1}
- className="text-xl font-semibold leading-tight tracking-normal outline-none">
- {t("starPrompt.title")}
- </DialogTitle>
- <DialogDescription className="mt-3 text-sm leading-6 text-muted-foreground">
- {t("starPrompt.description")}
- </DialogDescription>
- <div className="mt-6 grid grid-cols-2 items-stretch gap-2">
- <Button variant="ghost" className="h-full min-h-11 !whitespace-normal bg-muted/70 px-3 py-2.5 text-sm font-medium settings-hover"
+ <img src={starInvitation} alt="" width={1672} height={941} draggable={false}
+ className="aspect-[1672/941] w-full shrink-0 select-none rounded-control bg-muted object-cover" />
+ <DialogClose aria-label={t("common.close")}
+ className="absolute right-[23px] top-[23px] grid h-11 w-11 place-items-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-white max-[480px]:right-[18px] max-[480px]:top-[18px]">
+ <span className="grid h-[30px] w-[30px] place-items-center rounded-full bg-black/40 text-white backdrop-blur-sm transition-colors hover:bg-black/60 motion-reduce:transition-none">
+ <X size={18} strokeWidth={1.75} aria-hidden />
+ </span>
+ </DialogClose>
+ <div className="shrink-0 px-2 pt-[27px] text-left max-[480px]:px-1 max-[480px]:pt-[23px]">
+ <DialogTitle ref={titleRef} tabIndex={-1}
+ className="text-[26px] font-semibold leading-[1.4] tracking-[-0.035em] outline-none [overflow-wrap:anywhere] max-[480px]:text-[clamp(18px,5.6vw,24px)]">
+ {t("starPrompt.title")}
+ </DialogTitle>
+ <DialogDescription className="mt-[15px] text-[15px] leading-[1.9] text-muted-foreground max-[480px]:mt-3 max-[480px]:text-[13px] max-[480px]:leading-[1.95]">
+ <span className="block">{t("starPrompt.intro")}</span>{" "}
+ <span className="block">{t("starPrompt.invitation")}</span>{" "}
+ <span className="block">{t("starPrompt.thanks")}</span>
+ </DialogDescription>
+ </div>
+ <div className="mt-[27px] grid shrink-0 grid-cols-2 items-stretch gap-3 px-2 max-[480px]:mt-[23px] max-[480px]:gap-2.5 max-[480px]:px-1">
+ <Button variant="outline" className={actionClassName}
onClick={() => setOpen(false)}>{t("starPrompt.later")}</Button>
- <div className="flex flex-col gap-2">
+ <div className="flex min-w-0 flex-col gap-2">
<StarLink fullWidth onSaved={() => setOpen(false)} />
</div>
</div>
- <Button variant="ghost" className="mx-auto mt-3 h-9 px-3 text-xs font-normal text-muted-foreground" disabled={saving}
+ <Button variant="ghost" className="mt-[7px] min-h-11 shrink-0 self-center !whitespace-normal px-4 text-xs font-normal text-muted-foreground" disabled={saving}
onClick={() => void dismissForever()}>{t("starPrompt.never")}</Button>
{error && <p role="alert" className="text-sm text-destructive">{t("starPrompt.saveError")}</p>}
</DialogContent>
diff --git a/webui/src/i18n/locales/en/common.json b/webui/src/i18n/locales/en/common.json
index 296cc2f0c..82d6203cb 100644
--- a/webui/src/i18n/locales/en/common.json
+++ b/webui/src/i18n/locales/en/common.json
@@ -31,11 +31,13 @@
},
"starPrompt": {
"footerAction": "Star nanobot on GitHub",
- "title": "Thanks for using nanobot",
- "description": "Star nanobot on GitHub to help us keep improving it.",
+ "title": "Glad we could help.",
+ "intro": "If nanobot has made your day a little easier,",
+ "invitation": "we'd love a Star on GitHub.",
+ "thanks": "Your support means a lot to us.",
"action": "Star on GitHub",
- "later": "Not now",
- "never": "Don’t ask again",
+ "later": "Maybe later",
+ "never": "Don't ask again",
"saveError": "There may be a network issue. This reminder may appear again."
},
"app": {
diff --git a/webui/src/i18n/locales/es/common.json b/webui/src/i18n/locales/es/common.json
index c35aa3197..816f8e319 100644
--- a/webui/src/i18n/locales/es/common.json
+++ b/webui/src/i18n/locales/es/common.json
@@ -31,10 +31,12 @@
},
"starPrompt": {
"footerAction": "Dale una estrella a nanobot",
- "title": "Gracias por usar nanobot",
- "description": "Danos una estrella en GitHub para ayudarnos a seguir mejorando nanobot.",
+ "title": "Nos alegra poder ayudarte.",
+ "intro": "Si nanobot te hace el día a día un poco más fácil,",
+ "invitation": "nos encantaría recibir tu estrella en GitHub.",
+ "thanks": "Ese pequeño gesto significa mucho para nosotros.",
"action": "Dar una estrella",
- "later": "Ahora no",
+ "later": "Quizá luego",
"never": "No volver a preguntar",
"saveError": "Puede que haya un problema de conexión. Este recordatorio podría volver a aparecer."
},
diff --git a/webui/src/i18n/locales/fr/common.json b/webui/src/i18n/locales/fr/common.json
index 32ad52b79..d812136b0 100644
--- a/webui/src/i18n/locales/fr/common.json
+++ b/webui/src/i18n/locales/fr/common.json
@@ -31,11 +31,13 @@
},
"starPrompt": {
"footerAction": "Ajouter une étoile à nanobot",
- "title": "Merci d’utiliser nanobot",
- "description": "Ajoutez une étoile sur GitHub pour nous aider à continuer à améliorer nanobot.",
- "action": "Mettre une étoile",
- "later": "Pas maintenant",
- "never": "Ne plus demander",
+ "title": "Ravis de vous aider.",
+ "intro": "Si nanobot vous simplifie un peu le quotidien,",
+ "invitation": "offrez-nous une étoile sur GitHub.",
+ "thanks": "Ce petit encouragement compte beaucoup pour nous.",
+ "action": "Offrir une étoile",
+ "later": "Plus tard",
+ "never": "Ne plus me le proposer",
"saveError": "Il y a peut-être un problème de connexion. Ce rappel pourrait réapparaître."
},
"app": {
diff --git a/webui/src/i18n/locales/id/common.json b/webui/src/i18n/locales/id/common.json
index 82e3ad843..8b86464a9 100644
--- a/webui/src/i18n/locales/id/common.json
+++ b/webui/src/i18n/locales/id/common.json
@@ -31,11 +31,13 @@
},
"starPrompt": {
"footerAction": "Beri bintang untuk nanobot",
- "title": "Terima kasih telah menggunakan nanobot",
- "description": "Beri bintang di GitHub untuk membantu kami terus menyempurnakan nanobot.",
+ "title": "Senang bisa membantu.",
+ "intro": "Kalau nanobot membuat harimu sedikit lebih mudah,",
+ "invitation": "yuk, beri kami bintang di GitHub.",
+ "thanks": "Dukungan kecilmu sangat berarti bagi kami.",
"action": "Beri bintang",
- "later": "Tidak sekarang",
- "never": "Jangan tanyakan lagi",
+ "later": "Lain kali",
+ "never": "Jangan ingatkan lagi",
"saveError": "Mungkin ada masalah jaringan. Pengingat ini mungkin muncul lagi."
},
"app": {
diff --git a/webui/src/i18n/locales/ja/common.json b/webui/src/i18n/locales/ja/common.json
index fd7525345..556ea9353 100644
--- a/webui/src/i18n/locales/ja/common.json
+++ b/webui/src/i18n/locales/ja/common.json
@@ -31,11 +31,13 @@
},
"starPrompt": {
"footerAction": "nanobot にスターを付ける",
- "title": "nanobot のご利用ありがとうございます",
- "description": "GitHub でスターを付けて、nanobot をより良くしていく取り組みを応援してください。",
- "action": "スターを付ける",
- "later": "今はしない",
- "never": "今後表示しない",
+ "title": "お役に立てて、うれしいです。",
+ "intro": "nanobot で毎日が少しでも楽になったら、",
+ "invitation": "GitHub で Star をいただけるとうれしいです。",
+ "thanks": "その小さな応援が、私たちの励みになります。",
+ "action": "Star で応援する",
+ "later": "また今度",
+ "never": "今後は表示しない",
"saveError": "ネットワークに問題が発生した可能性があります。この案内が再び表示されることがあります。"
},
"app": {
diff --git a/webui/src/i18n/locales/ko/common.json b/webui/src/i18n/locales/ko/common.json
index 8206f5e8c..1695bc995 100644
--- a/webui/src/i18n/locales/ko/common.json
+++ b/webui/src/i18n/locales/ko/common.json
@@ -31,11 +31,13 @@
},
"starPrompt": {
"footerAction": "nanobot에 스타 남기기",
- "title": "nanobot을 사용해 주셔서 감사합니다",
- "description": "GitHub에서 스타를 눌러 nanobot을 계속 개선할 수 있도록 응원해 주세요.",
- "action": "스타 남기기",
- "later": "나중에",
- "never": "다시 표시하지 않기",
+ "title": "도움이 되어 기뻐요.",
+ "intro": "nanobot 덕분에 일상이 조금 더 편해졌다면,",
+ "invitation": "GitHub에 Star 하나 남겨 주세요.",
+ "thanks": "작은 응원이 저희에겐 큰 힘이 돼요.",
+ "action": "Star로 응원하기",
+ "later": "다음에 할게요",
+ "never": "다시 보지 않기",
"saveError": "네트워크에 문제가 있는 것 같습니다. 이 알림이 다시 표시될 수 있습니다."
},
"app": {
diff --git a/webui/src/i18n/locales/pt-BR/common.json b/webui/src/i18n/locales/pt-BR/common.json
index c47daeb3b..0225d5657 100644
--- a/webui/src/i18n/locales/pt-BR/common.json
+++ b/webui/src/i18n/locales/pt-BR/common.json
@@ -31,11 +31,13 @@
},
"starPrompt": {
"footerAction": "Dê uma estrela ao nanobot",
- "title": "Obrigado por usar o nanobot",
- "description": "Dê uma estrela no GitHub para nos ajudar a continuar melhorando o nanobot.",
+ "title": "Que bom poder ajudar.",
+ "intro": "Se o nanobot deixou seu dia a dia um pouco mais leve,",
+ "invitation": "que tal deixar uma estrela no GitHub?",
+ "thanks": "Esse pequeno gesto significa muito para nós.",
"action": "Dar uma estrela",
- "later": "Agora não",
- "never": "Não perguntar novamente",
+ "later": "Mais tarde",
+ "never": "Não perguntar de novo",
"saveError": "Pode haver um problema de conexão. Este lembrete pode aparecer novamente."
},
"app": {
diff --git a/webui/src/i18n/locales/vi/common.json b/webui/src/i18n/locales/vi/common.json
index 320ed2e36..446963c61 100644
--- a/webui/src/i18n/locales/vi/common.json
+++ b/webui/src/i18n/locales/vi/common.json
@@ -31,10 +31,12 @@
},
"starPrompt": {
"footerAction": "Tặng nanobot một sao",
- "title": "Cảm ơn bạn đã dùng nanobot",
- "description": "Hãy tặng một sao trên GitHub để ủng hộ chúng tôi tiếp tục cải thiện nanobot.",
- "action": "Tặng sao",
- "later": "Để sau",
+ "title": "Thật vui khi giúp được bạn.",
+ "intro": "Nếu nanobot giúp mỗi ngày của bạn nhẹ nhàng hơn một chút,",
+ "invitation": "hãy tặng chúng mình một sao trên GitHub nhé.",
+ "thanks": "Sự động viên nhỏ ấy có ý nghĩa rất lớn với chúng mình.",
+ "action": "Tặng một sao",
+ "later": "Để lần sau",
"never": "Không nhắc lại",
"saveError": "Có thể đã xảy ra sự cố mạng. Lời nhắc này có thể xuất hiện lại."
},
diff --git a/webui/src/i18n/locales/zh-CN/common.json b/webui/src/i18n/locales/zh-CN/common.json
index a05b724ed..ca3aeb500 100644
--- a/webui/src/i18n/locales/zh-CN/common.json
+++ b/webui/src/i18n/locales/zh-CN/common.json
@@ -31,10 +31,12 @@
},
"starPrompt": {
"footerAction": "给 nanobot 点个 Star",
- "title": "感谢使用 nanobot",
- "description": "欢迎来 GitHub 点个 Star,支持我们继续改进。",
- "action": "点个 Star",
- "later": "暂时不了",
+ "title": "很高兴,能帮上你的忙。",
+ "intro": "如果 nanobot 让你的日常轻松了一点,",
+ "invitation": "欢迎在 GitHub 留下一颗 Star。",
+ "thanks": "这份小小的鼓励,我们会认真珍惜。",
+ "action": "去点颗 Star",
+ "later": "下次再说",
"never": "不再提醒",
"saveError": "网络可能出了点问题,之后可能还会弹出此提醒。"
},
diff --git a/webui/src/i18n/locales/zh-TW/common.json b/webui/src/i18n/locales/zh-TW/common.json
index c658d0c7f..60819a52e 100644
--- a/webui/src/i18n/locales/zh-TW/common.json
+++ b/webui/src/i18n/locales/zh-TW/common.json
@@ -31,10 +31,12 @@
},
"starPrompt": {
"footerAction": "給 nanobot 一顆 Star",
- "title": "感謝使用 nanobot",
- "description": "歡迎到 GitHub 給顆 Star,支持我們持續改進。",
- "action": "給個 Star",
- "later": "暫時不用",
+ "title": "很高興,能幫上你的忙。",
+ "intro": "如果 nanobot 讓你的日常輕鬆了一點,",
+ "invitation": "歡迎在 GitHub 留下一顆 Star。",
+ "thanks": "這份小小的鼓勵,我們會認真珍惜。",
+ "action": "去點顆 Star",
+ "later": "下次再說",
"never": "不再提醒",
"saveError": "網路可能出了點問題,之後可能還會跳出此提醒。"
},
diff --git a/webui/src/tests/star-prompt.test.tsx b/webui/src/tests/star-prompt.test.tsx
index 0b009a946..9855353a7 100644
--- a/webui/src/tests/star-prompt.test.tsx
+++ b/webui/src/tests/star-prompt.test.tsx
@@ -1,9 +1,11 @@
import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import { StarLink, StarPrompt } from "@/components/StarPrompt";
import { starPromptAction } from "@/lib/api";
import i18n from "@/i18n";
+import { supportedLocales } from "@/i18n/config";
vi.mock("@/lib/api", () => ({ starPromptAction: vi.fn() }));
const client = {
@@ -27,8 +29,8 @@ async function enter() {
it("claims once on entry and lets users skip without permanently dismissing", async () => {
const view = render(<StarPrompt ready />);
await enter();
- expect(screen.getByRole("dialog")).toHaveAccessibleName("Thanks for using nanobot");
- fireEvent.click(screen.getByRole("button", { name: "Not now" }));
+ expect(screen.getByRole("dialog")).toHaveAccessibleName("Glad we could help.");
+ fireEvent.click(screen.getByRole("button", { name: "Maybe later" }));
view.rerender(<StarPrompt ready />);
await enter();
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
@@ -77,10 +79,10 @@ it("keeps a failed permanent dismissal retryable", async () => {
render(<StarPrompt ready />);
await enter();
action.mockRejectedValueOnce(new Error("offline"));
- await act(async () => fireEvent.click(screen.getByRole("button", { name: "Don’t ask again" })));
+ await act(async () => fireEvent.click(screen.getByRole("button", { name: "Don't ask again" })));
expect(screen.getByRole("alert")).toHaveTextContent("There may be a network issue. This reminder may appear again.");
expect(screen.getByRole("dialog")).toBeVisible();
- await act(async () => fireEvent.click(screen.getByRole("button", { name: "Don’t ask again" })));
+ await act(async () => fireEvent.click(screen.getByRole("button", { name: "Don't ask again" })));
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
expect(action).toHaveBeenLastCalledWith(client, "dismiss");
});
@@ -106,7 +108,78 @@ it("waits for the initial connection and still attempts only once", async () =>
expect(action).not.toHaveBeenCalled();
await act(async () => statusChanged("open"));
expect(screen.getByRole("dialog")).toBeVisible();
- fireEvent.click(screen.getByRole("button", { name: "Not now" }));
+ fireEvent.click(screen.getByRole("button", { name: "Maybe later" }));
await act(async () => statusChanged("open"));
expect(action).toHaveBeenCalledTimes(1);
});
+
+it.each(supportedLocales.map(({ code }) => code))("localizes the complete invitation in %s", async (locale) => {
+ await i18n.changeLanguage(locale);
+ render(<StarPrompt ready />);
+ await enter();
+ expect(screen.getByRole("dialog")).toHaveAccessibleName(i18n.t("starPrompt.title"));
+ expect(screen.getByRole("dialog")).toHaveAccessibleDescription([
+ i18n.t("starPrompt.intro"), i18n.t("starPrompt.invitation"), i18n.t("starPrompt.thanks"),
+ ].join(" "));
+ expect(screen.getByRole("button", { name: i18n.t("starPrompt.later") })).toBeVisible();
+ expect(screen.getByRole("button", { name: i18n.t("starPrompt.never") })).toBeVisible();
+ expect(screen.getByRole("button", { name: i18n.t("common.close"), exact: true })).toBeVisible();
+ expect(screen.getByRole("link", { name: i18n.t("starPrompt.action") })).toHaveAttribute("rel", "noopener noreferrer");
+});
+
+it.each(["close button", "Escape"])("restores focus after %s without permanently dismissing", async (method) => {
+ const user = userEvent.setup();
+ const view = render(<><button>Previous control</button><StarPrompt ready={false} /></>);
+ screen.getByRole("button", { name: "Previous control" }).focus();
+ view.rerender(<><button>Previous control</button><StarPrompt ready /></>);
+ await enter();
+ expect(screen.getByRole("heading", { name: "Glad we could help." })).toHaveFocus();
+ if (method === "Escape") await user.keyboard("{Escape}");
+ else await user.click(screen.getByRole("button", { name: "Close", exact: true }));
+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
+ expect(screen.getByRole("button", { name: "Previous control" })).toHaveFocus();
+ expect(action).toHaveBeenCalledTimes(1);
+});
+
+it("keeps the illustration decorative and actions usable if it fails to load", async () => {
+ const view = render(<StarPrompt ready={false} />);
+ expect(document.querySelector("img")).toBeNull();
+ view.rerender(<StarPrompt ready />);
+ await enter();
+ const artwork = screen.getByRole("dialog").querySelector("img")!;
+ expect(artwork).toHaveAttribute("alt", "");
+ expect(artwork).toHaveAttribute("width", "1672");
+ expect(artwork).toHaveAttribute("height", "941");
+ expect(artwork.getAttribute("src")).toContain("star-invitation");
+ fireEvent.error(artwork);
+ fireEvent.click(screen.getByRole("button", { name: "Maybe later" }));
+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
+});
+
+it("keeps the GitHub action a real link and retries failed preference saves", async () => {
+ render(<StarPrompt ready />);
+ await enter();
+ const link = screen.getByRole("link", { name: "Star on GitHub" });
+ expect(link).toHaveAttribute("href", "https://github.com/HKUDS/nanobot");
+ expect(link).toHaveAttribute("target", "_blank");
+ expect(link.querySelector(".star-prompt-decoration")).toHaveAttribute("aria-hidden", "true");
+ action.mockRejectedValueOnce(new Error("offline"));
+ await act(async () => fireEvent.click(link));
+ expect(screen.getByRole("alert")).toBeVisible();
+ expect(screen.getByRole("dialog")).toBeVisible();
+ await act(async () => fireEvent.click(link));
+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
+ expect(action.mock.calls.map(([, command]) => command)).toEqual(["claim", "dismiss", "dismiss"]);
+});
+
+it.each([false, true])("preserves middle-click dismissal for the GitHub link (fullWidth: %s)", async (fullWidth) => {
+ const saved = vi.fn();
+ render(<StarLink fullWidth={fullWidth} onSaved={saved} />);
+ const link = screen.getByRole("link");
+ await act(async () => fireEvent(link, new MouseEvent("auxclick", { bubbles: true, button: 2 })));
+ expect(action).not.toHaveBeenCalled();
+ await act(async () => fireEvent(link, new MouseEvent("auxclick", { bubbles: true, button: 1 })));
+ expect(action).toHaveBeenCalledWith(client, "dismiss");
+ expect(saved).toHaveBeenCalledTimes(1);
+ if (!fullWidth) expect(link.querySelector(".star-prompt-decoration")).toBeNull();
+});