view models
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { RecordPageViewInputViewModel } from './RecordPageViewInputViewModel';
|
||||
|
||||
describe('RecordPageViewInputViewModel', () => {
|
||||
it('maps basic fields from input data', () => {
|
||||
const vm = new RecordPageViewInputViewModel({ path: '/home', userId: 'user-1' });
|
||||
|
||||
expect(vm.path).toBe('/home');
|
||||
expect(vm.userId).toBe('user-1');
|
||||
});
|
||||
|
||||
it('normalizes displayPath to always start with a slash', () => {
|
||||
const withLeadingSlash = new RecordPageViewInputViewModel({ path: '/dashboard' });
|
||||
const withoutLeadingSlash = new RecordPageViewInputViewModel({ path: 'settings' });
|
||||
|
||||
expect(withLeadingSlash.displayPath).toBe('/dashboard');
|
||||
expect(withoutLeadingSlash.displayPath).toBe('/settings');
|
||||
});
|
||||
|
||||
it('detects when user context is present', () => {
|
||||
const withUser = new RecordPageViewInputViewModel({ path: '/', userId: 'user-1' });
|
||||
const withoutUser = new RecordPageViewInputViewModel({ path: '/' });
|
||||
const emptyUserId = new RecordPageViewInputViewModel({ path: '/', userId: '' });
|
||||
|
||||
expect(withUser.hasUserContext).toBe(true);
|
||||
expect(withoutUser.hasUserContext).toBe(false);
|
||||
expect(emptyUserId.hasUserContext).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user