Commit bf803465 authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

WIP: add tests

parent d14453c8
......@@ -92,7 +92,7 @@
[operator]="attribute.operator"
[label]="attribute.form_label"
[criterion]="getCriterion(attribute.id)"
(add)="add($event)"
(addCriterion)="add($event)"
(deleteCriterion)="delete($event)">
</app-between-date>
</div>
......
......@@ -12,7 +12,7 @@
</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)="emitDelete()">
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BsDatepickerModule } from 'ngx-bootstrap';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { FormsModule, ReactiveFormsModule, FormControl } from '@angular/forms';
import { BetweenDateComponent } from './between-date.component';
import { Criterion, BetweenCriterion } from '../../../store/model';
import { BetweenCriterion } from '../../../store/model';
describe('[Search][Criteria][SearchType] Component: BetweenDateComponent', () => {
let component: BetweenDateComponent;
......@@ -45,15 +45,19 @@ describe('[Search][Criteria][SearchType] Component: BetweenDateComponent', () =>
expect(component.field.disabled).toBeTruthy();
});
// it('raises the add criterion event when clicked', () => {
// component.id = 123;
// component.deleteCriterion.subscribe((event: number) => expect(event).toEqual(component.id));
// component.emitDelete();
// });
// it('raises the delete criterion event when clicked', () => {
// component.id = 123;
// component.deleteCriterion.subscribe((event: number) => expect(event).toEqual(component.id));
// component.emitDelete();
// });
it('raises the add criterion event when clicked', () => {
component.id = 1;
const dateMin = '2019-02-08';
const dateMax = '2019-02-17';
component.field = new FormControl([new Date(dateMin), new Date(dateMax)]);
const expectedCriterion = new BetweenCriterion(component.id, dateMin, dateMax);
component.addCriterion.subscribe((event: BetweenCriterion) => 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();
});
});
......@@ -16,20 +16,19 @@ export class BetweenDateComponent {
set criterion(criterion: Criterion) {
this.getDefault(criterion);
}
@Output() add: EventEmitter<BetweenCriterion> = new EventEmitter();
@Output() addCriterion: EventEmitter<BetweenCriterion> = new EventEmitter();
@Output() deleteCriterion: EventEmitter<number> = new EventEmitter();
field = new FormControl('');
addCriterion(): void {
console.log(this.field.value);
emitAdd(): void {
const dateMin = this.getDateString(this.field.value[0]);
const dateMax = this.getDateString(this.field.value[1]);
const fd = new BetweenCriterion(this.id, dateMin, dateMax);
this.add.emit(fd);
this.addCriterion.emit(fd);
}
emitDelete() {
emitDelete(): void {
this.deleteCriterion.emit(this.id);
}
......
import { BetweenCriterion } from './between-criterion.model';
describe('[Search] Model: BetweenCriterion', () => {
it('should print criterion correctly', () => {
const dateMin = '2019-02-08';
const dateMax = '2019-02-17';
const criterion = new BetweenCriterion(1, dateMin, dateMax);
const expectedPrintedCriterion = '∈ [' + dateMin + ';' + dateMax + ']';
expect(criterion.printCriterion()).toEqual(expectedPrintedCriterion);
const criterionMin = new BetweenCriterion(1, dateMin, '');
const expectedPrintedCriterionMin = '>= ' + dateMin;
expect(criterionMin.printCriterion()).toEqual(expectedPrintedCriterionMin);
const criterionMax = new BetweenCriterion(1, '', dateMax);
const expectedPrintedCriterionMax = '<= ' + dateMax;
expect(criterionMax.printCriterion()).toEqual(expectedPrintedCriterionMax);
});
it('should print criterion url string correctly', () => {
const id = 1;
const dateMin = '2019-02-08';
const dateMax = '2019-02-17';
const criterion = new BetweenCriterion(id, dateMin, dateMax);
const expectedPrintedCriterion = id + '::bw::' + dateMin + '|' + dateMax;
expect(criterion.getCriterionStr()).toEqual(expectedPrintedCriterion);
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment