Skip to content
Snippets Groups Projects
Commit f7a8474f authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Add tests for datalist and date componenents

parent 84f15153
No related branches found
No related tags found
2 merge requests!813.1,!69Tests integration
......@@ -84,8 +84,8 @@
[label]="attribute.form_label"
[placeholder]="attribute.placeholder_min"
[criterion]="getCriterion(attribute.id)"
(add)="add($event)"
(delete)="delete($event)">
(addCriterion)="add($event)"
(deleteCriterion)="delete($event)">
</app-date>
</div>
<div *ngSwitchCase="'between-date'">
......
......@@ -48,12 +48,6 @@ describe('[Search][Criteria][SearchType] Component: DatalistComponent', () => {
expect(component.getPlaceholder()).toEqual('');
});
it('#getPlaceholder() should fill the placeholder if defined', () => {
const placeholder = '10';
component.placeholder = placeholder;
expect(component.getPlaceholder()).toEqual(placeholder);
});
it('#getDatalistId() should return an id', () => {
component.id = 1;
expect(component.getDatalistId()).toEqual('datalist_' + 1);
......
......@@ -11,10 +11,10 @@
</div>
<div class="col-2 text-center">
<button class="btn btn-outline-success" *ngIf="!field.disabled" [hidden]="!field.value"
(click)="addCriterion()">
(click)="emitAdd()">
<span class="fas fa-plus fa-fw"></span>
</button>
<button class="btn btn-outline-danger" *ngIf="field.disabled" (click)="deleteCriterion()">
<button class="btn btn-outline-danger" *ngIf="field.disabled" (click)="emitDelete()">
<span class="fa fa-times fa-fw"></span>
</button>
</div>
......
......@@ -23,57 +23,52 @@ describe('[Search][Criteria][SearchType] Component: DateComponent', () => {
expect(component).toBeTruthy();
});
// it('#getDefault() should enable and not fill form if criterion not defined', () => {
// const expectedFieldValue = '';
// component.getDefault(undefined);
// expect(component.field.value).toEqual(expectedFieldValue);
// expect(component.field.enabled).toBeTruthy();
// });
// it('#getDefault() should fill and disable form if criterion is defined', () => {
// const value = '10';
// const criterion = new FieldCriterion(1, '=', value);
// const expectedFieldValue = value;
// component.getDefault(criterion);
// expect(component.field.value).toEqual(expectedFieldValue);
// expect(component.field.disabled).toBeTruthy();
// });
it('#getDefault() should enable and not fill form if criterion not defined', () => {
const expectedFieldValue = '';
component.getDefault(undefined);
expect(component.field.value).toEqual(expectedFieldValue);
expect(component.field.enabled).toBeTruthy();
});
// it('#getPlaceholder() should fill the placeholder if defined', () => {
// const placeholder = '10';
// component.placeholder = placeholder;
// expect(component.getPlaceholder()).toEqual(placeholder);
// });
it('#getDefault() should fill and disable form if criterion is defined', () => {
const value = '2019-02-17';
const criterion = new FieldCriterion(1, '=', value);
const expectedFieldValue = new Date(value);
component.getDefault(criterion);
expect(component.field.value).toEqual(expectedFieldValue);
expect(component.field.disabled).toBeTruthy();
});
// it('#getPlaceholder() should not fill the placeholder if not defined', () => {
// expect(component.getPlaceholder()).toEqual('');
// });
it('#getPlaceholder() should fill the placeholder if defined', () => {
const placeholder = '2019-02-17';
component.placeholder = placeholder;
expect(component.getPlaceholder()).toEqual(placeholder);
});
// it('#getPlaceholder() should fill the placeholder if defined', () => {
// const placeholder = '10';
// component.placeholder = placeholder;
// expect(component.getPlaceholder()).toEqual(placeholder);
// });
it('#getPlaceholder() should not fill the placeholder if not defined', () => {
expect(component.getPlaceholder()).toEqual('');
});
// it('#getDatalistId() should return an id', () => {
// component.id = 1;
// expect(component.getDatalistId()).toEqual('datalist_' + 1);
// });
it('#getDateString() should return a date as string', () => {
const dateString = '2019-02-17';
const date = new Date(dateString);
expect(component.getDateString(date)).toEqual(dateString);
});
// it('raises the add criterion event when clicked', () => {
// component.id = 1;
// const operator = '=';
// const value = '10';
// component.field = new FormControl(value);
// component.operator = operator;
// const expectedCriterion = new FieldCriterion(component.id, operator, value);
// component.addCriterion.subscribe((event: FieldCriterion) => expect(event).toEqual(expectedCriterion));
// component.emitAdd();
// });
it('raises the add criterion event when clicked', () => {
component.id = 1;
const operator = '=';
component.operator = operator;
const date = '2019-02-17';
component.field = new FormControl(new Date(date));
const expectedCriterion = new FieldCriterion(component.id, operator, date);
component.addCriterion.subscribe((event: FieldCriterion) => expect(event).toEqual(expectedCriterion));
component.emitAdd();
});
// it('raises the delete criterion event when clicked', () => {
// component.id = 1;
// component.deleteCriterion.subscribe((event: number) => expect(event).toEqual(1));
// component.emitDelete();
// });
it('raises the delete criterion event when clicked', () => {
component.id = 1;
component.deleteCriterion.subscribe((event: number) => expect(event).toEqual(1));
component.emitDelete();
});
});
......@@ -17,18 +17,18 @@ export class DateComponent {
set criterion(criterion: Criterion) {
this.getDefault(criterion);
}
@Output() add: EventEmitter<FieldCriterion> = new EventEmitter();
@Output() delete: EventEmitter<number> = new EventEmitter();
@Output() addCriterion: EventEmitter<FieldCriterion> = new EventEmitter();
@Output() deleteCriterion: EventEmitter<number> = new EventEmitter();
field = new FormControl('');
addCriterion() {
const fd = new FieldCriterion(this.id, this.operator, this.getDateString());
this.add.emit(fd);
emitAdd() {
const fd = new FieldCriterion(this.id, this.operator, this.getDateString(this.field.value));
this.addCriterion.emit(fd);
}
deleteCriterion() {
this.delete.emit(this.id);
emitDelete() {
this.deleteCriterion.emit(this.id);
}
getDefault(criterion: Criterion): void {
......@@ -50,9 +50,9 @@ export class DateComponent {
}
}
getDateString() {
const month = ('0' + (this.field.value.getMonth() + 1)).slice(-2);
const day = ('0' + (this.field.value.getDate())).slice(-2);
return this.field.value.getFullYear() + '-' + month + '-' + day;
getDateString(date: Date) {
const month = ('0' + (date.getMonth() + 1)).slice(-2);
const day = ('0' + (date.getDate())).slice(-2);
return date.getFullYear() + '-' + month + '-' + day;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment