view models
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { SponsorSettingsViewModel, SponsorProfileViewModel, NotificationSettingsViewModel, PrivacySettingsViewModel } from './SponsorSettingsViewModel';
|
||||
|
||||
describe('SponsorSettingsViewModel', () => {
|
||||
const profile = {
|
||||
companyName: 'Acme Corp',
|
||||
contactName: 'John Doe',
|
||||
contactEmail: 'john@example.com',
|
||||
contactPhone: '+1234567890',
|
||||
website: 'https://acme.example',
|
||||
description: 'We sponsor racing',
|
||||
logoUrl: '/logo.png',
|
||||
industry: 'Automotive',
|
||||
address: {
|
||||
street: '123 Main St',
|
||||
city: 'Metropolis',
|
||||
country: 'US',
|
||||
postalCode: '12345',
|
||||
},
|
||||
taxId: 'TAX-123',
|
||||
socialLinks: {
|
||||
twitter: '@acme',
|
||||
linkedin: 'https://linkedin.com/acme',
|
||||
instagram: '@acme_insta',
|
||||
},
|
||||
};
|
||||
|
||||
const notifications = {
|
||||
emailNewSponsorships: true,
|
||||
emailWeeklyReport: false,
|
||||
emailRaceAlerts: true,
|
||||
emailPaymentAlerts: false,
|
||||
emailNewOpportunities: true,
|
||||
emailContractExpiry: true,
|
||||
};
|
||||
|
||||
const privacy = {
|
||||
publicProfile: true,
|
||||
showStats: false,
|
||||
showActiveSponsorships: true,
|
||||
allowDirectContact: false,
|
||||
};
|
||||
|
||||
it('maps raw settings object into nested view models', () => {
|
||||
const vm = new SponsorSettingsViewModel({ profile, notifications, privacy });
|
||||
|
||||
expect(vm.profile).toBeInstanceOf(SponsorProfileViewModel);
|
||||
expect(vm.notifications).toBeInstanceOf(NotificationSettingsViewModel);
|
||||
expect(vm.privacy).toBeInstanceOf(PrivacySettingsViewModel);
|
||||
|
||||
expect(vm.profile.companyName).toBe(profile.companyName);
|
||||
expect(vm.notifications.emailNewSponsorships).toBe(true);
|
||||
expect(vm.privacy.publicProfile).toBe(true);
|
||||
});
|
||||
|
||||
it('exposes fullAddress computed from address fields', () => {
|
||||
const profileVm = new SponsorProfileViewModel(profile);
|
||||
|
||||
expect(profileVm.fullAddress).toBe(
|
||||
`${profile.address.street}, ${profile.address.city}, ${profile.address.postalCode}, ${profile.address.country}`,
|
||||
);
|
||||
});
|
||||
|
||||
it('preserves notification and privacy boolean flags', () => {
|
||||
const notificationsVm = new NotificationSettingsViewModel(notifications);
|
||||
const privacyVm = new PrivacySettingsViewModel(privacy);
|
||||
|
||||
expect(notificationsVm.emailWeeklyReport).toBe(false);
|
||||
expect(notificationsVm.emailContractExpiry).toBe(true);
|
||||
|
||||
expect(privacyVm.showStats).toBe(false);
|
||||
expect(privacyVm.allowDirectContact).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user