From 105e8b237ff48f3ef9177dca0461b3b87dfdf8db Mon Sep 17 00:00:00 2001
From: "Bingxi Zhao (Frank)" <13051345080@163.com>
Date: Sun, 27 Sep 2026 05:01:54 +0800
Subject: [PATCH] fix(web): replace native title hints in question bank and
reading workspace (#1526)
---
.../reading/workspace/ReadAloudButton.tsx | 99 +++++++-------
.../reading/workspace/ReadingActionCards.tsx | 20 +--
.../reading/workspace/ReadingComposer.tsx | 20 +--
.../reading/workspace/ReadingWorkspace.tsx | 128 +++++++++---------
.../reading/workspace/SourceNavigator.tsx | 20 +--
.../reading/workspace/WorkspaceMenu.tsx | 24 ++--
.../space/question-bank/BankSelectionBar.tsx | 19 +--
.../space/question-bank/BankToolbar.tsx | 45 +++---
.../space/question-bank/CategoryManager.tsx | 104 +++++++-------
.../space/question-bank/CategoryMenu.tsx | 72 +++++-----
.../space/question-bank/QuestionCard.tsx | 91 +++++++------
web/tests/native-button-title-baseline.json | 92 +++++++++++++
web/tests/native-button-title.test.ts | 94 +++++++++++++
web/tests/question-bank-tooltips.spec.tsx | 33 +++++
14 files changed, 565 insertions(+), 296 deletions(-)
create mode 100644 web/tests/native-button-title-baseline.json
create mode 100644 web/tests/native-button-title.test.ts
create mode 100644 web/tests/question-bank-tooltips.spec.tsx
diff --git a/web/components/reading/workspace/ReadAloudButton.tsx b/web/components/reading/workspace/ReadAloudButton.tsx
index ce7bded56..e48505f06 100644
--- a/web/components/reading/workspace/ReadAloudButton.tsx
+++ b/web/components/reading/workspace/ReadAloudButton.tsx
@@ -4,6 +4,7 @@ import { ListChecks, Loader2, Sparkles, Square, Volume2 } from "lucide-react";
import { useTranslation } from "react-i18next";
import { useReadingActions } from "@/components/reading/reading-actions-context";
+import Tooltip from "@/shared/ui/Tooltip";
const READ_ALOUD_KEY = "read_aloud:read";
@@ -26,29 +27,30 @@ export function ReadAloudButton({ disabled }: { disabled?: boolean }) {
? t("Stop reading aloud")
: t("Read this page aloud");
return (
-
+
diff --git a/web/components/reading/workspace/ReadingComposer.tsx b/web/components/reading/workspace/ReadingComposer.tsx index 0d028facf..6aea99c03 100644 --- a/web/components/reading/workspace/ReadingComposer.tsx +++ b/web/components/reading/workspace/ReadingComposer.tsx @@ -29,6 +29,7 @@ import { } from "@/lib/ask-user-state"; import { notify } from "@/lib/notifications"; import { setReadingViewport } from "@/lib/reading-turn-state"; +import Tooltip from "@/shared/ui/Tooltip"; export function ReadingComposer({ placeholder, @@ -188,15 +189,16 @@ function QuotedPassage({{quote}
- ++ + ); } diff --git a/web/components/reading/workspace/ReadingWorkspace.tsx b/web/components/reading/workspace/ReadingWorkspace.tsx index 0ebe8edaf..e477153ed 100644 --- a/web/components/reading/workspace/ReadingWorkspace.tsx +++ b/web/components/reading/workspace/ReadingWorkspace.tsx @@ -4,6 +4,7 @@ import { scopedUrl } from "@/lib/workspace-scope"; import { READING_HOME, readingFolderRoute, readingSessionIdFromPath } from "@/lib/learning-routes"; import { browserStorage } from "@/shared/storage"; +import Tooltip from "@/shared/ui/Tooltip"; import Link from "next/link"; import dynamic from "next/dynamic"; @@ -491,39 +492,44 @@ export function ReadingWorkspacePage() { {/* The outline opens on the left, so its switch lives on the left: it sat at the far right, next to the companion's, and a learner had to guess which of two panel icons was which. */} - - - ++ + + ++ + + ++ + {notice && ( @@ -538,24 +544,23 @@ export function ReadingWorkspacePage() { /> {/* An icon, like every other control on this bar: as the only labelled button it read as the page's primary action. */} - +{expanded && ( diff --git a/web/components/reading/workspace/WorkspaceMenu.tsx b/web/components/reading/workspace/WorkspaceMenu.tsx index aba3b9976..ee7ced5ea 100644 --- a/web/components/reading/workspace/WorkspaceMenu.tsx +++ b/web/components/reading/workspace/WorkspaceMenu.tsx @@ -10,6 +10,7 @@ import { type WorkspaceMenuSection, } from "@/components/reading/workspace-menu-context"; import { MenuItem } from "./WorkspaceChrome"; +import Tooltip from "@/shared/ui/Tooltip"; export type WorkspaceMenuSections = Partial< Record+ + - - + + + )} - ++ + @@ -69,17 +70,18 @@ export function WorkspaceMenu({ return ( - +- ++ + {open && ( <>setOpen(false)} /> diff --git a/web/components/space/question-bank/BankSelectionBar.tsx b/web/components/space/question-bank/BankSelectionBar.tsx index bf741b429..5fd422698 100644 --- a/web/components/space/question-bank/BankSelectionBar.tsx +++ b/web/components/space/question-bank/BankSelectionBar.tsx @@ -5,6 +5,7 @@ import { CheckSquare, FolderMinus, X } from "lucide-react"; import type { NotebookCategory } from "@/lib/notebook-api"; import CategoryMenu from "./CategoryMenu"; import type { BankScope } from "./useQuestionBank"; +import Tooltip from "@/shared/ui/Tooltip"; interface BankSelectionBarProps { count: number; @@ -79,14 +80,16 @@ export default function BankSelectionBar({ )} - +); } diff --git a/web/components/space/question-bank/BankToolbar.tsx b/web/components/space/question-bank/BankToolbar.tsx index 6132c95e7..166e7c9a3 100644 --- a/web/components/space/question-bank/BankToolbar.tsx +++ b/web/components/space/question-bank/BankToolbar.tsx @@ -14,6 +14,7 @@ import type { ScoreTrend, } from "@/lib/notebook-api"; import type { BankSort, ReviewFilters } from "./useQuestionBank"; +import Tooltip from "@/shared/ui/Tooltip"; interface BankToolbarProps { search: string; @@ -61,28 +62,33 @@ export default function BankToolbar({ {refreshing ? (+ + ) : search ? ( - + + + + + ) : null}+ + - - ++ + ++ + > ) : ( <> @@ -101,37 +106,41 @@ export default function CategoryManager({ {category.entry_count} - - + > )} @@ -161,6 +170,7 @@ export default function CategoryManager({void run(() => onCreate(newName)).then((ok) => { if (ok) setNewName(""); diff --git a/web/components/space/question-bank/CategoryMenu.tsx b/web/components/space/question-bank/CategoryMenu.tsx index 8ac2f3987..32144b868 100644 --- a/web/components/space/question-bank/CategoryMenu.tsx +++ b/web/components/space/question-bank/CategoryMenu.tsx @@ -5,6 +5,7 @@ import { useTranslation } from "react-i18next"; import { Check, FolderPlus, Loader2, Plus } from "lucide-react"; import { notify } from "@/lib/notifications"; import type { NotebookCategory } from "@/lib/notebook-api"; +import Tooltip from "@/shared/ui/Tooltip"; interface CategoryMenuProps { categories: NotebookCategory[]; @@ -105,26 +106,29 @@ export default function CategoryMenu({ return ( -)} diff --git a/web/components/space/question-bank/QuestionCard.tsx b/web/components/space/question-bank/QuestionCard.tsx index c44f8197f..75411dfe2 100644 --- a/web/components/space/question-bank/QuestionCard.tsx +++ b/web/components/space/question-bank/QuestionCard.tsx @@ -18,6 +18,7 @@ import { optionIsAnswer } from "@/lib/question-bank-answers"; import { bookRoute, masterySessionRoute } from "@/lib/learning-routes"; import CategoryMenu from "./CategoryMenu"; import { practiceMarkdown } from "@/lib/practice-content"; +import Tooltip from "@/shared/ui/Tooltip"; const SOURCE_LABELS: RecordsetOpen((v) => !v)} - title={t("Add tag")} - className={`inline-flex items-center gap-1.5 rounded-lg text-[11.5px] font-medium transition-colors disabled:opacity-40 ${ - variant === "outlined" ? "border px-2 py-1.5" : "p-1.5" - } ${ - open - ? variant === "outlined" - ? "border-[var(--primary)]/40 bg-[var(--primary)]/10 text-[var(--primary)]" - : "bg-[var(--muted)]/60 text-[var(--primary)]" - : variant === "outlined" - ? "border-[var(--border)] text-[var(--muted-foreground)] hover:bg-[var(--muted)]/60 hover:text-[var(--foreground)]" - : "text-[var(--muted-foreground)] hover:bg-[var(--muted)]/60 hover:text-[var(--foreground)]" - }`} - > - +- {label ? {label} : null} - + {open && ( -setOpen((v) => !v)} + aria-label={label || t("Add tag")} + aria-expanded={open} + className={`inline-flex items-center gap-1.5 rounded-lg text-[11.5px] font-medium transition-colors disabled:opacity-40 ${ + variant === "outlined" ? "border px-2 py-1.5" : "p-1.5" + } ${ + open + ? variant === "outlined" + ? "border-[var(--primary)]/40 bg-[var(--primary)]/10 text-[var(--primary)]" + : "bg-[var(--muted)]/60 text-[var(--primary)]" + : variant === "outlined" + ? "border-[var(--border)] text-[var(--muted-foreground)] hover:bg-[var(--muted)]/60 hover:text-[var(--foreground)]" + : "text-[var(--muted-foreground)] hover:bg-[var(--muted)]/60 hover:text-[var(--foreground)]" + }`} + > + ++ {label ? {label} : null} + void handleCreate()} - title={t("Create and add")} - className="shrink-0 rounded-lg bg-[var(--primary)] p-1.5 text-white transition-opacity disabled:opacity-30" - > - {busy ? ( - +- ) : ( - - )} - + void handleCreate()} + aria-label={t("Create and add")} + className="shrink-0 rounded-lg bg-[var(--primary)] p-1.5 text-white transition-opacity disabled:opacity-30" + > + {busy ? ( + ++ ) : ( + + )} + = { deep_question: "Deep Question", @@ -286,47 +287,53 @@ export default function QuestionCard({ onUnpick={onUnfile} onCreate={onCreateAndFile} /> - - - {showReviewState && ( +- + {showReviewState && ( + - {entry.resolved ? ( - +- ) : ( - - )} + + )} -+ {entry.resolved ? ( + ++ ) : ( + + )} + - +- + @@ -466,15 +473,17 @@ export default function QuestionCard({ className="inline-flex items-center gap-1 rounded-md border border-[var(--border)] bg-[var(--muted)]/40 py-0.5 pl-2 pr-1 text-[var(--muted-foreground)]" > {category.name} -+ ++ void onUnfile(category.id)} - disabled={disabled} - title={t("Remove tag")} - className="rounded p-0.5 transition-colors hover:bg-[var(--muted)] hover:text-[var(--foreground)] disabled:opacity-40" - > - +- + ))} {hasConversationSession && entry.source !== "import" && ( diff --git a/web/tests/native-button-title-baseline.json b/web/tests/native-button-title-baseline.json new file mode 100644 index 000000000..25c93cfa7 --- /dev/null +++ b/web/tests/native-button-title-baseline.json @@ -0,0 +1,92 @@ +{ + "app/(admin)/admin/users/page.tsx": ["2062b4d5ddb4c30d","472e77d1046643e1","5db5f4b744aa129d"], + "app/(utility)/session-handoff/page.tsx": ["ea0758b3abef58d5"], + "app/(workspace)/co-writer/page.tsx": ["c4b460087174c7d1"], + "app/(workspace)/kanban/page.tsx": ["9fbc9c11a1180034","a7565e650e5aba54","aeccd7575e9820b7"], + "app/(workspace)/learning/books/components/BookChatPanel.tsx": ["4dd0ddd866978e50"], + "app/(workspace)/learning/books/components/BookCreator.tsx": ["4a81c6dfb255ee77"], + "app/(workspace)/learning/books/components/BookHealthBanner.tsx": ["39044f87184bce61","805a5d47c999eaea"], + "app/(workspace)/learning/books/components/BookLibrary.tsx": ["94d4fce96270ab32"], + "app/(workspace)/learning/books/components/BookSidebar.tsx": ["5cc9cef7cc744776","9726d994424b74b4","a0e52ce02849fb58","fa3b55fb791ae302"], + "app/(workspace)/learning/books/components/LearningCapturePanel.tsx": ["f263bc4350540dcf"], + "app/(workspace)/learning/books/components/PageOutlineNav.tsx": ["438c97f8d456752d","542eab7e9945df98"], + "app/(workspace)/learning/books/components/PageReader.tsx": ["451d97ffd70b2cce","53b7fc0beb53cf4d","9a0ebb5a90deee8e"], + "app/(workspace)/learning/books/components/blocks/BlockRenderer.tsx": ["104d0957f4b4f517","40a02aeb89b2f7ab","48d62d6823995f15","6a981344f3174a7c","76e9fa63f5b286ff","f2109d5b66da4b67"], + "app/(workspace)/learning/books/components/blocks/DeepDiveBlock.tsx": ["085a7b26057b8828"], + "app/(workspace)/learning/books/components/blocks/UserNoteBlock.tsx": ["94600886694d29f8"], + "app/(workspace)/partners/[partnerId]/page.tsx": ["087215314c6987da","504883adb4c02e80","550e828ba3bbf720","5cdc5fa3c2a39503","67d0cac91be25bd1","e6e304c6f49e7795"], + "app/(workspace)/partners/groups/[groupId]/page.tsx": ["aefb4192588e78e5"], + "components/agents/ConnectedAgents.tsx": ["8d1b1b9a9ab7f1d3"], + "components/auth/LogoutButton.tsx": ["fe803f9f9c035c7b"], + "components/chat/MyAgentsPicker.tsx": ["9de41a24dfd55c5a"], + "components/chat/home/ChatComposer.tsx": ["8a2e4aeb0d05841e","b9d19f8a62dbe1dc","c4cdd71599b0a6e5"], + "components/chat/home/ComposerRail.tsx": ["064d6f5464f66ecc"], + "components/chat/home/ModelSelector.tsx": ["3152db27d320353d","9cfe996e2a7ef139","da77f8a2bb413fd7"], + "components/chat/home/SelectedResources.tsx": ["104c56119ad6d653"], + "components/chat/home/SessionActivityPanel.tsx": ["c4e6fa254275dd34"], + "components/chat/home/SessionViewerPanel.tsx": ["3fbe3782aa64cd06","50553880b9e5710c","6df6a6968069c06d","7457e0cbd0b881b9"], + "components/chat/home/StarterSuggestions.tsx": ["31b4f8d5b0483a5e"], + "components/chat/preview/FilePreviewDrawer.tsx": ["4a8b532fc93d841e","801709683650aed7","a6508430d1c2c5b0"], + "components/chat/preview/previewers/XlsxPreview.tsx": ["644e66fec714a278"], + "components/cli-apps/CliAppsSection.tsx": ["4297890756842a8d"], + "components/common/GeogebraOpenCTA.tsx": ["c922f34a7cbab6fc"], + "components/knowledge/CreateKbModal.tsx": ["f0b47e25abfa183a"], + "components/knowledge/FileDropZone.tsx": ["b090b69445b9626c"], + "components/knowledge/KbDocumentList.tsx": ["0cb9a2f0be64dc21","22f74a32c8edf442","2d2d8d0a367709a3","9e8b922f0bd9649e","c70d02d3d88edea7","cf62e1c80305f6d2","d586e779faf3fe93","e1b1b9985a06297e","e9ab1ad073047aec","f493f2282f2d952c"], + "components/knowledge/KbFilePreview.tsx": ["3fcd4dcde9a8c49f","74872960f708a6a5","74872960f708a6a5","d899aee2a951ffda"], + "components/knowledge/KbGitHubSourcesSection.tsx": ["a45507814306d2b0"], + "components/knowledge/KbIndexVersionsSection.tsx": ["cca712cf150b8e34"], + "components/knowledge/KbLinkedFoldersSection.tsx": ["02bdc6724cac8ecb","0e03400573df5031","5a86fb5a135080df"], + "components/knowledge/KbUpdateHistory.tsx": ["16f6d96751e34943"], + "components/knowledge/KbWebSourcesSection.tsx": ["05e0e41adba1dff1","36c0e1d57f9215fe","5432c20c4bd61669"], + "components/knowledge/KnowledgeBaseDetail.tsx": ["3a15884928eef782"], + "components/learning/practice/PracticeInsights.tsx": ["3b4b2336e855eea4"], + "components/memory/MemoryRunPanel.tsx": ["060a159e01bddd43","4e6edc77c87d1d60","55172231371dae47","6af569ad63057100","c6f3fe36c916e65c","d99a915c7452ea52"], + "components/memory/MemorySection.tsx": ["607d03f9841c16ed","607d03f9841c16ed","8ef98453cb691350"], + "components/notebook/NotebookConsole.tsx": ["ce6e5b9219b029ca"], + "components/notebook/NotebookRecordRow.tsx": ["224834fc8c082451"], + "components/partners/AssetPicker.tsx": ["ce740dd43aa500fe"], + "components/partners/PartnerArchives.tsx": ["58540567c02eb130","73792ac6d7f0e598","857df68488445e96"], + "components/partners/PartnerChannels.tsx": ["4e6c301b7c8893de"], + "components/partners/PartnerComposer.tsx": ["4dd0ddd866978e50","89c6cfcb9ec5af55"], + "components/partners/SoulPicker.tsx": ["d89d6e61f57764c9"], + "components/partners/group/GroupComposer.tsx": ["ab299ea7f4504c51","b6d0dbdef35684e7"], + "components/partners/group/GroupSessionPicker.tsx": ["bb3aae75b685744f"], + "components/partners/group/PartnerSeat.tsx": ["04e2114ac19fdaf5","c5e52a4103c00279"], + "components/partners/schema-form.tsx": ["7cf112e40158bc18"], + "components/quiz/QuizConfigPanel.tsx": ["6cfc3e0690b46adb","f52fe91070af5cb1"], + "components/quiz/QuizViewer.tsx": ["10fe5ac34f0e5b5c","155eb455409f5fee","5914ded12426314c","68d30d274f1cfd3f","867faa22062895ed","f34db87829bd639a"], + "components/reading/AnnotationLayer.tsx": ["2ea1d9af29459edb"], + "components/reading/AnnotationList.tsx": ["9f2a45a2887e1a3f"], + "components/reading/ReaderDisplayControls.tsx": ["f7ceaa362f776884"], + "components/reading/ReaderPane.tsx": ["5287ce04aaaee4f8","f7ceaa362f776884"], + "components/reading/ReadingExtensionBar.tsx": ["090161977d5e7acf","b03082aae3a3777b"], + "components/reading/library/FolderDialog.tsx": ["289f0e3e0693cd09"], + "components/reading/library/ReadingFolder.tsx": ["314253c02a6ff29a","79a4406eb0165bf7"], + "components/reading/workspace/SourceNavigator.tsx": ["77d599c76a538534","942c1a2294e92e5a"], + "components/settings/CodeBuddyAuthCard.tsx": ["7471c9e2a8e28339"], + "components/settings/ModelsWorkspace.tsx": ["ce53e95e372ce024"], + "components/settings/ProvidersWorkspace.tsx": ["6a01d5cc51cde922"], + "components/settings/RegistryControls.tsx": ["d2e5a59d961d98ba"], + "components/settings/ServiceConfigEditor.tsx": ["8ae3f2f23cc44037"], + "components/settings/SettingsToolbar.tsx": ["66830400e0fd25e6"], + "components/space/ArchivedConversations.tsx": ["1e3aeb7319e5f65a","5f4cfea0cda04a3e"], + "components/space/MyAgentsSection.tsx": ["9d284f1f46bbdc41","df7468919c9a7ea8"], + "components/space/PersonasSection.tsx": ["1be81f8b4229bc9e","6746a68137fe2391","89ef0ac70d058a20"], + "components/space/SkillsSection.tsx": ["6581aa3354cc6d2d","6746a68137fe2391","789eee2908c10770","ad71bc1aca08d1a5","d1c86b5ddb329174"], + "components/space/learning/MasteryStudy.tsx": ["67d0cac91be25bd1"], + "components/space/learning/ModeSwitch.tsx": ["6c98276670c94312"], + "components/space/learning/PathTitle.tsx": ["142069af8906d16c","85b37242c76f46a3","ac6d10ef156c74dd"], + "components/space/learning/ReviewTrail.tsx": ["67432e520fac2bd8"], + "components/space/learning/StudyOutline.tsx": ["b61001c8756d0f9d","ea2c9a7f429a8944"], + "components/visualize/VisualizationViewer.tsx": ["b58434ec29492df8","be23e619c1d2e3e3","ed6a8d0dc50cedcc"], + "components/visualize/VisualizeConfigPanel.tsx": ["1927f8cc6fe4ecb1"], + "components/workspaces/WorkspaceChatGroups.tsx": ["c3c3c760376dc6d6"], + "components/workspaces/WorkspacePill.tsx": ["30841304e8b58ccc","53da125ababd5a38","c3990b73bc43d246"], + "features/chat/components/ChatWorkspace.tsx": ["01c3aa61603e3336"], + "features/co-writer/components/CoWriterWorkspace.tsx": ["0219f3bd0cfce757","369bed5cfffcda93","53f44662b8d95095","ab73950bcdb666a5","b34363d5acaef69f","c8340c792e0fc256","d4b48fe0bd46c01d","e66eeeac83db6144"], + "features/settings/components/UsageActivity.tsx": ["044bb0f681e7b117"], + "features/settings/sections/ArchivedChatsSettingsSection.tsx": ["3b6ca9ed135e8910"], + "features/settings/sections/ToolsSettingsSection.tsx": ["89d0d5d67ee69c8f"], + "features/settings/sections/WorkspaceSettingsSection.tsx": ["8ddce9eae1d2450c","be4c3b734823542f","e71d8dc6e998551d"] +} diff --git a/web/tests/native-button-title.test.ts b/web/tests/native-button-title.test.ts new file mode 100644 index 000000000..f7927487b --- /dev/null +++ b/web/tests/native-button-title.test.ts @@ -0,0 +1,94 @@ +import assert from "node:assert/strict"; +import { createHash } from "node:crypto"; +import { readFileSync, readdirSync } from "node:fs"; +import path from "node:path"; +import test from "node:test"; +import ts from "typescript"; + +type TitleDebt = Recordvoid onUnfile(category.id)} + disabled={disabled} + aria-label={t("Remove tag")} + className="rounded p-0.5 transition-colors hover:bg-[var(--muted)] hover:text-[var(--foreground)] disabled:opacity-40" + > + ++ ; + +const root = process.cwd(); +// Existing native hints remain in this debt snapshot. Deleting one needs no +// fixture update; adding one fails even when another file was cleaned up. +const baseline: TitleDebt = JSON.parse( + readFileSync(path.join(root, "tests/native-button-title-baseline.json"), "utf8"), +); + +function sourceFiles(directory: string): string[] { + return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => { + const file = path.join(directory, entry.name); + if (entry.isDirectory()) return sourceFiles(file); + return entry.name.endsWith(".tsx") ? [file] : []; + }); +} + +function attribute( + node: ts.JsxOpeningElement | ts.JsxSelfClosingElement, + name: string, +): ts.JsxAttribute | undefined { + return node.attributes.properties.find( + (property): property is ts.JsxAttribute => + ts.isJsxAttribute(property) && property.name.getText() === name, + ); +} + +function signature( + node: ts.JsxOpeningElement | ts.JsxSelfClosingElement, + source: ts.SourceFile, +): string { + // Ignore styling and line movement. The hint and action identify a legacy + // control; adding another control with the same pair still exceeds its + // allowed occurrence count. + const details = ["title", "onClick", "aria-label"] + .map((name) => attribute(node, name)?.initializer?.getText(source) ?? "") + .map((value) => value.replace(/\s+/g, " ").trim()) + .join("|"); + return createHash("sha256").update(details).digest("hex").slice(0, 16); +} + +test("new native button titles must use the shared Tooltip", () => { + const violations: string[] = []; + for (const sourceRoot of [ + "app", + "components", + "context", + "features", + "hooks", + "lib", + "shared", + ]) { + for (const file of sourceFiles(path.join(root, sourceRoot))) { + const relative = path.relative(root, file).split(path.sep).join("/"); + const source = ts.createSourceFile( + file, + readFileSync(file, "utf8"), + ts.ScriptTarget.Latest, + true, + ts.ScriptKind.TSX, + ); + const allowed = [...(baseline[relative] ?? [])]; + const visit = (node: ts.Node) => { + if ( + (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) && + node.tagName.getText(source) === "button" && + attribute(node, "title") + ) { + const hash = signature(node, source); + const index = allowed.indexOf(hash); + if (index >= 0) allowed.splice(index, 1); + else { + const line = source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1; + violations.push(`${relative}:${line}`); + } + } + ts.forEachChild(node, visit); + }; + visit(source); + } + } + assert.deepEqual( + violations, + [], + "Replace new hints with @/shared/ui/Tooltip and an accessible button name", + ); +}); diff --git a/web/tests/question-bank-tooltips.spec.tsx b/web/tests/question-bank-tooltips.spec.tsx new file mode 100644 index 000000000..215416ea3 --- /dev/null +++ b/web/tests/question-bank-tooltips.spec.tsx @@ -0,0 +1,33 @@ +import { fireEvent, render, screen, waitFor } from "@testing-library/react"; +import { expect, it, vi } from "vitest"; + +import CategoryManager from "@/components/space/question-bank/CategoryManager"; + +vi.mock("react-i18next", () => ({ + useTranslation: () => ({ t: (value: string) => value }), +})); + +it("names tag actions and exposes their hints without native titles", async () => { + render( + true)} + onRename={vi.fn(async () => true)} + onDelete={vi.fn(async () => true)} + />, + ); + + const rename = screen.getByRole("button", { name: "Rename" }); + expect(rename).not.toHaveAttribute("title"); + expect(document.getElementById(rename.getAttribute("aria-describedby")!)).toHaveTextContent( + "Rename", + ); + + fireEvent.focus(rename); + await waitFor(() => + expect(document.body.querySelector('[role="tooltip"].fixed')).toHaveTextContent("Rename"), + ); + fireEvent.click(rename); + expect(screen.getByRole("button", { name: "Save" })).not.toHaveAttribute("title"); + expect(screen.getByRole("button", { name: "Cancel" })).not.toHaveAttribute("title"); +});