UI-Improvements
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
process.env.DATABASE_PATH = ':memory:';
|
||||
process.env.FRONTEND_DIST = './frontend/dist';
|
||||
process.env.NODE_ENV = 'test';
|
||||
// Intentionally do NOT set process.env.THEMES_DIR — this spec exercises the
|
||||
// default path-resolution behaviour so the test fails if the default ever
|
||||
// regresses to a CWD-relative path.
|
||||
|
||||
import { AdminGeneralService } from '../../backend/src/modules/admin/general.service';
|
||||
import { THEME_IDS } from '../../backend/src/common/types/theme-ids';
|
||||
@@ -20,16 +17,14 @@ describe('AdminGeneralService.listThemes - default THEMES_DIR resolution (Job 89
|
||||
const fakeSettings = { get: jest.fn(), set: jest.fn() } as any;
|
||||
const fakeHub = { emitEvent: jest.fn() } as any;
|
||||
const fakeThemes = { listThemes: () => makeFakeThemeLoader() } as any;
|
||||
// Mimic the production Nest ConfigService: .get('THEMES_DIR', './themes')
|
||||
// returns the literal default string when no env override is present.
|
||||
const fakeConfig = {
|
||||
get: jest.fn().mockImplementation((key: string, fallback?: any) => fallback),
|
||||
} as any;
|
||||
|
||||
it('returns all 10 canonical themes when THEMES_DIR is left at its default', () => {
|
||||
it('returns all canonical themes when THEMES_DIR is left at its default', () => {
|
||||
const svc = new AdminGeneralService(fakeSettings, fakeThemes, fakeHub, fakeConfig);
|
||||
const themes = svc.listThemes();
|
||||
expect(themes.length).toBe(10);
|
||||
expect(themes.length).toBe(THEME_IDS.length);
|
||||
const ids = themes.map((t) => t.id).sort();
|
||||
expect(ids).toEqual([...THEME_IDS].sort());
|
||||
});
|
||||
@@ -44,11 +39,11 @@ describe('AdminGeneralService.listThemes - default THEMES_DIR resolution (Job 89
|
||||
}
|
||||
});
|
||||
|
||||
it('produces the same 10-entry list on repeated calls (no I/O ordering surprises)', () => {
|
||||
it('produces the same canonical entry list on repeated calls', () => {
|
||||
const svc = new AdminGeneralService(fakeSettings, fakeThemes, fakeHub, fakeConfig);
|
||||
const a = svc.listThemes().map((t) => t.id).sort();
|
||||
const b = svc.listThemes().map((t) => t.id).sort();
|
||||
expect(b).toEqual(a);
|
||||
expect(a.length).toBe(10);
|
||||
expect(a.length).toBe(THEME_IDS.length);
|
||||
});
|
||||
});
|
||||
@@ -267,7 +267,7 @@ describe('AdminGeneralService.listThemes - filter to on-disk themes', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('returns the 10 theme entries that have on-disk files', () => {
|
||||
it('returns all theme entries that have on-disk files', () => {
|
||||
const svc = new AdminGeneralService(
|
||||
{ get: jest.fn(), set: jest.fn() } as any,
|
||||
{ listThemes: () => makeFakeThemeLoader() } as any,
|
||||
@@ -275,7 +275,7 @@ describe('AdminGeneralService.listThemes - filter to on-disk themes', () => {
|
||||
{ get: jest.fn().mockReturnValue(themesDir) } as any,
|
||||
);
|
||||
const themes = svc.listThemes();
|
||||
expect(themes.length).toBe(10);
|
||||
expect(themes.length).toBe(THEME_IDS.length);
|
||||
for (const t of themes) {
|
||||
expect(t.id).toBe(t.key);
|
||||
expect(typeof t.name).toBe('string');
|
||||
@@ -292,7 +292,7 @@ describe('AdminGeneralService.listThemes - filter to on-disk themes', () => {
|
||||
);
|
||||
const themes = svc.listThemes();
|
||||
expect(themes.find((t) => t.id === 'classic')).toBeUndefined();
|
||||
expect(themes.length).toBe(9);
|
||||
expect(themes.length).toBe(THEME_IDS.length - 1);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import { DatabaseModule } from '../../backend/src/database/database.module';
|
||||
import { DatabaseInitService } from '../../backend/src/database/database-init.service';
|
||||
import { THEME_IDS } from '../../backend/src/common/types/theme-ids';
|
||||
|
||||
describe('ThemeLoaderService - require 10 + validate configured key', () => {
|
||||
describe('ThemeLoaderService - require canonical + validate configured key', () => {
|
||||
let app: INestApplication;
|
||||
let svc: ThemeLoaderService;
|
||||
|
||||
@@ -41,12 +41,12 @@ describe('ThemeLoaderService - require 10 + validate configured key', () => {
|
||||
if (app) await app.close();
|
||||
});
|
||||
|
||||
it('exposes all 10 canonical theme ids even when THEMES_DIR is empty', async () => {
|
||||
it('exposes all canonical theme ids even when THEMES_DIR is empty', async () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'themes-empty-'));
|
||||
await buildApp(tmp, 'classic');
|
||||
await buildApp(tmp, 'hip');
|
||||
const ids = svc.listThemes().map((t) => t.id).sort();
|
||||
expect(ids).toEqual([
|
||||
'classic', 'crimson', 'cyber', 'forest', 'midnight',
|
||||
'classic', 'crimson', 'cyber', 'forest', 'hip', 'midnight',
|
||||
'monochrome', 'neon', 'ocean', 'paper', 'sunset',
|
||||
]);
|
||||
expect(svc.listThemes().length).toBe(THEME_IDS.length);
|
||||
@@ -54,8 +54,7 @@ describe('ThemeLoaderService - require 10 + validate configured key', () => {
|
||||
|
||||
it('backfills missing disk themes with built-ins (per-id warn)', async () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'themes-partial-'));
|
||||
// Only write 3 of the 10 themes to disk.
|
||||
for (const id of ['classic', 'midnight', 'cyber']) {
|
||||
for (const id of ['hip', 'classic', 'midnight', 'cyber']) {
|
||||
fs.writeFileSync(path.join(tmp, `${id}.json`), JSON.stringify({
|
||||
id,
|
||||
name: id,
|
||||
@@ -67,7 +66,7 @@ describe('ThemeLoaderService - require 10 + validate configured key', () => {
|
||||
},
|
||||
}));
|
||||
}
|
||||
await buildApp(tmp, 'classic');
|
||||
await buildApp(tmp, 'hip');
|
||||
expect(svc.listThemes().length).toBe(THEME_IDS.length);
|
||||
});
|
||||
|
||||
@@ -79,21 +78,21 @@ describe('ThemeLoaderService - require 10 + validate configured key', () => {
|
||||
expect(theme.id).toBe('ocean');
|
||||
});
|
||||
|
||||
it('falls back to classic and warns when configured themeKey is invalid', async () => {
|
||||
it('falls back to default and warns when configured themeKey is invalid', async () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'themes-'));
|
||||
await buildApp(tmp, 'this-theme-does-not-exist');
|
||||
expect(svc.getDefaultId()).toBe('classic');
|
||||
expect(svc.getDefaultId()).toBe('hip');
|
||||
});
|
||||
|
||||
it('falls back to classic and warns when configured themeKey is empty', async () => {
|
||||
it('falls back to default and warns when configured themeKey is empty', async () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'themes-'));
|
||||
await buildApp(tmp, '');
|
||||
expect(svc.getDefaultId()).toBe('classic');
|
||||
expect(svc.getDefaultId()).toBe('hip');
|
||||
});
|
||||
|
||||
it('getTheme() returns a real theme for any canonical id', async () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'themes-'));
|
||||
await buildApp(tmp, 'classic');
|
||||
await buildApp(tmp, 'hip');
|
||||
for (const id of THEME_IDS) {
|
||||
expect(svc.getTheme(id).id).toBe(id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user