🐛 fix(vscode): 改动 tab 默认统一视图并保留阅读位置
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
DEFAULT_PR_DIFF_MODE,
|
||||
isPrDiffMode,
|
||||
parsePrDiffMode,
|
||||
type PrDiffMode,
|
||||
} from './prDiffMode'
|
||||
|
||||
describe('DEFAULT_PR_DIFF_MODE', () => {
|
||||
it('默认是 unified', () => {
|
||||
expect(DEFAULT_PR_DIFF_MODE).toBe('unified')
|
||||
})
|
||||
})
|
||||
|
||||
describe('isPrDiffMode', () => {
|
||||
it('仅接受 unified / split', () => {
|
||||
expect(isPrDiffMode('unified')).toBe(true)
|
||||
expect(isPrDiffMode('split')).toBe(true)
|
||||
expect(isPrDiffMode('Unified')).toBe(false)
|
||||
expect(isPrDiffMode('SPLIT')).toBe(false)
|
||||
expect(isPrDiffMode('')).toBe(false)
|
||||
expect(isPrDiffMode(null)).toBe(false)
|
||||
expect(isPrDiffMode(undefined)).toBe(false)
|
||||
expect(isPrDiffMode(3)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('parsePrDiffMode', () => {
|
||||
it('split → split', () => {
|
||||
expect(parsePrDiffMode('split')).toBe('split')
|
||||
})
|
||||
|
||||
it('unified → unified', () => {
|
||||
expect(parsePrDiffMode('unified')).toBe('unified')
|
||||
})
|
||||
|
||||
it('缺省 / 非法一律 unified', () => {
|
||||
expect(parsePrDiffMode(undefined)).toBe('unified')
|
||||
expect(parsePrDiffMode(null)).toBe('unified')
|
||||
expect(parsePrDiffMode('')).toBe('unified')
|
||||
expect(parsePrDiffMode('Split')).toBe('unified')
|
||||
expect(parsePrDiffMode('UNIFIED')).toBe('unified')
|
||||
expect(parsePrDiffMode(1)).toBe('unified')
|
||||
expect(parsePrDiffMode({})).toBe('unified')
|
||||
})
|
||||
|
||||
it('返回类型可赋值给 PrDiffMode', () => {
|
||||
const mode: PrDiffMode = parsePrDiffMode('split')
|
||||
expect(mode).toBe('split')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 「改动」tab 的 diff 模式(统一 / 分栏)解析。
|
||||
* 纯逻辑:不碰 VS Code API,便于单测。
|
||||
*/
|
||||
|
||||
export const DEFAULT_PR_DIFF_MODE = 'unified' as const
|
||||
|
||||
export type PrDiffMode = 'unified' | 'split'
|
||||
|
||||
export function isPrDiffMode(x: unknown): x is PrDiffMode {
|
||||
return x === 'unified' || x === 'split'
|
||||
}
|
||||
|
||||
/**
|
||||
* workspaceState 读出值 → 合法模式。
|
||||
* 仅精确字符串 `'split'` 才是分栏;其它一律统一(默认路径)。
|
||||
*/
|
||||
export function parsePrDiffMode(stored: unknown): PrDiffMode {
|
||||
return stored === 'split' ? 'split' : DEFAULT_PR_DIFF_MODE
|
||||
}
|
||||
Reference in New Issue
Block a user