feat(web/m7-363): branding helper + window.__MINSTREL__ consumer

This commit is contained in:
2026-05-03 17:30:31 -04:00
parent a4a7225542
commit 6c23dba51b
2 changed files with 86 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { appName, description, pageTitle } from './branding';
const setGlobal = (g: { appName: string; description: string } | undefined) => {
if (g === undefined) {
delete (window as { __MINSTREL__?: unknown }).__MINSTREL__;
} else {
(window as { __MINSTREL__?: typeof g }).__MINSTREL__ = g;
}
};
describe('branding helpers', () => {
beforeEach(() => setGlobal(undefined));
afterEach(() => setGlobal(undefined));
it('appName returns the global value when set', () => {
setGlobal({ appName: 'Family Jukebox', description: 'home' });
expect(appName()).toBe('Family Jukebox');
});
it('appName falls back to "Minstrel" when global is undefined', () => {
expect(appName()).toBe('Minstrel');
});
it('appName falls back to "Minstrel" when value contains an unrendered Go token', () => {
setGlobal({ appName: '{{ .AppName }}', description: 'x' });
expect(appName()).toBe('Minstrel');
});
it('description returns the global value when set', () => {
setGlobal({ appName: 'Minstrel', description: 'Our home library.' });
expect(description()).toBe('Our home library.');
});
it('description falls back to a default tagline when unset', () => {
expect(description()).toContain('Self-hosted music server');
});
it('pageTitle with section returns "{appName} · {section}"', () => {
setGlobal({ appName: 'Minstrel', description: 'x' });
expect(pageTitle('Search')).toBe('Minstrel · Search');
});
it('pageTitle without section returns just the appName', () => {
setGlobal({ appName: 'Minstrel', description: 'x' });
expect(pageTitle()).toBe('Minstrel');
});
it('pageTitle composes nested sections via the · separator', () => {
setGlobal({ appName: 'Minstrel', description: 'x' });
expect(pageTitle('Library · Artists')).toBe('Minstrel · Library · Artists');
});
});