summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/themes/theme-manager.test.ts
diff options
context:
space:
mode:
authorAli Al Jufairi <[email protected]>2025-07-20 16:51:18 +0900
committerGitHub <[email protected]>2025-07-20 07:51:18 +0000
commit76b935d598b895240b9bc2b182eb9f1e1b24be0d (patch)
treecc76fb76a8655f7ab9a064b6c2af750726dd2478 /packages/cli/src/ui/themes/theme-manager.test.ts
parentc0bfa388c571342265915f8de888a43190c82759 (diff)
Feature custom themes logic (#2639)
Co-authored-by: Jacob Richman <[email protected]>
Diffstat (limited to 'packages/cli/src/ui/themes/theme-manager.test.ts')
-rw-r--r--packages/cli/src/ui/themes/theme-manager.test.ts106
1 files changed, 106 insertions, 0 deletions
diff --git a/packages/cli/src/ui/themes/theme-manager.test.ts b/packages/cli/src/ui/themes/theme-manager.test.ts
new file mode 100644
index 00000000..f218af4b
--- /dev/null
+++ b/packages/cli/src/ui/themes/theme-manager.test.ts
@@ -0,0 +1,106 @@
+/**
+ * @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: '#D5A40A',
+ AccentRed: '#DD4C4C',
+ Comment: '#008000',
+ Gray: '#B7BECC',
+};
+
+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 not load invalid custom themes', () => {
+ const invalidTheme = { ...validCustomTheme, Background: 'not-a-color' };
+ themeManager.loadCustomThemes({
+ InvalidTheme: invalidTheme as unknown as CustomTheme,
+ });
+ expect(themeManager.getCustomThemeNames()).not.toContain('InvalidTheme');
+ expect(themeManager.isCustomTheme('InvalidTheme')).toBe(false);
+ });
+
+ 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 fallback 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;
+ }
+ });
+});