chore: Fix broken unit tests, add themeLoading test

This commit is contained in:
jamesread 2026-01-11 22:24:18 +00:00
parent 9b032196be
commit 93d56cc42e
6 changed files with 105 additions and 3 deletions

View File

@ -0,0 +1,11 @@
---
listenAddressSingleHTTPFrontend: 0.0.0.0:1337
logLevel: "DEBUG"
checkForUpdates: false
actions:
- title: Test action
shell: "echo 'Hello from theme loading test'"
icon: ping

View File

@ -0,0 +1,5 @@
/* Theme One CSS */
body {
background-color: #theme-one;
}

View File

@ -0,0 +1,5 @@
/* Theme Two CSS */
body {
background-color: #theme-two;
}

View File

@ -0,0 +1,73 @@
import { describe, it, before, after } from 'mocha'
import { expect } from 'chai'
import {
getRootAndWait,
takeScreenshotOnFailure,
} from '../../lib/elements.js'
describe('config: themeLoading', function () {
before(async function () {
await runner.start('themeLoading')
})
after(async () => {
await runner.stop()
})
afterEach(function () {
takeScreenshotOnFailure(this.currentTest, webdriver)
})
it('Available themes are discovered and returned in Init response', async function () {
await getRootAndWait()
// Wait for initResponse to be available
await webdriver.wait(async () => {
const hasInitResponse = await webdriver.executeScript(
'return typeof window.initResponse !== "undefined" && window.initResponse !== null'
)
return hasInitResponse
}, 5000, 'Init response should be available')
// Get available themes from the Init response
const availableThemes = await webdriver.executeScript(
'return window.initResponse ? (window.initResponse.availableThemes || []) : []'
)
// Verify themes array exists and is an array
expect(availableThemes).to.be.an('array')
// Verify that themes with theme.css are discovered
// theme-one and theme-two have theme.css, invalid-theme does not
expect(availableThemes).to.include('theme-one')
expect(availableThemes).to.include('theme-two')
// Verify that themes without theme.css are not included
expect(availableThemes).to.not.include('invalid-theme')
// Verify themes are sorted alphabetically
const sortedThemes = [...availableThemes].sort()
expect(availableThemes).to.deep.equal(sortedThemes)
})
it('Available themes list is accessible via JavaScript', async function () {
await getRootAndWait()
// Wait for initResponse to be available
await webdriver.wait(async () => {
const hasInitResponse = await webdriver.executeScript(
'return typeof window.initResponse !== "undefined" && window.initResponse !== null'
)
return hasInitResponse
}, 5000, 'Init response should be available')
// Verify availableThemes is accessible
const availableThemes = await webdriver.executeScript(
'return window.initResponse ? (window.initResponse.availableThemes || []) : []'
)
expect(availableThemes).to.be.an('array')
expect(availableThemes.length).to.be.at.least(2)
})
})

View File

@ -913,8 +913,13 @@ func (api *oliveTinAPI) Init(ctx ctx.Context, req *connect.Request[apiv1.InitReq
// discoverAvailableThemes finds all available themes in the custom-webui/themes directory.
// A theme is considered available if it has a theme.css file.
func discoverAvailableThemes(cfg *config.Config) []string {
themesDir := path.Join(cfg.GetDir(), "custom-webui", "themes")
configDir := cfg.GetDir()
if configDir == "" {
return []string{}
}
themesDir := path.Join(configDir, "custom-webui", "themes")
entries, err := os.ReadDir(themesDir)
if err != nil {
log.WithFields(log.Fields{
@ -932,7 +937,7 @@ func discoverAvailableThemes(cfg *config.Config) []string {
themeName := entry.Name()
themeCssPath := path.Join(themesDir, themeName, "theme.css")
if _, err := os.Stat(themeCssPath); err == nil {
themes = append(themes, themeName)
}

View File

@ -58,5 +58,8 @@ func (cfg *Config) SetDir(dir string) {
}
func (cfg *Config) GetDir() string {
if len(cfg.sourceFiles) == 0 {
return ""
}
return cfg.sourceFiles[len(cfg.sourceFiles)-1]
}