|
3 | 3 | FieldSchema, |
4 | 4 | FieldType, |
5 | 5 | SelectOptionSchema, |
6 | | - type Field, |
| 6 | + Field, |
7 | 7 | type SelectOption |
8 | 8 | } from './field.zod'; |
9 | 9 |
|
@@ -304,3 +304,122 @@ describe('FieldSchema', () => { |
304 | 304 | }); |
305 | 305 | }); |
306 | 306 | }); |
| 307 | + |
| 308 | +describe('Field Factory Helpers', () => { |
| 309 | + describe('Basic Field Types', () => { |
| 310 | + it('should create phone field', () => { |
| 311 | + const phoneField = Field.phone({ label: 'Mobile Phone', required: true }); |
| 312 | + |
| 313 | + expect(phoneField.type).toBe('phone'); |
| 314 | + expect(phoneField.label).toBe('Mobile Phone'); |
| 315 | + expect(phoneField.required).toBe(true); |
| 316 | + }); |
| 317 | + |
| 318 | + it('should create text field', () => { |
| 319 | + const textField = Field.text({ label: 'Name', maxLength: 100 }); |
| 320 | + |
| 321 | + expect(textField.type).toBe('text'); |
| 322 | + expect(textField.label).toBe('Name'); |
| 323 | + expect(textField.maxLength).toBe(100); |
| 324 | + }); |
| 325 | + |
| 326 | + it('should create email field', () => { |
| 327 | + const emailField = Field.email({ label: 'Email Address' }); |
| 328 | + |
| 329 | + expect(emailField.type).toBe('email'); |
| 330 | + expect(emailField.label).toBe('Email Address'); |
| 331 | + }); |
| 332 | + }); |
| 333 | + |
| 334 | + describe('Select Field Factory', () => { |
| 335 | + it('should create select field with string array (old API)', () => { |
| 336 | + const selectField = Field.select(['High', 'Medium', 'Low'], { label: 'Priority' }); |
| 337 | + |
| 338 | + expect(selectField.type).toBe('select'); |
| 339 | + expect(selectField.label).toBe('Priority'); |
| 340 | + expect(selectField.options).toHaveLength(3); |
| 341 | + expect(selectField.options[0]).toEqual({ label: 'High', value: 'High' }); |
| 342 | + }); |
| 343 | + |
| 344 | + it('should create select field with SelectOption array in config (new API)', () => { |
| 345 | + const selectField = Field.select({ |
| 346 | + label: 'Priority', |
| 347 | + options: [ |
| 348 | + { label: 'High Priority', value: 'high', color: '#FF0000' }, |
| 349 | + { label: 'Low Priority', value: 'low', color: '#00FF00' }, |
| 350 | + ], |
| 351 | + }); |
| 352 | + |
| 353 | + expect(selectField.type).toBe('select'); |
| 354 | + expect(selectField.label).toBe('Priority'); |
| 355 | + expect(selectField.options).toHaveLength(2); |
| 356 | + expect(selectField.options[0].color).toBe('#FF0000'); |
| 357 | + expect(selectField.options[1].value).toBe('low'); |
| 358 | + }); |
| 359 | + |
| 360 | + it('should create select field with mixed string/object array (new API)', () => { |
| 361 | + const selectField = Field.select({ |
| 362 | + label: 'Status', |
| 363 | + options: [ |
| 364 | + { label: 'Active', value: 'active', color: '#00AA00' }, |
| 365 | + 'Inactive', |
| 366 | + 'Pending', |
| 367 | + ], |
| 368 | + }); |
| 369 | + |
| 370 | + expect(selectField.type).toBe('select'); |
| 371 | + expect(selectField.options).toHaveLength(3); |
| 372 | + expect(selectField.options[0]).toEqual({ label: 'Active', value: 'active', color: '#00AA00' }); |
| 373 | + expect(selectField.options[1]).toEqual({ label: 'Inactive', value: 'Inactive' }); |
| 374 | + expect(selectField.options[2]).toEqual({ label: 'Pending', value: 'Pending' }); |
| 375 | + }); |
| 376 | + }); |
| 377 | + |
| 378 | + describe('Multiselect Field Factory', () => { |
| 379 | + it('should create multiselect field with string array (old API)', () => { |
| 380 | + const multiselectField = Field.multiselect(['Tag1', 'Tag2', 'Tag3'], { label: 'Tags' }); |
| 381 | + |
| 382 | + expect(multiselectField.type).toBe('multiselect'); |
| 383 | + expect(multiselectField.label).toBe('Tags'); |
| 384 | + expect(multiselectField.options).toHaveLength(3); |
| 385 | + }); |
| 386 | + |
| 387 | + it('should create multiselect field with SelectOption array (new API)', () => { |
| 388 | + const multiselectField = Field.multiselect({ |
| 389 | + label: 'Categories', |
| 390 | + options: [ |
| 391 | + { label: 'Technology', value: 'tech' }, |
| 392 | + { label: 'Business', value: 'biz' }, |
| 393 | + ], |
| 394 | + }); |
| 395 | + |
| 396 | + expect(multiselectField.type).toBe('multiselect'); |
| 397 | + expect(multiselectField.options).toHaveLength(2); |
| 398 | + expect(multiselectField.options[0].value).toBe('tech'); |
| 399 | + }); |
| 400 | + }); |
| 401 | + |
| 402 | + describe('Lookup and Master-Detail Fields', () => { |
| 403 | + it('should create lookup field', () => { |
| 404 | + const lookupField = Field.lookup('account', { |
| 405 | + label: 'Account', |
| 406 | + referenceFilters: ['status = "active"'], |
| 407 | + }); |
| 408 | + |
| 409 | + expect(lookupField.type).toBe('lookup'); |
| 410 | + expect(lookupField.reference).toBe('account'); |
| 411 | + expect(lookupField.label).toBe('Account'); |
| 412 | + }); |
| 413 | + |
| 414 | + it('should create master_detail field', () => { |
| 415 | + const masterDetailField = Field.master_detail('parent_object', { |
| 416 | + label: 'Parent', |
| 417 | + deleteBehavior: 'cascade', |
| 418 | + }); |
| 419 | + |
| 420 | + expect(masterDetailField.type).toBe('master_detail'); |
| 421 | + expect(masterDetailField.reference).toBe('parent_object'); |
| 422 | + expect(masterDetailField.deleteBehavior).toBe('cascade'); |
| 423 | + }); |
| 424 | + }); |
| 425 | +}); |
0 commit comments