added unit tests for angular

pull/8/head
Driton Dauti 4 years ago
parent a813028f88
commit 756faac527

@ -0,0 +1,137 @@
import {async, TestBed} from '@angular/core/testing';
import {CellComponent} from './cell.component';
import {DatePipe} from '@angular/common';
describe('CellComponent', () => {
let fixture, cell;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [CellComponent],
providers: [DatePipe]
});
fixture = TestBed.createComponent(CellComponent);
cell = fixture.componentInstance;
});
it('should accept value true', async(() => {
cell._value = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell._value).toBe(true);
});
}));
it('should set value true', async(() => {
cell.value = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell._value).toBe(true);
});
}));
it('should return value false', async(() => {
cell._value = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell.value).toBe(false);
});
}));
it('should accept editable true', async(() => {
cell._editable = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell._editable).toBe(true);
});
}));
it('should set editable false', async(() => {
cell.editable = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell._editable).toBe(false);
});
}));
it('should return editable false', async(() => {
cell._editable = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell.editable).toBe(false);
});
}));
it('should accept input type String', async(() => {
cell._inputType = 'String';
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell._inputType).toBe('String');
});
}));
it('should set input type String', async(() => {
cell.inputType = 'String';
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell._inputType).toBe('String');
});
}));
it('should return input type String', async(() => {
cell._inputType = 'String';
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell.inputType).toBe('String');
});
}));
it('should accept required true', async(() => {
cell._required = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell._required).toBe(true);
});
}));
it('should set required false', async(() => {
cell.required = false;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell._required).toBe(false);
});
}));
it('should return required true', async(() => {
cell._required = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell.required).toBe(true);
});
}));
it('should return html input type text', async(() => {
cell.getHtmlInputType('String');
expect(cell.htmlInputType).toBe('text');
}));
it('should return html input type enum', async(() => {
cell.getHtmlInputType('Enum');
expect(cell.htmlInputType).toBe('enum');
}));
it('should return html input type number', async(() => {
cell.getHtmlInputType('Int');
expect(cell.htmlInputType).toBe('number');
}));
it('should return html input type boolean', async(() => {
cell.getHtmlInputType('Boolean');
expect(cell.htmlInputType).toBe('boolean');
}));
});

@ -0,0 +1,50 @@
import {async, TestBed} from "@angular/core/testing";
import {CellComponent} from "../cell/cell.component";
import {DatePipe} from "@angular/common";
import {DateRangeCellComponent} from "./date-range-cell.component";
describe('DateRangeCellComponent', () => {
let fixture, daterangecell;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [DateRangeCellComponent],
providers: [DatePipe]
});
fixture = TestBed.createComponent(DateRangeCellComponent);
daterangecell = fixture.componentInstance;
});
it('should set from date value', async(() => {
let event = {
value: '2020-11-23'
};
daterangecell.startDateChange(event);
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(daterangecell.from).toBe('2020-11-23');
});
}));
it('should set to date value', async(() => {
let event = {
value: '2020-11-23'
};
daterangecell.endDateChange(event);
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(daterangecell.to).toBe('2020-11-23');
});
}));
it('should transform 23-Nov-2020 to 2020-11.23', async(() => {
expect(daterangecell.transformDate('23-Nov-2020')).toBe('2020-11-23');
}));
it('should return 2020-11-23 as 23.11.2020 ', async(() => {
expect(daterangecell.toLocaleDate('2020-11-23')).toBe('23.11.2020');
}));
});

@ -0,0 +1,139 @@
import {async, TestBed} from '@angular/core/testing';
import {DatePipe} from '@angular/common';
import {NumberRangeCellComponent} from './number-range-cell.component';
import {FormControl, FormGroup} from '@angular/forms';
describe('NumberRangeCellComponent', () => {
let fixture, cell;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [NumberRangeCellComponent],
providers: [DatePipe]
});
fixture = TestBed.createComponent(NumberRangeCellComponent);
cell = fixture.componentInstance;
});
it('should set minimum value as 0', async(() => {
cell.min = 0;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell._min).toBe(0);
});
}));
it('should return minimum value 0', async(() => {
cell._min = 0;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell.min).toBe(0);
});
}));
it('should set max value as 100', async(() => {
cell.max = 100;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell._max).toBe(100);
});
}));
it('should return max value 100', async(() => {
cell._max = 100;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell.max).toBe(100);
});
}));
it('should set editable true', async(() => {
cell.editable = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell._editable).toBe(true);
});
}));
it('should change min value, from event with value -5, to 5', async(() => {
const targ = {
value: -5
};
const event = {
target: targ
};
let rangeForm = new FormGroup({
minValue: new FormControl(),
maxValue: new FormControl(),
});
cell.rangeForm = rangeForm;
cell.minValueChange(event);
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell.min).toBe(5);
});
}));
it('should change max value, from event with value -100, to 100', async(() => {
const targ = {
value: -100
};
const event = {
target: targ
};
let rangeForm = new FormGroup({
minValue: new FormControl(),
maxValue: new FormControl(),
});
cell.rangeForm = rangeForm;
cell.maxValueChange(event);
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(cell.max).toBe(100);
});
}));
it('should set rangeError at check for invalid range of min 50 and max 10', async(() => {
let rangeForm = new FormGroup({
minValue: new FormControl(),
maxValue: new FormControl(),
});
cell.rangeForm = rangeForm;
cell.min = 50;
cell.max = 10;
cell.checkIfRangeIsValid();
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(rangeForm.controls['minValue'].errors.rangeError).toBe(true);
expect(rangeForm.controls['maxValue'].errors.rangeError).toBe(true);
});
}));
it('should set rangeError for parameter true', async(() => {
let rangeForm = new FormGroup({
minValue: new FormControl(),
maxValue: new FormControl(),
});
cell.rangeForm = rangeForm;
cell.setRangeError(true);
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(rangeForm.controls['minValue'].errors.rangeError).toBe(true);
expect(rangeForm.controls['maxValue'].errors.rangeError).toBe(true);
});
}));
it('should return 5 from string -5', async(() => {
expect(cell.toPositiveNumber('-5')).toBe(5);
}));
it('should return null from string "" ', async(() => {
expect(cell.toPositiveNumber('')).toBe(null);
}));
});
Loading…
Cancel
Save