1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
// Patch: Unset NO_COLOR at the very top before any imports
if (process.env['NO_COLOR'] !== undefined) {
delete process.env['NO_COLOR'];
}
import { describe, it, expect, beforeEach } from 'vitest';
import { themeManager, DEFAULT_THEME } from './theme-manager.js';
import { CustomTheme } from './theme.js';
const validCustomTheme: CustomTheme = {
type: 'custom',
name: 'MyCustomTheme',
Background: '#000000',
Foreground: '#ffffff',
LightBlue: '#89BDCD',
AccentBlue: '#3B82F6',
AccentPurple: '#8B5CF6',
AccentCyan: '#06B6D4',
AccentGreen: '#3CA84B',
AccentYellow: 'yellow',
AccentRed: 'red',
DiffAdded: 'green',
DiffRemoved: 'red',
Comment: 'gray',
Gray: 'gray',
};
describe('ThemeManager', () => {
beforeEach(() => {
// Reset themeManager state
themeManager.loadCustomThemes({});
themeManager.setActiveTheme(DEFAULT_THEME.name);
});
it('should load valid custom themes', () => {
themeManager.loadCustomThemes({ MyCustomTheme: validCustomTheme });
expect(themeManager.getCustomThemeNames()).toContain('MyCustomTheme');
expect(themeManager.isCustomTheme('MyCustomTheme')).toBe(true);
});
it('should set and get the active theme', () => {
expect(themeManager.getActiveTheme().name).toBe(DEFAULT_THEME.name);
themeManager.setActiveTheme('Ayu');
expect(themeManager.getActiveTheme().name).toBe('Ayu');
});
it('should set and get a custom active theme', () => {
themeManager.loadCustomThemes({ MyCustomTheme: validCustomTheme });
themeManager.setActiveTheme('MyCustomTheme');
expect(themeManager.getActiveTheme().name).toBe('MyCustomTheme');
});
it('should return false when setting a non-existent theme', () => {
expect(themeManager.setActiveTheme('NonExistentTheme')).toBe(false);
expect(themeManager.getActiveTheme().name).toBe(DEFAULT_THEME.name);
});
it('should list available themes including custom themes', () => {
themeManager.loadCustomThemes({ MyCustomTheme: validCustomTheme });
const available = themeManager.getAvailableThemes();
expect(
available.some(
(t: { name: string; isCustom?: boolean }) =>
t.name === 'MyCustomTheme' && t.isCustom,
),
).toBe(true);
});
it('should get a theme by name', () => {
expect(themeManager.getTheme('Ayu')).toBeDefined();
themeManager.loadCustomThemes({ MyCustomTheme: validCustomTheme });
expect(themeManager.getTheme('MyCustomTheme')).toBeDefined();
});
it('should fall back to default theme if active theme is invalid', () => {
(themeManager as unknown as { activeTheme: unknown }).activeTheme = {
name: 'NonExistent',
type: 'custom',
};
expect(themeManager.getActiveTheme().name).toBe(DEFAULT_THEME.name);
});
it('should return NoColorTheme if NO_COLOR is set', () => {
const original = process.env['NO_COLOR'];
process.env['NO_COLOR'] = '1';
expect(themeManager.getActiveTheme().name).toBe('NoColor');
if (original === undefined) {
delete process.env['NO_COLOR'];
} else {
process.env['NO_COLOR'] = original;
}
});
});
|