feat: v0.4.1 — Zen 专注模式宽度可配置 + 5 项修复 + 841 测试
CI / test-parser (push) Successful in 9m29s
CI / test-core (push) Successful in 9m36s
CI / test-rest (push) Successful in 9m29s
CI / e2e (push) Successful in 9m44s
CI / verify (18.x) (push) Successful in 9m50s
CI / verify (20.x) (push) Successful in 9m50s
CI / verify (24.x) (push) Successful in 9m45s

This commit is contained in:
2026-08-09 20:17:25 +08:00
parent b743af8d90
commit 4d6767482e
14 changed files with 258 additions and 35 deletions
+141
View File
@@ -1768,6 +1768,59 @@ describe('MarkdownEditor - v0.2.0 outline 构建', () => {
});
});
describe('MarkdownEditor - v0.4.1 outline 启动初始化', () => {
test('outline: true 构造后自动构建面板(无需手动调用)', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, { value: '# H1\n## H2', outline: true, mode: 'split' });
const panel = ed.el.querySelector('.me-outline');
expect(panel).not.toBeNull();
expect(panel!.querySelectorAll('a').length).toBe(2);
ed.destroy();
});
test('outline: true + edit 模式构造后切换 split 自动构建面板', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, { value: '# H1', outline: true, mode: 'edit' });
expect(ed.el.querySelector('.me-outline')).toBeNull();
ed.setMode('split');
expect(ed.el.querySelector('.me-outline')).not.toBeNull();
ed.destroy();
});
test('outline: false 构造后不创建面板', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, { value: '# H1', outline: false, mode: 'split' });
expect(ed.el.querySelector('.me-outline')).toBeNull();
ed.destroy();
});
});
describe('MarkdownEditor - v0.4.1 edit 模式初始行号', () => {
test('edit 模式构造后 gutter 已渲染行号', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, { value: 'a\nb\nc', mode: 'edit' });
expect(ed.gutter.children.length).toBe(3);
ed.destroy();
});
test('preview 模式构造后 gutter 也渲染行号', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, { value: 'a\nb\nc\nd', mode: 'preview' });
expect(ed.gutter.children.length).toBe(4);
ed.destroy();
});
});
describe('MarkdownEditor - v0.2.0 gutter 更新', () => {
test('gutter 行数不变时跳过 DOM 更新', () => {
document.body.innerHTML = '';
@@ -2723,6 +2776,94 @@ describe('MarkdownEditor - v0.2.5 zenMode 初始状态', () => {
});
});
describe('MarkdownEditor - v0.4.1 zenMaxWidth 专注模式宽度', () => {
test('默认 zenMaxWidth 为 960', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, {});
expect(ed.getZenMaxWidth()).toBe(960);
ed.destroy();
});
test('配置 zenMaxWidth 数字转为 px 并写入 CSS 变量', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, { zenMaxWidth: 1200 });
expect(ed.getZenMaxWidth()).toBe(1200);
expect(ed.el.style.getPropertyValue('--md-zen-max-width')).toBe('1200px');
ed.destroy();
});
test('配置 zenMaxWidth 字符串原样写入 CSS 变量', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, { zenMaxWidth: 'min(1200px, 90%)' });
expect(ed.el.style.getPropertyValue('--md-zen-max-width')).toBe('min(1200px, 90%)');
ed.destroy();
});
test('配置 zenMaxWidth: false 清除 CSS 变量(不限制宽度)', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, { zenMaxWidth: false });
expect(ed.el.style.getPropertyValue('--md-zen-max-width')).toBe('');
ed.destroy();
});
test('setZenMaxWidth 运行时更新宽度且仅在 zen 时生效类', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, {});
ed.setZenMaxWidth(1080);
expect(ed.getZenMaxWidth()).toBe(1080);
expect(ed.el.style.getPropertyValue('--md-zen-max-width')).toBe('1080px');
ed.setZenMaxWidth(false);
expect(ed.el.style.getPropertyValue('--md-zen-max-width')).toBe('');
ed.setZenMaxWidth('60vw');
expect(ed.el.style.getPropertyValue('--md-zen-max-width')).toBe('60vw');
ed.destroy();
});
test('zenMode: true 启动时应用 zenMaxWidth 变量', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, { zenMode: true, zenMaxWidth: 1000 });
expect(ed.isZen()).toBe(true);
expect(ed.el.style.getPropertyValue('--md-zen-max-width')).toBe('1000px');
ed.destroy();
});
});
describe('MarkdownEditor - v0.4.1 wordWrap: false 配置生效', () => {
test('wordWrap: false 初始 whiteSpace 为 pre', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, { wordWrap: false });
expect(ed.isWordWrap()).toBe(false);
expect(ed.textarea.style.whiteSpace).toBe('pre');
ed.toggleWordWrap();
expect(ed.isWordWrap()).toBe(true);
expect(ed.textarea.style.whiteSpace).toBe('pre-wrap');
ed.destroy();
});
test('默认 wordWrap 为 true', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, {});
expect(ed.isWordWrap()).toBe(true);
ed.destroy();
});
});
describe('MarkdownEditor - v0.2.5 分隔条实例隔离', () => {
test('分隔条位置按实例 id 保存', () => {
localStorage.clear();
+1 -1
View File
@@ -29,7 +29,7 @@ describe('index.ts - 全局 API', () => {
test('VERSION 是字符串', () => {
expect(typeof VERSION).toBe('string');
expect(VERSION).toBe('0.4.0');
expect(VERSION).toBe('0.4.1');
});
test('api.default 是 api 本身', () => {
+26
View File
@@ -1239,6 +1239,32 @@ describe('v0.2.5 exportTool exportPDF', () => {
});
});
describe('v0.4.1 exportTool 卸载清理', () => {
test('unuse 后实例上的导出方法被删除', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, { value: '# hi' });
ed.use('exportTool');
expect(typeof (ed as any).exportMarkdown).toBe('function');
ed.unuse('exportTool');
expect((ed as any).exportMarkdown).toBeUndefined();
expect((ed as any).exportHTML).toBeUndefined();
expect((ed as any).exportPDF).toBeUndefined();
ed.destroy();
});
test('destroy 时实例上的导出方法被删除', () => {
document.body.innerHTML = '';
const c = document.createElement('div');
document.body.appendChild(c);
const ed = new MarkdownEditor(c, { value: '# hi', plugins: ['exportTool'] });
expect(typeof (ed as any).exportMarkdown).toBe('function');
ed.destroy();
expect((ed as any).exportMarkdown).toBeUndefined();
});
});
describe('v0.2.5 imagePaste 尺寸限制', () => {
test('超出 maxSizeKB 时 toast 警告且不插入', () => {
document.body.innerHTML = '';