-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: checkpoint restore popover positioning issue (#8219) #8220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
webview-ui/src/components/chat/checkpoints/__tests__/CheckpointSaved.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| // npx vitest run src/components/chat/checkpoints/__tests__/CheckpointSaved.spec.tsx | ||
|
|
||
| vi.mock("@/components/ui", () => { | ||
| // Minimal UI primitives to ensure deterministic behavior in tests | ||
| return { | ||
| Button: ({ children, ...rest }: any) => <button {...rest}>{children}</button>, | ||
| StandardTooltip: ({ children }: any) => <>{children}</>, | ||
| Popover: ({ children, onOpenChange, open }: any) => { | ||
| lastOnOpenChange = onOpenChange | ||
| return ( | ||
| <div data-testid="popover-root" data-open={open}> | ||
| {children} | ||
| </div> | ||
| ) | ||
| }, | ||
| PopoverTrigger: ({ children }: any) => <div data-testid="popover-trigger">{children}</div>, | ||
| PopoverContent: ({ children }: any) => <div data-testid="popover-content">{children}</div>, | ||
| } | ||
| }) | ||
|
|
||
| import { render, waitFor, screen } from "@/utils/test-utils" | ||
| import React from "react" | ||
| import userEvent from "@testing-library/user-event" | ||
| import { CheckpointSaved } from "../CheckpointSaved" | ||
|
|
||
| // Capture onOpenChange from Popover to control open/close in tests | ||
| let lastOnOpenChange: ((open: boolean) => void) | undefined | ||
|
|
||
| const waitForOpenHandler = async () => { | ||
| await waitFor(() => { | ||
| // ensure Popover mock captured the onOpenChange handler before using it | ||
| expect(lastOnOpenChange).toBeTruthy() | ||
| }) | ||
| } | ||
|
|
||
| describe("CheckpointSaved popover visibility", () => { | ||
| // Timers are controlled per-test to avoid interfering with i18n init | ||
| const baseProps = { | ||
| ts: 123, | ||
| commitHash: "abc123", | ||
| currentHash: "zzz999", | ||
| checkpoint: { from: "prev123", to: "abc123" } as Record<string, unknown>, | ||
| } | ||
|
|
||
| it("shows menu while popover is open and hides when closed", async () => { | ||
| const { getByTestId } = render(<CheckpointSaved {...baseProps} />) | ||
|
|
||
| const getMenu = () => getByTestId("checkpoint-menu-container") as HTMLElement | ||
|
|
||
| // Initially hidden (relies on group-hover) | ||
| expect(getMenu()).toBeTruthy() | ||
| expect(getMenu().className).toContain("hidden") | ||
|
|
||
| // Open via captured handler | ||
| await waitForOpenHandler() | ||
| lastOnOpenChange?.(true) | ||
|
|
||
| await waitFor(() => { | ||
| expect(getMenu().className).toContain("block") | ||
| expect(getMenu().className).not.toContain("hidden") | ||
| }) | ||
|
|
||
| // Close via captured handler — menu remains visible briefly, then hides | ||
| lastOnOpenChange?.(false) | ||
|
|
||
| await waitFor(() => { | ||
| expect(getMenu().className).toContain("block") | ||
| }) | ||
|
|
||
| await waitFor(() => { | ||
| expect(getMenu().className).toContain("hidden") | ||
| }) | ||
| }) | ||
|
|
||
| it("resets confirm state when popover closes", async () => { | ||
| const { getByTestId } = render(<CheckpointSaved {...baseProps} />) | ||
|
|
||
| // Open the popover | ||
| await waitForOpenHandler() | ||
| lastOnOpenChange?.(true) | ||
|
|
||
| // Enter confirm state | ||
| const restoreFilesAndTaskBtn = await waitFor(() => getByTestId("restore-files-and-task-btn")) | ||
| await userEvent.click(restoreFilesAndTaskBtn) | ||
|
|
||
| // Confirm warning should be visible | ||
| expect(getByTestId("checkpoint-confirm-warning")).toBeTruthy() | ||
|
|
||
| // Close popover -> confirm state should reset | ||
| lastOnOpenChange?.(false) | ||
|
|
||
| // Reopen | ||
| lastOnOpenChange?.(true) | ||
|
|
||
| // Confirm warning should be gone after reopening | ||
| await waitFor(() => { | ||
| expect(screen.queryByTestId("checkpoint-confirm-warning")).toBeNull() | ||
| }) | ||
| }) | ||
|
|
||
| it("closes popover after preview and after confirm restore", async () => { | ||
| const { getByTestId } = render(<CheckpointSaved {...baseProps} />) | ||
|
|
||
| const popoverRoot = () => getByTestId("popover-root") | ||
| const menuContainer = () => getByTestId("checkpoint-menu-container") | ||
|
|
||
| // Open | ||
| await waitForOpenHandler() | ||
| lastOnOpenChange?.(true) | ||
| await waitFor(() => { | ||
| expect(popoverRoot().getAttribute("data-open")).toBe("true") | ||
| expect(menuContainer().className).toContain("block") | ||
| }) | ||
|
|
||
| // Click preview -> popover closes; menu remains briefly visible, then hides | ||
| await userEvent.click(getByTestId("restore-files-btn")) | ||
| await waitFor(() => { | ||
| expect(popoverRoot().getAttribute("data-open")).toBe("false") | ||
| expect(menuContainer().className).toContain("block") | ||
| }) | ||
| await waitFor(() => { | ||
| expect(menuContainer().className).toContain("hidden") | ||
| }) | ||
|
|
||
| // Reopen | ||
| lastOnOpenChange?.(true) | ||
| await waitFor(() => { | ||
| expect(popoverRoot().getAttribute("data-open")).toBe("true") | ||
| }) | ||
|
|
||
| // Enter confirm and confirm restore -> popover closes; menu then hides | ||
| await userEvent.click(getByTestId("restore-files-and-task-btn")) | ||
| await userEvent.click(getByTestId("confirm-restore-btn")) | ||
| await waitFor(() => { | ||
| expect(popoverRoot().getAttribute("data-open")).toBe("false") | ||
| }) | ||
| await waitFor(() => { | ||
| expect(menuContainer().className).toContain("hidden") | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test coverage: Consider adding tests for this component, especially to verify the popover positioning fix and state management behavior. This would help prevent regression of the positioning bug.