Add isAdvancedFilter and isValidFilter functions with tests.

This commit is contained in:
Matt Mazzola 2016-07-13 12:57:25 -07:00
Родитель 33d60f7052
Коммит 952fb17418
2 изменённых файлов: 41 добавлений и 0 удалений

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

@ -159,6 +159,14 @@ export interface IAdvancedFilter extends IFilter {
conditions: IAdvancedFilterCondition[];
}
export function isAdvancedFilter(filter: IFilter): Boolean {
return (filter.$schema === AdvancedFilter.schemaUrl);
}
export function isValueFilter(filter: IFilter): Boolean {
return (filter.$schema === ValueFilter.schemaUrl);
}
export function isMeasure(arg: any): arg is IFilterMeasureTarget {
return arg.table !== undefined && arg.measure !== undefined;
}

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

@ -446,4 +446,37 @@ describe("Unit | Filters", function () {
expect(errors).toBeUndefined();
});
});
describe('determine filter type', function () {
it('isValueFilter should return true for objects with matching shemaUrl and false otherwise', function () {
// Arrange
const testData = {
filter: new models.ValueFilter({ table: "a", column: "b" }, "In", ["x", "y"]),
nonFilter: <models.IFilter>{}
};
// Act
// Assert
expect(models.isValueFilter(testData.filter.toJSON())).toBe(true);
expect(models.isValueFilter(testData.nonFilter)).toBe(false);
});
it('isAdvancedFilter should return true for objects with matching shemaUrl and false otherwise', function () {
// Arrange
const testData = {
filter: new models.AdvancedFilter({ table: "a", column: "b" }, "And",
{ operator: "Contains", value: "x" },
{ operator: "Contains", value: "x" }
),
nonFilter: <models.IFilter>{}
};
// Act
// Assert
expect(models.isAdvancedFilter(testData.filter.toJSON())).toBe(true);
expect(models.isAdvancedFilter(testData.nonFilter)).toBe(false);
});
});
});