forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in DSC-828 (pull request DSpace#398)
- Loading branch information
Showing
7 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...ess-parameters/parameter-value-input/number-value-input/number-value-input.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<input required #string="ngModel" type="number" name="number-value-{{index}}" class="form-control" id="number-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.number.required' | translate}} | ||
</div> | ||
</div> |
Empty file.
72 changes: 72 additions & 0 deletions
72
...-parameters/parameter-value-input/number-value-input/number-value-input.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing'; | ||
|
||
import { FormsModule } from '@angular/forms'; | ||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; | ||
import { By } from '@angular/platform-browser'; | ||
import { NumberValueInputComponent } from './number-value-input.component'; | ||
import { TranslateLoaderMock } from '../../../../../shared/mocks/translate-loader.mock'; | ||
|
||
describe('NumberValueInputComponent', () => { | ||
let component: NumberValueInputComponent; | ||
let fixture: ComponentFixture<NumberValueInputComponent>; | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
FormsModule, | ||
TranslateModule.forRoot({ | ||
loader: { | ||
provide: TranslateLoader, | ||
useClass: TranslateLoaderMock | ||
} | ||
})], | ||
declarations: [NumberValueInputComponent], | ||
providers: [ | ||
] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(NumberValueInputComponent); | ||
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(); | ||
})); | ||
}); |
36 changes: 36 additions & 0 deletions
36
...ocess-parameters/parameter-value-input/number-value-input/number-value-input.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
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 numeric parameter | ||
*/ | ||
@Component({ | ||
selector: 'ds-number-value-input', | ||
templateUrl: './number-value-input.component.html', | ||
styleUrls: ['./number-value-input.component.scss'], | ||
viewProviders: [ { provide: ControlContainer, | ||
useFactory: controlContainerFactory, | ||
deps: [[new Optional(), NgForm]] } ] | ||
}) | ||
export class NumberValueInputComponent extends ValueInputComponent<string> { | ||
/** | ||
* The current value of the string | ||
*/ | ||
value: string; | ||
|
||
/** | ||
* Initial value of the field | ||
*/ | ||
@Input() initialValue; | ||
|
||
ngOnInit() { | ||
this.value = this.initialValue; | ||
} | ||
|
||
setValue(value) { | ||
this.value = value; | ||
this.updateValue.emit(value); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...s-page/form/process-parameters/parameter-value-input/parameter-value-input.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters