mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Dropdown widget tests
This commit is contained in:
@@ -20,6 +20,7 @@ import { FormService } from '../../../services/form.service';
|
|||||||
import { DropdownWidget } from './dropdown.widget';
|
import { DropdownWidget } from './dropdown.widget';
|
||||||
import { FormModel } from './../core/form.model';
|
import { FormModel } from './../core/form.model';
|
||||||
import { FormFieldModel } from './../core/form-field.model';
|
import { FormFieldModel } from './../core/form-field.model';
|
||||||
|
import { FormFieldOption } from './../core/form-field-option';
|
||||||
|
|
||||||
describe('DropdownWidget', () => {
|
describe('DropdownWidget', () => {
|
||||||
|
|
||||||
@@ -32,6 +33,18 @@ describe('DropdownWidget', () => {
|
|||||||
widget.field = new FormFieldModel(new FormModel());
|
widget.field = new FormFieldModel(new FormModel());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should require field with restUrl', () => {
|
||||||
|
spyOn(formService, 'getRestFieldValues').and.stub();
|
||||||
|
|
||||||
|
widget.field = null;
|
||||||
|
widget.ngOnInit();
|
||||||
|
expect(formService.getRestFieldValues).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
widget.field = new FormFieldModel(null, { restUrl: null });
|
||||||
|
widget.ngOnInit();
|
||||||
|
expect(formService.getRestFieldValues).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should request field values from service', () => {
|
it('should request field values from service', () => {
|
||||||
const taskId = '<form-id>';
|
const taskId = '<form-id>';
|
||||||
const fieldId = '<field-id>';
|
const fieldId = '<field-id>';
|
||||||
@@ -58,4 +71,27 @@ describe('DropdownWidget', () => {
|
|||||||
widget.handleError('Err');
|
widget.handleError('Err');
|
||||||
expect(console.error).toHaveBeenCalledWith('Err');
|
expect(console.error).toHaveBeenCalledWith('Err');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should preserve empty option when loading fields', () => {
|
||||||
|
let restFieldValue: FormFieldOption = <FormFieldOption> { id: '1', name: 'Option1' };
|
||||||
|
spyOn(formService, 'getRestFieldValues').and.returnValue(Observable.create(observer => {
|
||||||
|
observer.next([restFieldValue]);
|
||||||
|
observer.complete();
|
||||||
|
}));
|
||||||
|
|
||||||
|
let form = new FormModel({ taskId: '<id>' });
|
||||||
|
let emptyOption: FormFieldOption = <FormFieldOption> { id: 'empty', name: 'Empty' };
|
||||||
|
widget.field = new FormFieldModel(form, {
|
||||||
|
id: '<id>',
|
||||||
|
restUrl: '/some/url/address',
|
||||||
|
hasEmptyValue: true,
|
||||||
|
options: [emptyOption]
|
||||||
|
});
|
||||||
|
widget.ngOnInit();
|
||||||
|
|
||||||
|
expect(formService.getRestFieldValues).toHaveBeenCalled();
|
||||||
|
expect(widget.field.options.length).toBe(2);
|
||||||
|
expect(widget.field.options[0]).toBe(emptyOption);
|
||||||
|
expect(widget.field.options[1]).toBe(restFieldValue);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user