perf: 完善黑夜模式的表现效果,工作流编排幕布和节点在黑夜模式正常表现

This commit is contained in:
2026-03-04 19:56:20 +08:00
parent 27376a5f33
commit a79718b03b
33 changed files with 605 additions and 363 deletions

View File

@@ -0,0 +1,70 @@
import {beforeEach, describe, expect, it} from 'vitest';
import {componentName} from './consts';
import {Tinyflow} from './Tinyflow';
describe('tinyflow theme', () => {
beforeEach(() => {
document.body.innerHTML = '';
});
it('should use light theme by default', () => {
const container = document.createElement('div');
document.body.append(container);
const tinyflow = new Tinyflow({
element: container
});
const tinyflowEl = container.querySelector(componentName);
expect(tinyflowEl).toBeTruthy();
expect(tinyflowEl?.classList.contains('tf-theme-light')).toBe(true);
expect(tinyflowEl?.classList.contains('tf-theme-dark')).toBe(false);
tinyflow.destroy();
});
it('should toggle theme class without remount', () => {
const container = document.createElement('div');
document.body.append(container);
const tinyflow = new Tinyflow({
element: container,
theme: 'dark'
});
const tinyflowEl = container.querySelector(componentName);
expect(tinyflowEl?.classList.contains('tf-theme-dark')).toBe(true);
tinyflow.setTheme('light');
expect(tinyflowEl?.classList.contains('tf-theme-light')).toBe(true);
expect(tinyflowEl?.classList.contains('tf-theme-dark')).toBe(false);
tinyflow.destroy();
});
it('should keep theme when data is reset', () => {
const container = document.createElement('div');
document.body.append(container);
const tinyflow = new Tinyflow({
element: container,
theme: 'dark'
});
const firstRenderEl = container.querySelector(componentName);
tinyflow.setData({
nodes: [],
edges: []
});
const secondRenderEl = container.querySelector(componentName);
expect(firstRenderEl).toBeTruthy();
expect(secondRenderEl).toBeTruthy();
expect(secondRenderEl).not.toBe(firstRenderEl);
expect(secondRenderEl?.classList.contains('tf-theme-dark')).toBe(true);
tinyflow.destroy();
});
});