File size: 1,623 Bytes
84aa3bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import { describe, it, expect, vi, beforeEach } from 'vitest';
import { validateTheme } from './theme.js';
import { themeManager } from '../ui/themes/theme-manager.js';
import { type LoadedSettings } from '../config/settings.js';

vi.mock('../ui/themes/theme-manager.js', () => ({
  themeManager: {
    findThemeByName: vi.fn(),
  },
}));

describe('theme', () => {
  let mockSettings: LoadedSettings;

  beforeEach(() => {
    vi.clearAllMocks();
    mockSettings = {
      merged: {
        ui: {
          theme: 'test-theme',
        },
      },
    } as unknown as LoadedSettings;
  });

  it('should return null if theme is found', () => {
    vi.mocked(themeManager.findThemeByName).mockReturnValue(
      {} as unknown as ReturnType<typeof themeManager.findThemeByName>,
    );
    const result = validateTheme(mockSettings);
    expect(result).toBeNull();
    expect(themeManager.findThemeByName).toHaveBeenCalledWith('test-theme');
  });

  it('should return error message if theme is not found', () => {
    vi.mocked(themeManager.findThemeByName).mockReturnValue(undefined);
    const result = validateTheme(mockSettings);
    expect(result).toBe('Theme "test-theme" not found.');
    expect(themeManager.findThemeByName).toHaveBeenCalledWith('test-theme');
  });

  it('should return null if theme is undefined', () => {
    mockSettings.merged.ui.theme = undefined;
    const result = validateTheme(mockSettings);
    expect(result).toBeNull();
    expect(themeManager.findThemeByName).not.toHaveBeenCalled();
  });
});