diff --git a/apis/nucleus/src/components/selections/OneField.jsx b/apis/nucleus/src/components/selections/OneField.jsx index 512bab5a1..14096d186 100644 --- a/apis/nucleus/src/components/selections/OneField.jsx +++ b/apis/nucleus/src/components/selections/OneField.jsx @@ -25,7 +25,9 @@ export default function OneField({ const theme = useTheme(); const [showListBoxPopover, setShowListBoxPopover] = useState(false); let Component = null; + let ChildComponent = null; let selection; + let displayName = ''; const isPinnedItem = !!field.isPinned && isPinFieldEnabled; const handleShowListBoxPopover = (e) => { @@ -41,17 +43,8 @@ export default function OneField({ }; if (isPinnedItem) { - Component = ( - - ); + displayName = field.qName || field.qField; + ChildComponent = ; } else { selection = field.selections[stateIx]; if (typeof selection.qTotal === 'undefined') { @@ -159,40 +152,48 @@ export default function OneField({ ))} ); - Component = ( - + ChildComponent = ( + <> {Header} {Icon} {SegmentsIndicator} - {showListBoxPopover && ( - - )} - + ); } } + Component = ( + + {ChildComponent} + {showListBoxPopover && ( + + )} + + ); + return moreAlignTo ? ( - - {displayName} - - {showListBoxPopover && ( - - )} - + + {displayName} + ); } diff --git a/apis/nucleus/src/components/selections/SelectedFields.jsx b/apis/nucleus/src/components/selections/SelectedFields.jsx index 9bfd9e4bc..93fdff6d0 100644 --- a/apis/nucleus/src/components/selections/SelectedFields.jsx +++ b/apis/nucleus/src/components/selections/SelectedFields.jsx @@ -157,7 +157,7 @@ export default function SelectedFields({ api, app, halo }) { {state.items.map((s) => ( ({ - ...jest.requireActual('@nebula.js/ui/theme'), - useTheme: jest.fn(), -})); - -jest.mock('../../listbox/ListBoxPopover', () => ({ - __esModule: true, - default: () =>
ListBoxPopover
, -})); - describe('', () => { let renderer; - beforeEach(() => { - jest.spyOn(NebulaThemeModule, 'useTheme').mockImplementation(() => ({ - palette: { - background: { paper: '#ffffff' }, - action: { hover: '#f5f5f5' }, - divider: '#e0e0e0', - }, - })); - }); - afterEach(() => { - jest.resetAllMocks(); - jest.restoreAllMocks(); if (renderer) { renderer.unmount(); } }); - test('should render field name from qName when available', () => { - const field = { - qName: 'Product', - qField: 'product_field', - }; - const api = { - model: {}, - }; - + test('should render display name', () => { act(() => { - renderer = ReactTestRenderer.create( - - ); + renderer = ReactTestRenderer.create(); }); const output = renderer.toJSON(); expect(JSON.stringify(output)).toContain('Product'); }); - test('should render field name from qField as fallback when qName is not available', () => { - const field = { - qField: 'product_field', - }; - const api = { - model: {}, - }; - + test('should render Typography component with correct styles', () => { act(() => { - renderer = ReactTestRenderer.create( - - ); + renderer = ReactTestRenderer.create(); }); - const output = renderer.toJSON(); - expect(JSON.stringify(output)).toContain('product_field'); + const typography = renderer.root.findByType(Typography); + expect(typography).toBeDefined(); + expect(typography.props.noWrap).toBe(true); + expect(typography.props.style).toMatchObject({ + fontSize: '12px', + lineHeight: '16px', + fontWeight: 600, + marginTop: '8px', + }); }); - test('should call handleShowListBoxPopover when clicked and skipHandleShowListBoxPopover is false', () => { - const handleShowListBoxPopover = jest.fn(); - const field = { - qName: 'Product', - qField: 'product_field', - }; - const api = { - model: {}, - }; - + test('should render empty string when displayName is empty', () => { act(() => { - renderer = ReactTestRenderer.create( - - ); + renderer = ReactTestRenderer.create(); }); - // Verify handler hasn't been called yet - expect(handleShowListBoxPopover).not.toHaveBeenCalled(); - - // Find the clickable element by data-testid - const pinItemElement = renderer.root.findByProps({ 'data-testid': 'pin-item-Product' }); - expect(pinItemElement).toBeDefined(); - - // Simulate click - act(() => { - pinItemElement.props.onClick(); - }); - - // Verify handler was called - expect(handleShowListBoxPopover).toHaveBeenCalledTimes(1); + const typography = renderer.root.findByType(Typography); + expect(typography.props.children).toBe(''); }); - test('should not call handleShowListBoxPopover when skipHandleShowListBoxPopover is true', () => { - const handleShowListBoxPopover = jest.fn(); - const field = { - qName: 'Product', - qField: 'product_field', - }; - const api = { - model: {}, - }; - + test('should handle undefined displayName', () => { act(() => { - renderer = ReactTestRenderer.create( - - ); + renderer = ReactTestRenderer.create(); }); - expect(handleShowListBoxPopover).not.toHaveBeenCalled(); - }); - - test('should render ListBoxPopover when showListBoxPopover is true', () => { - const field = { - qName: 'Product', - qField: 'product_field', - }; - const api = { - model: {}, - }; - const alignToRef = React.createRef(); - - act(() => { - renderer = ReactTestRenderer.create( - - ); - }); - - const output = renderer.toJSON(); - const serialized = JSON.stringify(output); - expect(serialized).toContain('ListBoxPopover'); - }); - - test('should not render ListBoxPopover when showListBoxPopover is false', () => { - const field = { - qName: 'Product', - qField: 'product_field', - }; - const api = { - model: {}, - }; - const alignToRef = React.createRef(); - - act(() => { - renderer = ReactTestRenderer.create( - - ); - }); - - const output = renderer.toJSON(); - const serialized = JSON.stringify(output); - expect(serialized).not.toContain('ListBoxPopover'); + const typography = renderer.root.findByType(Typography); + expect(typography.props.children).toBeUndefined(); }); });