From 93d56cc42eb7b89168c6dbdca500fdf9bd267898 Mon Sep 17 00:00:00 2001 From: jamesread Date: Sun, 11 Jan 2026 22:24:18 +0000 Subject: [PATCH] chore: Fix broken unit tests, add themeLoading test --- .../tests/themeLoading/config.yaml | 11 +++ .../custom-webui/themes/theme-one/theme.css | 5 ++ .../custom-webui/themes/theme-two/theme.css | 5 ++ .../tests/themeLoading/themeLoading.mjs | 73 +++++++++++++++++++ service/internal/api/api.go | 11 ++- service/internal/config/config_helpers.go | 3 + 6 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 integration-tests/tests/themeLoading/config.yaml create mode 100644 integration-tests/tests/themeLoading/custom-webui/themes/theme-one/theme.css create mode 100644 integration-tests/tests/themeLoading/custom-webui/themes/theme-two/theme.css create mode 100644 integration-tests/tests/themeLoading/themeLoading.mjs diff --git a/integration-tests/tests/themeLoading/config.yaml b/integration-tests/tests/themeLoading/config.yaml new file mode 100644 index 0000000..dbca056 --- /dev/null +++ b/integration-tests/tests/themeLoading/config.yaml @@ -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 + diff --git a/integration-tests/tests/themeLoading/custom-webui/themes/theme-one/theme.css b/integration-tests/tests/themeLoading/custom-webui/themes/theme-one/theme.css new file mode 100644 index 0000000..2ea8a4d --- /dev/null +++ b/integration-tests/tests/themeLoading/custom-webui/themes/theme-one/theme.css @@ -0,0 +1,5 @@ +/* Theme One CSS */ +body { + background-color: #theme-one; +} + diff --git a/integration-tests/tests/themeLoading/custom-webui/themes/theme-two/theme.css b/integration-tests/tests/themeLoading/custom-webui/themes/theme-two/theme.css new file mode 100644 index 0000000..ad920fd --- /dev/null +++ b/integration-tests/tests/themeLoading/custom-webui/themes/theme-two/theme.css @@ -0,0 +1,5 @@ +/* Theme Two CSS */ +body { + background-color: #theme-two; +} + diff --git a/integration-tests/tests/themeLoading/themeLoading.mjs b/integration-tests/tests/themeLoading/themeLoading.mjs new file mode 100644 index 0000000..22b2928 --- /dev/null +++ b/integration-tests/tests/themeLoading/themeLoading.mjs @@ -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) + }) +}) + diff --git a/service/internal/api/api.go b/service/internal/api/api.go index f933681..d336235 100644 --- a/service/internal/api/api.go +++ b/service/internal/api/api.go @@ -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) } diff --git a/service/internal/config/config_helpers.go b/service/internal/config/config_helpers.go index 611dbe7..43443dd 100644 --- a/service/internal/config/config_helpers.go +++ b/service/internal/config/config_helpers.go @@ -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] }