mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
added create-from functionality
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
<input required #string="ngModel" type="text" name="string-value-{{index}}" class="form-control" id="string-value-{{index}}" [ngModel]="value" (ngModelChange)="setValue($event)"/>
|
||||
<div *ngIf="string.invalid && (string.dirty || string.touched)"
|
||||
class="alert alert-danger validation-error">
|
||||
<div *ngIf="string.errors.required">
|
||||
{{'process.new.parameter.string.required' | translate}}
|
||||
</div>
|
||||
</div>
|
@@ -0,0 +1,72 @@
|
||||
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||
|
||||
import { FormsModule, NgForm } from '@angular/forms';
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { StringValueInputComponent } from './string-value-input.component';
|
||||
import { TranslateLoaderMock } from '../../../../../shared/mocks/translate-loader.mock';
|
||||
|
||||
describe('StringValueInputComponent', () => {
|
||||
let component: StringValueInputComponent;
|
||||
let fixture: ComponentFixture<StringValueInputComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
FormsModule,
|
||||
TranslateModule.forRoot({
|
||||
loader: {
|
||||
provide: TranslateLoader,
|
||||
useClass: TranslateLoaderMock
|
||||
}
|
||||
})],
|
||||
declarations: [StringValueInputComponent],
|
||||
providers: [
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(StringValueInputComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should not show a validation error if the input field was left untouched but left empty', () => {
|
||||
const validationError = fixture.debugElement.query(By.css('.validation-error'));
|
||||
expect(validationError).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should show a validation error if the input field was touched but left empty', fakeAsync(() => {
|
||||
component.value = '';
|
||||
fixture.detectChanges();
|
||||
tick();
|
||||
|
||||
const input = fixture.debugElement.query(By.css('input'));
|
||||
input.triggerEventHandler('blur', null);
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const validationError = fixture.debugElement.query(By.css('.validation-error'));
|
||||
expect(validationError).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should not show a validation error if the input field was touched but not left empty', fakeAsync(() => {
|
||||
component.value = 'testValue';
|
||||
fixture.detectChanges();
|
||||
tick();
|
||||
|
||||
const input = fixture.debugElement.query(By.css('input'));
|
||||
input.triggerEventHandler('blur', null);
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
const validationError = fixture.debugElement.query(By.css('.validation-error'));
|
||||
expect(validationError).toBeFalsy();
|
||||
}));
|
||||
});
|
@@ -0,0 +1,32 @@
|
||||
import { Component, Optional, Input } from '@angular/core';
|
||||
import { ValueInputComponent } from '../value-input.component';
|
||||
import { ControlContainer, NgForm } from '@angular/forms';
|
||||
import { controlContainerFactory } from '../../../process-form.component';
|
||||
|
||||
/**
|
||||
* Represents the user inputted value of a string parameter
|
||||
*/
|
||||
@Component({
|
||||
selector: 'ds-string-value-input',
|
||||
templateUrl: './string-value-input.component.html',
|
||||
styleUrls: ['./string-value-input.component.scss'],
|
||||
viewProviders: [ { provide: ControlContainer,
|
||||
useFactory: controlContainerFactory,
|
||||
deps: [[new Optional(), NgForm]] } ]
|
||||
})
|
||||
export class StringValueInputComponent extends ValueInputComponent<string> {
|
||||
/**
|
||||
* The current value of the string
|
||||
*/
|
||||
value: string;
|
||||
@Input() initialValue;
|
||||
|
||||
ngOnInit() {
|
||||
this.value = this.initialValue;
|
||||
}
|
||||
|
||||
setValue(value) {
|
||||
this.value = value;
|
||||
this.updateValue.emit(value)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user