mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-17 13:13:35 +08:00
PR #428 added a General Settings zoom slider after the desktop shortcut work already introduced a native-first app zoom controller. Keeping both paths would create double scaling and stale UI state, so the slider now routes through the existing controller and store state while the app shell no longer applies a second CSS zoom. Constraint: UI zoom is device-local display state and should not be written into shared user settings. Rejected: Keep cc-haha-ui-zoom plus AppShell style.zoom | it conflicts with shortcut zoom and multiplies visual scale. Rejected: Persist zoom through /api/settings/user | it would sync display-specific state across machines. Confidence: high Scope-risk: moderate Directive: Keep app zoom behind desktop/src/lib/appZoom.ts; do not add another storage key or DOM zoom application point without migration and shortcut sync tests. Tested: cd desktop && bun run test -- --run src/lib/appZoom.test.ts src/hooks/useKeyboardShortcuts.test.tsx src/stores/settingsStore.test.ts src/__tests__/generalSettings.test.tsx src/lib/persistenceMigrations.test.ts src/lib/doctorRepair.test.ts Tested: bun run check:desktop Not-tested: Real Windows/Linux desktop runtime smoke.
104 lines
2.7 KiB
TypeScript
104 lines
2.7 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
import { cleanup, fireEvent, render, waitFor } from '@testing-library/react'
|
|
import { APP_ZOOM_STORAGE_KEY } from '../lib/appZoom'
|
|
import { useSettingsStore } from '../stores/settingsStore'
|
|
import { useKeyboardShortcuts } from './useKeyboardShortcuts'
|
|
|
|
function ShortcutHost() {
|
|
useKeyboardShortcuts()
|
|
return null
|
|
}
|
|
|
|
function setNavigatorPlatform(platform: string) {
|
|
Object.defineProperty(window.navigator, 'platform', {
|
|
configurable: true,
|
|
value: platform,
|
|
})
|
|
}
|
|
|
|
describe('useKeyboardShortcuts app zoom', () => {
|
|
beforeEach(() => {
|
|
window.localStorage.clear()
|
|
document.documentElement.removeAttribute('data-app-zoom-mode')
|
|
document.documentElement.removeAttribute('data-app-zoom-percent')
|
|
document.documentElement.style.removeProperty('--app-zoom')
|
|
document.body.style.removeProperty('zoom')
|
|
useSettingsStore.setState({ uiZoom: 1 })
|
|
setNavigatorPlatform('Win32')
|
|
})
|
|
|
|
afterEach(() => {
|
|
cleanup()
|
|
})
|
|
|
|
it('handles Ctrl zoom shortcuts on Windows and Linux style platforms', async () => {
|
|
render(<ShortcutHost />)
|
|
|
|
fireEvent.keyDown(document, {
|
|
code: 'Equal',
|
|
ctrlKey: true,
|
|
key: '=',
|
|
})
|
|
|
|
await waitFor(() => {
|
|
expect(window.localStorage.getItem(APP_ZOOM_STORAGE_KEY)).toBe('1.1')
|
|
})
|
|
expect(useSettingsStore.getState().uiZoom).toBe(1.1)
|
|
expect(document.documentElement.getAttribute('data-app-zoom-percent')).toBe('110')
|
|
|
|
fireEvent.keyDown(document, {
|
|
code: 'Minus',
|
|
ctrlKey: true,
|
|
key: '-',
|
|
})
|
|
|
|
await waitFor(() => {
|
|
expect(window.localStorage.getItem(APP_ZOOM_STORAGE_KEY)).toBe('1')
|
|
})
|
|
expect(useSettingsStore.getState().uiZoom).toBe(1)
|
|
|
|
fireEvent.keyDown(document, {
|
|
code: 'NumpadAdd',
|
|
ctrlKey: true,
|
|
key: '+',
|
|
})
|
|
await waitFor(() => {
|
|
expect(window.localStorage.getItem(APP_ZOOM_STORAGE_KEY)).toBe('1.1')
|
|
})
|
|
|
|
fireEvent.keyDown(document, {
|
|
code: 'Digit0',
|
|
ctrlKey: true,
|
|
key: '0',
|
|
})
|
|
|
|
await waitFor(() => {
|
|
expect(window.localStorage.getItem(APP_ZOOM_STORAGE_KEY)).toBe('1')
|
|
})
|
|
})
|
|
|
|
it('uses Cmd zoom shortcuts on macOS', async () => {
|
|
setNavigatorPlatform('MacIntel')
|
|
render(<ShortcutHost />)
|
|
|
|
fireEvent.keyDown(document, {
|
|
code: 'Minus',
|
|
key: '-',
|
|
metaKey: true,
|
|
})
|
|
|
|
await waitFor(() => {
|
|
expect(window.localStorage.getItem(APP_ZOOM_STORAGE_KEY)).toBe('0.9')
|
|
})
|
|
|
|
fireEvent.keyDown(document, {
|
|
code: 'Equal',
|
|
ctrlKey: true,
|
|
key: '=',
|
|
})
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 0))
|
|
expect(window.localStorage.getItem(APP_ZOOM_STORAGE_KEY)).toBe('0.9')
|
|
})
|
|
})
|