-
-
Notifications
You must be signed in to change notification settings - Fork 213
feat: add font size and word wrap settings to editor preferences #721
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
base: main
Are you sure you want to change the base?
Changes from all commits
d78f35e
87c91cf
bfcc2e7
ef8926e
67cf583
c0a43e6
be9a668
4b8effb
c4e2423
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export const FONT_SIZE_OPTIONS = [12, 13, 14, 15, 16, 18, 20] as const; | ||
| export const DEFAULT_FONT_SIZE = 14; | ||
| export const MIN_FONT_SIZE = FONT_SIZE_OPTIONS[0]; | ||
| export const MAX_FONT_SIZE = FONT_SIZE_OPTIONS[FONT_SIZE_OPTIONS.length - 1]; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,15 +1,22 @@ | ||||||||||||||||||||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||||||||||||||||||||
| import { render, screen } from '@testing-library/react'; | ||||||||||||||||||||
| import { render, screen, fireEvent } from '@testing-library/react'; | ||||||||||||||||||||
| import SettingsModal from '../../components/SettingsModal'; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Mock the store - use inline functions to avoid hoisting issues | ||||||||||||||||||||
| const mockSetEditorFontSize = vi.fn(); | ||||||||||||||||||||
| const mockSetEditorWordWrap = vi.fn(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| vi.mock('../../store/store', () => { | ||||||||||||||||||||
| return { | ||||||||||||||||||||
| default: vi.fn((selector) => selector({ | ||||||||||||||||||||
| isSettingsOpen: true, | ||||||||||||||||||||
| setSettingsOpen: vi.fn(), | ||||||||||||||||||||
| showLineNumbers: true, | ||||||||||||||||||||
| setShowLineNumbers: vi.fn(), | ||||||||||||||||||||
| editorFontSize: 14, | ||||||||||||||||||||
| setEditorFontSize: mockSetEditorFontSize, | ||||||||||||||||||||
| editorWordWrap: true, | ||||||||||||||||||||
| setEditorWordWrap: mockSetEditorWordWrap, | ||||||||||||||||||||
| textColor: '#121212', | ||||||||||||||||||||
| backgroundColor: '#ffffff', | ||||||||||||||||||||
| toggleDarkMode: vi.fn(), | ||||||||||||||||||||
|
|
@@ -76,10 +83,46 @@ describe('SettingsModal', () => { | |||||||||||||||||||
| expect(toggle).toBeChecked(); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| it('renders the Font Size setting', () => { | ||||||||||||||||||||
| render(<SettingsModal />); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| expect(screen.getByText('Font Size')).toBeInTheDocument(); | ||||||||||||||||||||
| expect(screen.getByText('Adjust font size in code editors')).toBeInTheDocument(); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
||||||||||||||||||||
| it('renders the Font Size select with the correct initial value', () => { | |
| render(<SettingsModal />); | |
| const fontSizeSelect = screen.getByRole('combobox', { name: /font size/i }); | |
| expect(fontSizeSelect).toBeInTheDocument(); | |
| expect(fontSizeSelect).toHaveValue('14'); | |
| }); |
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.
The getInitialFontSize function doesn't validate that the parsed font size is within the allowed range (12-20). If localStorage contains an invalid value like 5 or 100, it will be accepted. Consider adding validation to ensure the parsed value is within FONT_SIZE_OPTIONS or at least within a reasonable range before returning it.