mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-06-29 09:55:56 +08:00
chore: 开源项目基础设施全面完善
新增配置文件: - .editorconfig — 跨编辑器代码风格统一 - .gitattributes — 行尾符 CRLF 规范化 - .prettierrc + .prettierignore — 前端代码格式化 - .markdownlint.json — Markdown 格式规范 - commitlint.config.js — Conventional Commits 强制校验 新增 GitHub 社区文件: - .github/dependabot.yml — 依赖自动更新 (npm + Cargo + Actions) - .github/CODEOWNERS — 自动 PR 审查分配 - .github/FUNDING.yml — 开源赞助入口 新增文档: - ROADMAP.md — v5.1/v5.2/v6.0 路线图 - SUPPORT.md — 帮助与支持指南 - docs/screenshots/ — 截图目录就位 新增 Git Hooks: - .husky/pre-commit — lint-staged 自动格式化+修复 - .husky/commit-msg — commitlint 校验提交消息 CI 强化 (.github/workflows/ci.yml): - 新增 Prettier 格式检查步骤 - 新增 cargo fmt --check 步骤 - 新增 Vitest 覆盖率生成 + Codecov 上报 修复: - index.html 标题 v4.0 → v5.0 - PathEditDialog set-state-in-effect 改用 useRef prevOpen 守卫 - use-app-actions.test.tsx 缺失 @vitest-environment jsdom - 所有 TS/TSX 文件 Prettier 格式化统一 配置更新: - vitest.config.ts — v8 覆盖率 + 阈值门禁 (60%/70%) - package.json — format/format:check/test:coverage/prepare 脚本 + lint-staged - .gitignore — 新增 coverage/sync-conflict/playwright-report - README.md — 新增 coverage + platform 徽章 + 截图区域
This commit is contained in:
@@ -1,12 +1,24 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { UndoRedoManager, OperationType, TargetType, type OpRecord } from '../../src/core/undo-redo';
|
||||
import {
|
||||
UndoRedoManager,
|
||||
OperationType,
|
||||
TargetType,
|
||||
type OpRecord,
|
||||
} from '../../src/core/undo-redo';
|
||||
import type { PathEntry } from '../../src/core/path-entry';
|
||||
|
||||
function pe(s: string, enabled: boolean = true): PathEntry {
|
||||
return { path: s, enabled };
|
||||
}
|
||||
|
||||
function makeRecord(type: OperationType, target: TargetType, index: number, count: number, oldPaths: PathEntry[], newPaths: PathEntry[]): OpRecord {
|
||||
function makeRecord(
|
||||
type: OperationType,
|
||||
target: TargetType,
|
||||
index: number,
|
||||
count: number,
|
||||
oldPaths: PathEntry[],
|
||||
newPaths: PathEntry[],
|
||||
): OpRecord {
|
||||
return { type, target, index, count, oldPaths, newPaths };
|
||||
}
|
||||
|
||||
@@ -31,10 +43,10 @@ describe('UndoRedoManager', () => {
|
||||
mgr.push(makeRecord(OperationType.ADD, TargetType.SYSTEM, 2, 1, [], [pe('C:\\NewPath')]));
|
||||
|
||||
const u = mgr.undo(sys, user)!;
|
||||
expect(u[0].map(e => e.path)).toEqual(['C:\\Windows', 'C:\\Program Files']);
|
||||
expect(u[0].map((e) => e.path)).toEqual(['C:\\Windows', 'C:\\Program Files']);
|
||||
|
||||
const r = mgr.redo(...u)!;
|
||||
expect(r[0].map(e => e.path)).toEqual(['C:\\Windows', 'C:\\Program Files', 'C:\\NewPath']);
|
||||
expect(r[0].map((e) => e.path)).toEqual(['C:\\Windows', 'C:\\Program Files', 'C:\\NewPath']);
|
||||
});
|
||||
|
||||
it('DELETE 撤销/重做', () => {
|
||||
@@ -46,11 +58,20 @@ describe('UndoRedoManager', () => {
|
||||
expect(u[0][0].path).toBe(removed.path);
|
||||
|
||||
const r = mgr.redo(...u)!;
|
||||
expect(r[0].map(e => e.path)).toEqual(['C:\\Program Files']);
|
||||
expect(r[0].map((e) => e.path)).toEqual(['C:\\Program Files']);
|
||||
});
|
||||
|
||||
it('EDIT 撤销/重做', () => {
|
||||
mgr.push(makeRecord(OperationType.EDIT, TargetType.SYSTEM, 0, 1, [pe('C:\\Windows')], [pe('C:\\Edited')]));
|
||||
mgr.push(
|
||||
makeRecord(
|
||||
OperationType.EDIT,
|
||||
TargetType.SYSTEM,
|
||||
0,
|
||||
1,
|
||||
[pe('C:\\Windows')],
|
||||
[pe('C:\\Edited')],
|
||||
),
|
||||
);
|
||||
sys[0] = pe('C:\\Edited');
|
||||
|
||||
const u = mgr.undo(sys, user)!;
|
||||
@@ -65,10 +86,10 @@ describe('UndoRedoManager', () => {
|
||||
[sys[0], sys[1]] = [sys[1], sys[0]];
|
||||
|
||||
const u = mgr.undo(sys, user)!;
|
||||
expect(u[0].map(e => e.path)).toEqual(['C:\\Windows', 'C:\\Program Files']);
|
||||
expect(u[0].map((e) => e.path)).toEqual(['C:\\Windows', 'C:\\Program Files']);
|
||||
|
||||
const r = mgr.redo(...u)!;
|
||||
expect(r[0].map(e => e.path)).toEqual(['C:\\Program Files', 'C:\\Windows']);
|
||||
expect(r[0].map((e) => e.path)).toEqual(['C:\\Program Files', 'C:\\Windows']);
|
||||
});
|
||||
|
||||
it('MOVE_DOWN 撤销/重做', () => {
|
||||
@@ -76,7 +97,7 @@ describe('UndoRedoManager', () => {
|
||||
[sys[0], sys[1]] = [sys[1], sys[0]];
|
||||
|
||||
const u = mgr.undo(sys, user)!;
|
||||
expect(u[0].map(e => e.path)).toEqual(['C:\\Windows', 'C:\\Program Files']);
|
||||
expect(u[0].map((e) => e.path)).toEqual(['C:\\Windows', 'C:\\Program Files']);
|
||||
});
|
||||
|
||||
it('CLEAN 撤销/重做', () => {
|
||||
@@ -140,9 +161,12 @@ describe('UndoRedoManager', () => {
|
||||
// 删除 indices [1, 3](C:\Program Files 和 C:\Extra2)
|
||||
const removed = [sys[1], sys[3]];
|
||||
mgr.push({
|
||||
type: OperationType.DELETE, target: TargetType.SYSTEM,
|
||||
index: 1, count: 2,
|
||||
oldPaths: removed, newPaths: [],
|
||||
type: OperationType.DELETE,
|
||||
target: TargetType.SYSTEM,
|
||||
index: 1,
|
||||
count: 2,
|
||||
oldPaths: removed,
|
||||
newPaths: [],
|
||||
indices: [1, 3],
|
||||
});
|
||||
sys.splice(3, 1);
|
||||
@@ -152,21 +176,29 @@ describe('UndoRedoManager', () => {
|
||||
expect(u[0]).toEqual(old);
|
||||
|
||||
const r = mgr.redo(...u)!;
|
||||
expect(r[0].map(e => e.path)).toEqual(['C:\\Windows', 'C:\\Extra1']);
|
||||
expect(r[0].map((e) => e.path)).toEqual(['C:\\Windows', 'C:\\Extra1']);
|
||||
});
|
||||
|
||||
it('操作 USER 路径', () => {
|
||||
user.push(pe('C:\\NewUserPath'));
|
||||
mgr.push(makeRecord(OperationType.ADD, TargetType.USER, 1, 1, [], [pe('C:\\NewUserPath')]));
|
||||
const u = mgr.undo(sys, user)!;
|
||||
expect(u[1].map(e => e.path)).toEqual(['C:\\Users\\me\\AppData']);
|
||||
expect(u[0].map(e => e.path)).toEqual(['C:\\Windows', 'C:\\Program Files']);
|
||||
expect(u[1].map((e) => e.path)).toEqual(['C:\\Users\\me\\AppData']);
|
||||
expect(u[0].map((e) => e.path)).toEqual(['C:\\Windows', 'C:\\Program Files']);
|
||||
});
|
||||
|
||||
it('TOGGLE 撤销/重做', () => {
|
||||
sys[0] = pe('C:\\Windows', false);
|
||||
mgr.push(makeRecord(OperationType.TOGGLE, TargetType.SYSTEM, 0, 1,
|
||||
[pe('C:\\Windows', true)], [pe('C:\\Windows', false)]));
|
||||
mgr.push(
|
||||
makeRecord(
|
||||
OperationType.TOGGLE,
|
||||
TargetType.SYSTEM,
|
||||
0,
|
||||
1,
|
||||
[pe('C:\\Windows', true)],
|
||||
[pe('C:\\Windows', false)],
|
||||
),
|
||||
);
|
||||
|
||||
const u = mgr.undo(sys, user)!;
|
||||
expect(u[0][0].enabled).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user