forked from cline/cline
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: add chat message font size setting #8680
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
roomote
wants to merge
2
commits into
main
Choose a base branch
from
feat/chat-message-font-size
base: main
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.
Open
Changes from all commits
Commits
Show all changes
2 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
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
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
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
127 changes: 127 additions & 0 deletions
127
webview-ui/src/components/settings/__tests__/UISettings.fontsize.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,127 @@ | ||
// npx vitest run src/components/settings/__tests__/UISettings.fontsize.spec.tsx | ||
|
||
import { render, screen } from "@testing-library/react" | ||
import { describe, it, expect, vi, beforeEach } from "vitest" | ||
import "@testing-library/jest-dom" | ||
import { UISettings } from "../UISettings" | ||
import { ExtensionStateContextProvider } from "@src/context/ExtensionStateContext" | ||
import React from "react" | ||
|
||
// Mock vscode API | ||
const mockPostMessage = vi.fn() | ||
;(global as any).vscode = { | ||
postMessage: mockPostMessage, | ||
} | ||
|
||
// Mock the useTranslation hook | ||
vi.mock("react-i18next", () => ({ | ||
useTranslation: () => ({ | ||
t: (key: string) => key, | ||
}), | ||
Trans: ({ children }: { children: React.ReactNode }) => <>{children}</>, | ||
})) | ||
|
||
// Mock VSCode webview UI toolkit components | ||
vi.mock("@vscode/webview-ui-toolkit/react", () => ({ | ||
VSCodeDropdown: ({ children, value, onChange }: any) => ( | ||
<select role="combobox" value={value} onChange={(e) => onChange && onChange(e)}> | ||
{children} | ||
</select> | ||
), | ||
VSCodeOption: ({ children, value }: any) => ( | ||
<option role="option" value={value}> | ||
{children} | ||
</option> | ||
), | ||
VSCodeCheckbox: ({ children }: any) => <label>{children}</label>, | ||
})) | ||
|
||
// Mock useExtensionState hook to provide consistent state | ||
vi.mock("@src/context/ExtensionStateContext", async () => { | ||
const actual = await vi.importActual("@src/context/ExtensionStateContext") | ||
return { | ||
...actual, | ||
useExtensionState: () => ({ | ||
chatMessageFontSize: "default", | ||
setChatMessageFontSize: vi.fn(), | ||
soundEnabled: true, | ||
setSoundEnabled: vi.fn(), | ||
soundVolume: 0.5, | ||
setSoundVolume: vi.fn(), | ||
diffEnabled: true, | ||
setDiffEnabled: vi.fn(), | ||
browserActionType: "auto", | ||
setBrowserActionType: vi.fn(), | ||
}), | ||
} | ||
}) | ||
|
||
describe("UISettings - Chat Message Font Size", () => { | ||
const defaultProps = { | ||
expandedRows: {}, | ||
setExpandedRows: vi.fn(), | ||
isHidden: false, | ||
hideAnnouncement: vi.fn(), | ||
soundEnabled: true, | ||
soundVolume: 0.5, | ||
diffEnabled: true, | ||
allowedCommands: [], | ||
deniedCommands: [], | ||
historyPreviewCollapsed: false, | ||
chatMessageFontSize: "default", | ||
reasoningBlockCollapsed: false, | ||
setCachedStateField: vi.fn(), | ||
} | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
it("should render chat message font size dropdown with all options", () => { | ||
render( | ||
<ExtensionStateContextProvider> | ||
<UISettings {...defaultProps} /> | ||
</ExtensionStateContextProvider>, | ||
) | ||
|
||
// Check that the dropdown is rendered | ||
const dropdown = screen.getByRole("combobox") | ||
expect(dropdown).toBeInTheDocument() | ||
|
||
// Check that all font size options are available | ||
const options = screen.getAllByRole("option") | ||
const optionTexts = options.map((opt) => opt.textContent) | ||
|
||
expect(optionTexts).toContain("Default") | ||
expect(optionTexts).toContain("Extra Small (90%)") | ||
expect(optionTexts).toContain("Small (95%)") | ||
expect(optionTexts).toContain("Large (105%)") | ||
expect(optionTexts).toContain("Extra Large (110%)") | ||
}) | ||
|
||
it("should display the current font size setting", () => { | ||
const props = { ...defaultProps, chatMessageFontSize: "large" } | ||
render( | ||
<ExtensionStateContextProvider> | ||
<UISettings {...props} /> | ||
</ExtensionStateContextProvider>, | ||
) | ||
|
||
const dropdown = screen.getByRole("combobox") | ||
expect(dropdown).toHaveValue("large") | ||
}) | ||
|
||
it("should handle undefined chatMessageFontSize gracefully", () => { | ||
// Use type assertion to test undefined case | ||
const props = { ...defaultProps, chatMessageFontSize: undefined as any } | ||
render( | ||
<ExtensionStateContextProvider> | ||
<UISettings {...props} /> | ||
</ExtensionStateContextProvider>, | ||
) | ||
|
||
const dropdown = screen.getByRole("combobox") | ||
// Should default to "default" when undefined | ||
expect(dropdown).toHaveValue("default") | ||
}) | ||
}) |
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
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.
Review: The new state property 'chatMessageFontSize' is added; consider improving type safety instead of using 'as any' in the update block.