import assert from 'assert'; import { UserProfile, renderUserProfile } from '../src/settings'; describe('renderUserProfile', () => { it('returns empty string when profile is undefined', () => { assert.strictEqual(renderUserProfile(undefined), ''); }); it('returns empty string when profile has no filled fields', () => { const profile: UserProfile = { personal: {}, business: {} }; assert.strictEqual(renderUserProfile(profile), ''); }); it('treats whitespace-only fields as empty', () => { const profile: UserProfile = { personal: { name: ' ', address: '\n\t' }, business: { name: '' }, }; assert.strictEqual(renderUserProfile(profile), ''); }); it('renders only Personal section when business is empty', () => { const profile: UserProfile = { personal: { name: 'Jane Doe' }, }; const out = renderUserProfile(profile); assert.ok(out.startsWith('## Personal Information')); assert.ok(out.includes('**Name:**\nJane Doe')); assert.ok(!out.includes('## Business Information')); }); it('renders only Business section when personal is empty', () => { const profile: UserProfile = { business: { name: 'My Bakery', hours: 'Mon-Fri 9-5' }, }; const out = renderUserProfile(profile); assert.ok(out.startsWith('## Business Information')); assert.ok(out.includes('**Name:**\nMy Bakery')); assert.ok(out.includes('**Hours:**\nMon-Fri 9-5')); assert.ok(!out.includes('## Personal Information')); }); it('renders both sections with Personal first', () => { const profile: UserProfile = { personal: { name: 'Jane', address: '123 Main St' }, business: { name: 'My Bakery', locations: '123 Main St' }, }; const out = renderUserProfile(profile); assert.ok(out.indexOf('## Personal Information') < out.indexOf('## Business Information')); }); it('renders fields in the declared order within a section', () => { const profile: UserProfile = { business: { details: 'Family-owned', hours: 'Mon-Fri 9-5', name: 'My Bakery', locations: '123 Main St', }, }; const out = renderUserProfile(profile); const iName = out.indexOf('**Name:**'); const iLocations = out.indexOf('**Locations:**'); const iHours = out.indexOf('**Hours:**'); const iDetails = out.indexOf('**Details:**'); assert.ok(iName < iLocations); assert.ok(iLocations < iHours); assert.ok(iHours < iDetails); }); it('omits individual empty fields within a section', () => { const profile: UserProfile = { personal: { name: 'Jane', address: '', details: 'vegetarian' }, }; const out = renderUserProfile(profile); assert.ok(out.includes('**Name:**\nJane')); assert.ok(!out.includes('**Address:**')); assert.ok(out.includes('**Details:**\nvegetarian')); }); it('preserves multi-line field values verbatim (trimmed)', () => { const profile: UserProfile = { business: { locations: '123 Main St\nSpringfield, IL\nSuite 4' }, }; const out = renderUserProfile(profile); assert.ok(out.includes('**Locations:**\n123 Main St\nSpringfield, IL\nSuite 4')); }); it('trims leading/trailing whitespace on values', () => { const profile: UserProfile = { personal: { name: ' Jane Doe \n' }, }; const out = renderUserProfile(profile); assert.ok(out.includes('**Name:**\nJane Doe')); assert.ok(!out.includes(' Jane Doe')); }); it('renders a fully populated profile with both sections', () => { const profile: UserProfile = { personal: { name: 'Jane Doe', address: '123 Main St, Springfield IL', details: 'Vegetarian, prefers dark mode', }, business: { name: 'My Bakery', locations: '123 Main St, Springfield IL', hours: 'Mon-Fri 7am-6pm', details: 'Family-owned since 2012', }, }; const out = renderUserProfile(profile); assert.ok(out.includes('## Personal Information')); assert.ok(out.includes('## Business Information')); assert.ok(out.includes('**Name:**\nJane Doe')); assert.ok(out.includes('**Address:**\n123 Main St, Springfield IL')); assert.ok(out.includes('**Details:**\nVegetarian, prefers dark mode')); assert.ok(out.includes('**Name:**\nMy Bakery')); assert.ok(out.includes('**Hours:**\nMon-Fri 7am-6pm')); assert.ok(out.includes('**Details:**\nFamily-owned since 2012')); }); });