Added UT for getColumnIndex method

This commit is contained in:
Violet Voronetzky 2019-12-02 10:45:14 +02:00
Родитель 17347d04eb
Коммит f4d22319a2
1 изменённых файлов: 88 добавлений и 3 удалений

Просмотреть файл

@ -1,11 +1,98 @@
'use strict';
import { Utilities } from '../src/common/utilities';
import { DraftColumnType } from '../src/common/chartModels';
describe('Unit tests for Utilities', () => {
//#region Tests
describe('Validate getValidDate method', () => {
describe('Validate getValidDate method', () => {
//#region getColumnIndex
const columns = [
{ name: 'country', type: DraftColumnType.String },
{ name: 'country', type: DraftColumnType.Long },
{ name: 'percentage', type: DraftColumnType.Decimal },
{ name: 'request_count', type: DraftColumnType.Int },
];
it("Validate getColumnIndex: column doesn't exist - incompatible types", () => {
const queryResultData = {
rows: [],
columns: columns
}
const columnToFind = { name: 'country', type: DraftColumnType.Guid };
// Act
const result = Utilities.getColumnIndex(queryResultData, columnToFind);
// Assert
expect(result).toEqual(-1);
});
it("Validate getColumnIndex: column doesn't exist - incompatible names", () => {
const queryResultData = {
rows: [],
columns: columns
}
const columnToFind = { name: 'country_', type: DraftColumnType.String };
// Act
const result = Utilities.getColumnIndex(queryResultData, columnToFind);
// Assert
expect(result).toEqual(-1);
});
it("Validate getColumnIndex: column doesn't exist - incompatible type and name", () => {
const queryResultData = {
rows: [],
columns: columns
}
const columnToFind = { name: 'country_', type: DraftColumnType.Guid };
// Act
const result = Utilities.getColumnIndex(queryResultData, columnToFind);
// Assert
expect(result).toEqual(-1);
});
it("Validate getColumnIndex: column exists when there are two columns with the same name", () => {
const queryResultData = {
rows: [],
columns: columns
}
const columnToFind = { name: 'country', type: DraftColumnType.Long };
// Act
const result = Utilities.getColumnIndex(queryResultData, columnToFind);
// Assert
expect(result).toEqual(1);
});
it("Validate getColumnIndex: column exists", () => {
const queryResultData = {
rows: [],
columns: columns
}
const columnToFind = { name: 'request_count', type: DraftColumnType.Int };
// Act
const result = Utilities.getColumnIndex(queryResultData, columnToFind);
// Assert
expect(result).toEqual(3);
});
//#endregion getColumnIndex
//#region getValidDate
function validateDateResult(actual: Date, expected: Date) {
@ -76,8 +163,6 @@ describe('Unit tests for Utilities', () => {
// Assert
validateDateResult(result, expectedResult);
});
//#endregion getValidDate
});
//#endregion Tests