mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Added changes to select the default value
This commit is contained in:
committed by
Mario Romano
parent
a915c0ad6a
commit
87d4cfcc41
@@ -21,15 +21,21 @@ 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';
|
import { FormFieldOption } from './../core/form-field-option';
|
||||||
|
import { CoreModule } from 'ng2-alfresco-core';
|
||||||
|
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||||
|
import { EcmModelService } from '../../../services/ecm-model.service';
|
||||||
|
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
|
||||||
|
|
||||||
describe('DropdownWidget', () => {
|
describe('DropdownWidget', () => {
|
||||||
|
|
||||||
let formService: FormService;
|
let formService: FormService;
|
||||||
let widget: DropdownWidget;
|
let widget: DropdownWidget;
|
||||||
|
let visibilityService: WidgetVisibilityService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
formService = new FormService(null, null);
|
formService = new FormService(null, null);
|
||||||
widget = new DropdownWidget(formService);
|
visibilityService = new WidgetVisibilityService(null, null, null);
|
||||||
|
widget = new DropdownWidget(formService, visibilityService);
|
||||||
widget.field = new FormFieldModel(new FormModel());
|
widget.field = new FormFieldModel(new FormModel());
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -104,45 +110,74 @@ describe('DropdownWidget', () => {
|
|||||||
let fixture: ComponentFixture<DropdownWidget>;
|
let fixture: ComponentFixture<DropdownWidget>;
|
||||||
let element: HTMLElement;
|
let element: HTMLElement;
|
||||||
let componentHandler;
|
let componentHandler;
|
||||||
|
let stubFormService;
|
||||||
|
let fakeOptionList: FormFieldOption[] = [{ id: 'opt_1', name: 'option_1' }, {
|
||||||
|
id: 'opt_2',
|
||||||
|
name: 'option_2'
|
||||||
|
}, { id: 'opt_3', name: 'option_3' }];
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
componentHandler = jasmine.createSpyObj('componentHandler', ['upgradeAllRegistered', 'upgradeElement']);
|
componentHandler = jasmine.createSpyObj('componentHandler', ['upgradeAllRegistered', 'upgradeElement']);
|
||||||
window['componentHandler'] = componentHandler;
|
window['componentHandler'] = componentHandler;
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [CoreModule],
|
imports: [CoreModule],
|
||||||
declarations: [DropdownWidget]
|
declarations: [DropdownWidget],
|
||||||
|
providers: [FormService, EcmModelService, WidgetVisibilityService]
|
||||||
}).compileComponents().then(() => {
|
}).compileComponents().then(() => {
|
||||||
fixture = TestBed.createComponent(DropdownWidget);
|
fixture = TestBed.createComponent(DropdownWidget);
|
||||||
dateWidget = fixture.componentInstance;
|
dropDownWidget = fixture.componentInstance;
|
||||||
element = fixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(async(() => {
|
||||||
spyOn(dateWidget, 'setupMaterialTextField').and.stub();
|
stubFormService = fixture.debugElement.injector.get(FormService);
|
||||||
dateWidget.field = new FormFieldModel(new FormModel(), {
|
visibilityService = fixture.debugElement.injector.get(WidgetVisibilityService);
|
||||||
id: 'date-field-id',
|
spyOn(visibilityService, 'refreshVisibility').and.stub();
|
||||||
|
spyOn(stubFormService, 'getRestFieldValues').and.returnValue(Observable.of(fakeOptionList));
|
||||||
|
dropDownWidget.field = new FormFieldModel(new FormModel({ taskId: 'fake-task-id' }), {
|
||||||
|
id: 'dropdown-id',
|
||||||
name: 'date-name',
|
name: 'date-name',
|
||||||
value: '9-9-9999',
|
type: 'dropdown',
|
||||||
type: 'date',
|
readOnly: 'false',
|
||||||
readOnly: 'false'
|
restUrl: 'fake-rest-url'
|
||||||
});
|
});
|
||||||
dateWidget.field.isVisible = true;
|
dropDownWidget.field.isVisible = true;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
}));
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
fixture.destroy();
|
fixture.destroy();
|
||||||
TestBed.resetTestingModule();
|
TestBed.resetTestingModule();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show visible date widget', async(() => {
|
it('should show visible dropdown widget', async(() => {
|
||||||
|
expect(element.querySelector('#dropdown-id')).toBeDefined();
|
||||||
|
expect(element.querySelector('#dropdown-id')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#opt_1')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#opt_2')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#opt_3')).not.toBeNull();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should select the default value', async(() => {
|
||||||
|
dropDownWidget.field.value = 'option_2';
|
||||||
|
fixture.detectChanges();
|
||||||
fixture.whenStable()
|
fixture.whenStable()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
expect(element.querySelector('#date-field-id')).toBeDefined();
|
let dropDownElement: HTMLSelectElement = <HTMLSelectElement> element.querySelector('#dropdown-id');
|
||||||
expect(element.querySelector('#date-field-id')).not.toBeNull();
|
expect(dropDownElement).not.toBeNull();
|
||||||
let dateElement: any = element.querySelector('#date-field-id');
|
expect(element.querySelector('#opt_2')).not.toBeNull();
|
||||||
expect(dateElement.value).toEqual('9-9-9999');
|
expect(dropDownElement.value).toBe('option_2');
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should be not visibile when isVisible is false', async(() => {
|
||||||
|
dropDownWidget.field.isVisible = false;
|
||||||
|
fixture.detectChanges();
|
||||||
|
fixture.whenStable()
|
||||||
|
.then(() => {
|
||||||
|
let dropDownElement: HTMLSelectElement = <HTMLSelectElement> element.querySelector('#dropdown-id');
|
||||||
|
expect(dropDownElement).toBeNull();
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
import { FormService } from '../../../services/form.service';
|
import { FormService } from '../../../services/form.service';
|
||||||
import { WidgetComponent } from './../widget.component';
|
import { WidgetComponent } from './../widget.component';
|
||||||
import { FormFieldOption } from './../core/form-field-option';
|
import { FormFieldOption } from './../core/form-field-option';
|
||||||
|
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
@@ -28,16 +29,17 @@ import { FormFieldOption } from './../core/form-field-option';
|
|||||||
})
|
})
|
||||||
export class DropdownWidget extends WidgetComponent implements OnInit {
|
export class DropdownWidget extends WidgetComponent implements OnInit {
|
||||||
|
|
||||||
constructor(private formService: FormService) {
|
constructor(private formService: FormService,
|
||||||
|
private visibilityService: WidgetVisibilityService) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.field && this.field.restUrl) {
|
if (this.field && this.field.restUrl) {
|
||||||
if (this.field.form.processDefinitionId) {
|
if (this.field.form.taskId) {
|
||||||
this.getValuesByProcessDefinitionId();
|
|
||||||
} else {
|
|
||||||
this.getValuesByTaskId();
|
this.getValuesByTaskId();
|
||||||
|
} else {
|
||||||
|
this.getValuesByProcessDefinitionId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,6 +92,10 @@ export class DropdownWidget extends WidgetComponent implements OnInit {
|
|||||||
return optionValue;
|
return optionValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkVisibility() {
|
||||||
|
this.visibilityService.refreshVisibility(this.field.form);
|
||||||
|
}
|
||||||
|
|
||||||
handleError(error: any) {
|
handleError(error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user