fix(site-builder): navbar logo image never shown — no logoType control
The Navbar renders logoImage only when logoType === 'image', but the
Logo/Text toggle lived in the settings UI removed in 65a10a1 (2026-07-12);
NavStylePanel kept the image picker and never gained the toggle. A picked
logo was stored and silently ignored (editor and published site showed the
text fallback "MySite"; seen on olsdigital.com).
- Logo Type Text/Image toggle in the Navbar Logo section
- picking an image sets logoImage + logoType:'image' in one undo step
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bdb4789903
commit
76f0ba9ca1
2 files changed
+100
-3
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import { describe, test, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import React from 'react';
|
||||
import { createRoot, Root } from 'react-dom/client';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
|
||||
/* Navbar logo: the Navbar only renders logoImage when logoType === 'image', so
|
||||
the panel must expose the type and picking an image must switch to it
|
||||
(olsdigital.com: a picked logo sat in logoImage while the site said "MySite"). */
|
||||
let lastProps: any;
|
||||
const setPropSpy = vi.fn((_id: string, updater: (p: any) => void) => { updater(lastProps); });
|
||||
vi.mock('@craftjs/core', () => ({
|
||||
useEditor: () => ({ actions: { setProp: setPropSpy, history: { merge: () => ({ setProp: setPropSpy }) } } }),
|
||||
}));
|
||||
vi.mock('../../../state/PageContext', () => ({ usePages: () => ({ pages: [] }) }));
|
||||
let pickerOnChange: ((url: string) => void) | null = null;
|
||||
vi.mock('../../../ui/AssetPicker', () => ({
|
||||
AssetPicker: ({ onChange }: { onChange: (url: string) => void }) => { pickerOnChange = onChange; return null; },
|
||||
}));
|
||||
|
||||
import { NavStylePanel } from './NavStylePanel';
|
||||
import { Navbar } from '../../../components/basic/Navbar';
|
||||
import { closeContinuousBurst } from './shared';
|
||||
|
||||
let container: HTMLDivElement;
|
||||
let root: Root;
|
||||
function render(ui: React.ReactElement) {
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
act(() => { root = createRoot(container); root.render(ui); });
|
||||
}
|
||||
const q = (id: string) => container.querySelector(`[data-testid="${id}"]`) as HTMLButtonElement | null;
|
||||
const click = (el: Element | null) => act(() => { (el as HTMLElement).dispatchEvent(new MouseEvent('click', { bubbles: true })); });
|
||||
|
||||
const navProps = () => ({ logoType: 'text', logoText: '', logoImage: '', logoUrl: '/', links: [], style: {} });
|
||||
|
||||
beforeEach(() => { setPropSpy.mockClear(); closeContinuousBurst(); pickerOnChange = null; lastProps = navProps(); });
|
||||
afterEach(() => { act(() => root.unmount()); container.remove(); });
|
||||
|
||||
describe('NavStylePanel navbar logo type', () => {
|
||||
test('shows a Text/Image toggle reflecting logoType, and Image sets logoType', () => {
|
||||
render(<NavStylePanel selectedId="n" nodeProps={lastProps} />);
|
||||
expect(q('navbar-logo-type-text')?.getAttribute('aria-pressed')).toBe('true');
|
||||
expect(q('navbar-logo-type-image')?.getAttribute('aria-pressed')).toBe('false');
|
||||
click(q('navbar-logo-type-image'));
|
||||
expect(lastProps.logoType).toBe('image');
|
||||
});
|
||||
|
||||
test('picking a logo image switches logoType to image in one setProp (one undo step)', () => {
|
||||
render(<NavStylePanel selectedId="n" nodeProps={lastProps} />);
|
||||
act(() => pickerOnChange!('/api/assets-proxy/?site_id=1&filename=logo.webp'));
|
||||
expect(setPropSpy).toHaveBeenCalledTimes(1);
|
||||
expect(lastProps).toMatchObject({ logoType: 'image', logoImage: '/api/assets-proxy/?site_id=1&filename=logo.webp' });
|
||||
});
|
||||
|
||||
test('clearing the image does not force logoType', () => {
|
||||
lastProps = { ...navProps(), logoType: 'image', logoImage: '/x.webp' };
|
||||
render(<NavStylePanel selectedId="n" nodeProps={lastProps} />);
|
||||
act(() => pickerOnChange!(''));
|
||||
expect(lastProps).toMatchObject({ logoType: 'image', logoImage: '' });
|
||||
});
|
||||
|
||||
test('no toggle for components without logoImage (e.g. Footer-style logoText only)', () => {
|
||||
lastProps = { logoText: 'Acme', links: [], style: {} };
|
||||
render(<NavStylePanel selectedId="n" nodeProps={lastProps} />);
|
||||
expect(q('navbar-logo-type-text')).toBeNull();
|
||||
});
|
||||
|
||||
test('export: logoType image + logoImage renders the <img>, not "MySite"', () => {
|
||||
const html = (Navbar as any).toHtml({ ...Navbar.craft!.props, logoType: 'image', logoImage: '/logo.webp', logoText: '' }, '').html as string;
|
||||
expect(html).toContain('<img src="/logo.webp"');
|
||||
expect(html).not.toContain('MySite');
|
||||
});
|
||||
});
|
||||
@@ -190,7 +190,7 @@ const PageLinkRow: React.FC<{ link: NavLink; pages: PageData[]; onHide: (pageId:
|
||||
/* ---------- NAV / MENU / LOGO / FOOTER ---------- */
|
||||
export const NavStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps }) => {
|
||||
const { actions } = useEditor();
|
||||
const { setProp, setPropStyle, setPropContinuous, setPropStyleContinuous } = useNodeProp(selectedId);
|
||||
const { setProp, setProps, setPropStyle, setPropContinuous, setPropStyleContinuous } = useNodeProp(selectedId);
|
||||
const { pages, updatePageNav, isEditingHeader } = usePages();
|
||||
|
||||
const links: NavLink[] = nodeProps.links || [];
|
||||
@@ -405,14 +405,38 @@ export const NavStylePanel: React.FC<StylePanelProps> = ({ selectedId, nodeProps
|
||||
{/* Navbar Logo settings */}
|
||||
{nodeProps.logoText !== undefined && (
|
||||
<CollapsibleSection title="Logo">
|
||||
{/* The Navbar only renders logoImage when logoType is 'image'; without
|
||||
this toggle a picked image was stored but never shown. */}
|
||||
{nodeProps.logoImage !== undefined && (
|
||||
<div style={sectionGap}>
|
||||
<label style={labelStyle}>Logo Type</label>
|
||||
<div style={{ display: 'flex', gap: 4 }}>
|
||||
{(['text', 'image'] as const).map((t) => {
|
||||
const active = (nodeProps.logoType ?? 'text') === t;
|
||||
return (
|
||||
<button
|
||||
key={t}
|
||||
type="button"
|
||||
aria-pressed={active}
|
||||
data-testid={`navbar-logo-type-${t}`}
|
||||
onClick={() => setProp('logoType', t)}
|
||||
style={{ padding: '4px 10px', fontSize: 11, background: active ? '#3b82f6' : '#27272a', color: active ? '#fff' : '#a1a1aa', border: `1px solid ${active ? '#3b82f6' : '#3f3f46'}`, borderRadius: 4, cursor: 'pointer' }}
|
||||
>
|
||||
<i className={t === 'text' ? 'fa fa-font' : 'fa fa-image'} style={{ marginRight: 4 }} />{t === 'text' ? 'Text' : 'Image'}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div style={sectionGap}>
|
||||
<label style={labelStyle}>Logo Text</label>
|
||||
<label style={labelStyle}>{nodeProps.logoImage !== undefined && nodeProps.logoType === 'image' ? 'Logo Alt Text' : 'Logo Text'}</label>
|
||||
<input type="text" value={nodeProps.logoText || ''} onChange={(e) => setPropContinuous('logoText', e.target.value)} style={inputStyle} />
|
||||
</div>
|
||||
{nodeProps.logoImage !== undefined && (
|
||||
<div style={sectionGap}>
|
||||
<label style={labelStyle}>Logo Image</label>
|
||||
<AssetPicker value={nodeProps.logoImage || ''} onChange={(url) => setProp('logoImage', url)} variant="full" />
|
||||
<AssetPicker value={nodeProps.logoImage || ''} onChange={(url) => setProps(url ? { logoImage: url, logoType: 'image' } : { logoImage: url })} variant="full" />
|
||||
</div>
|
||||
)}
|
||||
{nodeProps.logoUrl !== undefined && (
|
||||
|
||||
Reference in new issue
Block a user