chore: Fix broken unit tests, add themeLoading test
This commit is contained in:
parent
9b032196be
commit
93d56cc42e
|
|
@ -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
|
||||||
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
/* Theme One CSS */
|
||||||
|
body {
|
||||||
|
background-color: #theme-one;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
/* Theme Two CSS */
|
||||||
|
body {
|
||||||
|
background-color: #theme-two;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -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)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
@ -913,7 +913,12 @@ func (api *oliveTinAPI) Init(ctx ctx.Context, req *connect.Request[apiv1.InitReq
|
||||||
// discoverAvailableThemes finds all available themes in the custom-webui/themes directory.
|
// discoverAvailableThemes finds all available themes in the custom-webui/themes directory.
|
||||||
// A theme is considered available if it has a theme.css file.
|
// A theme is considered available if it has a theme.css file.
|
||||||
func discoverAvailableThemes(cfg *config.Config) []string {
|
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)
|
entries, err := os.ReadDir(themesDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -58,5 +58,8 @@ func (cfg *Config) SetDir(dir string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *Config) GetDir() string {
|
func (cfg *Config) GetDir() string {
|
||||||
|
if len(cfg.sourceFiles) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
return cfg.sourceFiles[len(cfg.sourceFiles)-1]
|
return cfg.sourceFiles[len(cfg.sourceFiles)-1]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue