import { formatAddressLine } from '../features/order-ship/utils/address'; describe( 'formatAddressLine', () => { // ---- Positive tests ---- it( 'formats a full address into a comma-separated string', () => { const result = formatAddressLine( { name: 'John Smith', address_1: '12 Baker Street', city: 'London', postcode: 'NW1 6XE', country: 'GB', } ); expect( result ).toContain( 'John Smith' ); expect( result ).toContain( '12 Baker Street' ); expect( result ).toContain( 'London' ); expect( result ).toContain( 'NW1 6XE' ); expect( result ).toContain( 'GB' ); } ); it( 'includes address_2 when provided', () => { const result = formatAddressLine( { address_1: '12 Baker Street', address_2: 'Flat 4', city: 'London', country: 'GB', postcode: 'NW1 6XE', } ); expect( result ).toContain( 'Flat 4' ); expect( result ).toContain( '12 Baker Street' ); } ); it( 'combines city and state with a comma', () => { const result = formatAddressLine( { city: 'Springfield', state: 'IL', country: 'US', postcode: '62701', } ); expect( result ).toContain( 'Springfield, IL' ); } ); it( 'works with only a country', () => { const result = formatAddressLine( { country: 'GB' } ); expect( result ).toBe( 'GB' ); } ); // ---- Negative tests ---- it( 'returns dash for null input', () => { expect( formatAddressLine( null ) ).toBe( '—' ); } ); it( 'returns dash for empty object', () => { expect( formatAddressLine( {} ) ).toBe( '—' ); } ); it( 'omits blank fields — no consecutive commas', () => { const result = formatAddressLine( { name: 'Jane', address_1: '', city: '', postcode: 'M1 1AA', country: 'GB', } ); expect( result ).not.toMatch( /,\s*,/ ); expect( result ).toContain( 'Jane' ); } ); it( 'omits undefined fields gracefully', () => { const result = formatAddressLine( { name: 'Test', address_1: undefined, city: 'London', } ); expect( result ).toContain( 'Test' ); expect( result ).toContain( 'London' ); } ); } );