-
Notifications
You must be signed in to change notification settings - Fork 454
[LWD] feat(desktop): add history button with cta support in topbar #15623
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
Open
mcayuelas-ledger
wants to merge
1
commit into
feat/wallet40-hide-operation-list
Choose a base branch
from
feat/wallet40-topbar-history-button
base: feat/wallet40-hide-operation-list
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+384
β180
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "ledger-live-desktop": minor | ||
| --- | ||
|
|
||
| add History button in topbar |
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
70 changes: 70 additions & 0 deletions
70
...-live-desktop/src/mvvm/components/TopBar/components/__tests__/TopBarActionButton.test.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,70 @@ | ||
| import React from "react"; | ||
| import { render, screen } from "tests/testSetup"; | ||
| import { TopBarActionButton } from "../TopBarActionButton"; | ||
| import { Eye, Clock } from "@ledgerhq/lumen-ui-react/symbols"; | ||
|
|
||
| describe("TopBarActionButton", () => { | ||
| const defaultProps = { | ||
| label: "test-action", | ||
| isInteractive: true, | ||
| onClick: jest.fn(), | ||
| icon: Eye, | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("renders an IconButton when no cta is provided", () => { | ||
| render(<TopBarActionButton {...defaultProps} />); | ||
|
|
||
| const button = screen.getByTestId("topbar-action-button-test-action"); | ||
| expect(button).toBeVisible(); | ||
| expect(button).toHaveAttribute("aria-label", "test-action"); | ||
| expect(screen.queryByText("History")).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders a Button with text label when cta is provided", () => { | ||
| render(<TopBarActionButton {...defaultProps} icon={Clock} cta="History" />); | ||
|
|
||
| const button = screen.getByTestId("topbar-action-button-test-action"); | ||
| expect(button).toBeVisible(); | ||
| expect(screen.getByText("History")).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("calls onClick when the cta button is clicked", async () => { | ||
| const handleClick = jest.fn(); | ||
|
|
||
| const { user } = render( | ||
| <TopBarActionButton {...defaultProps} icon={Clock} cta="History" onClick={handleClick} />, | ||
| ); | ||
|
|
||
| await user.click(screen.getByTestId("topbar-action-button-test-action")); | ||
| expect(handleClick).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("disables the cta button when isInteractive is false", () => { | ||
| render( | ||
| <TopBarActionButton {...defaultProps} icon={Clock} cta="History" isInteractive={false} />, | ||
| ); | ||
|
|
||
| const button = screen.getByTestId("topbar-action-button-test-action"); | ||
| expect(button).toBeDisabled(); | ||
| }); | ||
|
|
||
| it("calls onClick when the icon button is clicked", async () => { | ||
| const handleClick = jest.fn(); | ||
|
|
||
| const { user } = render(<TopBarActionButton {...defaultProps} onClick={handleClick} />); | ||
|
|
||
| await user.click(screen.getByTestId("topbar-action-button-test-action")); | ||
| expect(handleClick).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("disables the icon button when isInteractive is false", () => { | ||
| render(<TopBarActionButton {...defaultProps} isInteractive={false} />); | ||
|
|
||
| const button = screen.getByTestId("topbar-action-button-test-action"); | ||
| expect(button).toBeDisabled(); | ||
| }); | ||
| }); |
61 changes: 61 additions & 0 deletions
61
apps/ledger-live-desktop/src/mvvm/components/TopBar/hooks/__tests__/useHistory.test.ts
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,61 @@ | ||
| import { Clock } from "@ledgerhq/lumen-ui-react/symbols"; | ||
| import { renderHook, act } from "tests/testSetup"; | ||
| import { useHistory } from "../useHistory"; | ||
| import { useNavigate, useLocation } from "react-router"; | ||
|
|
||
| jest.mock("react-router", () => ({ | ||
| ...jest.requireActual("react-router"), | ||
| useNavigate: jest.fn(), | ||
| useLocation: jest.fn(), | ||
| })); | ||
|
|
||
| const mockNavigate = jest.fn(); | ||
| const mockUseNavigate = jest.mocked(useNavigate); | ||
| const mockUseLocation = jest.mocked(useLocation); | ||
|
|
||
| const createLocation = (pathname: string) => ({ | ||
| pathname, | ||
| state: null, | ||
| key: "default", | ||
| search: "", | ||
| hash: "", | ||
| }); | ||
|
|
||
| describe("useHistory", () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| mockUseNavigate.mockReturnValue(mockNavigate); | ||
| mockUseLocation.mockReturnValue(createLocation("/history")); | ||
| }); | ||
|
|
||
| it("returns handleHistory, historyIcon, tooltip, and cta", () => { | ||
| const { result } = renderHook(() => useHistory()); | ||
|
|
||
| expect(result.current.handleHistory).toBeDefined(); | ||
| expect(result.current.historyIcon).toBe(Clock); | ||
| expect(result.current.tooltip).toBeDefined(); | ||
| expect(result.current.cta).toBeDefined(); | ||
| }); | ||
|
|
||
| it("navigates to /history and sets tracking source when not already on history page", () => { | ||
| mockUseLocation.mockReturnValueOnce(createLocation("/accounts")); | ||
|
|
||
| const { result } = renderHook(() => useHistory()); | ||
|
|
||
| act(() => { | ||
| result.current.handleHistory(); | ||
| }); | ||
|
|
||
| expect(mockNavigate).toHaveBeenCalledWith("/history"); | ||
| }); | ||
|
|
||
| it("does not navigate when already on history page", () => { | ||
| const { result } = renderHook(() => useHistory()); | ||
|
|
||
| act(() => { | ||
| result.current.handleHistory(); | ||
| }); | ||
|
|
||
| expect(mockNavigate).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
This MVVM component uses a raw
<div>wrapper for layout. Insrc/mvvm/, UI code is expected to rely on the design system layout primitives (e.g., Lumen / shared layout components) rather than raw HTML containers so styling and accessibility stay consistent. Consider replacing this wrapper with an appropriate design-system layout component.