import { ISettings } from '../RangeSlider/types';
import { Model } from './Model';
let settings: ISettings;
function getPrivateMethod(methodName: string, settings: ISettings) {
const modelProto = Model.prototype as any;
const instance = Object.create(modelProto);
return () => modelProto[methodName].call(instance, settings);
}
describe('validateSettings function check: ', () => {
beforeEach(() => {
settings = {
min: 0,
max: 1500,
valueFrom: 1000,
valueTo: 1490,
isScaleVisible: true,
isTwoRunners: true,
isVertical: false,
isTooltipsVisible: true,
step: 10,
};
});
test('"settings.min >= settings.max" should throw Error', () => {
// тест не должен проходить при таких значениях, должен только при min > max
settings.min = 1000;
settings.max = 1500;
const minIsBiggerThanMax = getPrivateMethod('validateSettings', settings);
expect(minIsBiggerThanMax).toThrow();
});
});
private static validateSettings(settings: ISettings): void {
if (settings.min >= settings.max) {
throw new Error("'max' must be greater than 'min'");
}
// if (settings.valueFrom < settings.min) {
// throw new Error("'valueFrom' must be greater than 'min'");
// }
// if (settings.valueFrom > settings.valueTo) {
// throw new Error("'valueFrom' must be less than 'valueTo'");
// }
// if (settings.valueTo > settings.max) {
// throw new Error("'valueTo' must be less than 'max'");
// }
// if (settings.max - settings.min < settings.step) {
// throw new Error(`'step' must be less than ${settings.max - settings.min}`);
// }
}
constructor(settings: ISettings) {
Model.validateSettings(settings);
this.settings = settings;
// default options
this.minValue = this.settings.min;
this.maxValue = this.settings.max;
this.isTwoRunners = this.settings.isTwoRunners;
this.isScaleVisible = this.settings.isScaleVisible;
this.isVertical = this.settings.isVertical;
this.isTooltipsVisible = this.settings.isTooltipsVisible;
this.valueFrom = this.getThumbValue(this.settings, 'from');
this.valueTo = this.getThumbValue(this.settings, 'to');
this.step = this.getStepInPercents(this.settings.step);
this.rangePercent = (this.settings.max - this.settings.min) / 100;
this.getStepInPercents = this.getStepInPercents.bind(this);
}
import { ISettings } from '../RangeSlider/types';
import { Model } from './Model';
let settings: ISettings;
function getPrivateMethod(methodName: string, settings: ISettings) {
const modelProto = Model.prototype as any;
const instance = Object.create(modelProto);
return () => modelProto[methodName].call(instance, settings);
}
describe('validateSettings function check: ', () => {
beforeEach(() => {
settings = {
min: 0,
max: 1500,
valueFrom: 1000,
valueTo: 1490,
isScaleVisible: true,
isTwoRunners: true,
isVertical: false,
isTooltipsVisible: true,
step: 10,
};
});
test('"settings.min >= settings.max" should throw Error', () => {
// тест не должен проходить при таких значениях, должен только при min > max
settings.min = 1000;
settings.max = 1500;
const minIsBiggerThanMax = getPrivateMethod('validateSettings', settings);
expect(minIsBiggerThanMax).toThrow();
});
});
private static validateSettings(settings: ISettings): void {
if (settings.min >= settings.max) {
throw new Error("'max' must be greater than 'min'");
}
// if (settings.valueFrom < settings.min) {
// throw new Error("'valueFrom' must be greater than 'min'");
// }
// if (settings.valueFrom > settings.valueTo) {
// throw new Error("'valueFrom' must be less than 'valueTo'");
// }
// if (settings.valueTo > settings.max) {
// throw new Error("'valueTo' must be less than 'max'");
// }
// if (settings.max - settings.min < settings.step) {
// throw new Error(`'step' must be less than ${settings.max - settings.min}`);
// }
}
constructor(settings: ISettings) {
Model.validateSettings(settings);
this.settings = settings;
// default options
this.minValue = this.settings.min;
this.maxValue = this.settings.max;
this.isTwoRunners = this.settings.isTwoRunners;
this.isScaleVisible = this.settings.isScaleVisible;
this.isVertical = this.settings.isVertical;
this.isTooltipsVisible = this.settings.isTooltipsVisible;
this.valueFrom = this.getThumbValue(this.settings, 'from');
this.valueTo = this.getThumbValue(this.settings, 'to');
this.step = this.getStepInPercents(this.settings.step);
this.rangePercent = (this.settings.max - this.settings.min) / 100;
this.getStepInPercents = this.getStepInPercents.bind(this);
}
import { ISettings } from '../RangeSlider/types';
import { Model } from './Model';
let settings: ISettings;
function getPrivateMethod(methodName: string, settings: ISettings) {
const modelProto = Model.prototype as any;
const instance = Object.create(modelProto);
return () => modelProto[methodName].call(instance, settings);
}
describe('validateSettings function check: ', () => {
beforeEach(() => {
settings = {
min: 0,
max: 1500,
valueFrom: 1000,
valueTo: 1490,
isScaleVisible: true,
isTwoRunners: true,
isVertical: false,
isTooltipsVisible: true,
step: 10,
};
});
test('"settings.min >= settings.max" should throw Error', () => {
// тест не должен проходить при таких значениях, должен только при min > max
settings.min = 1000;
settings.max = 1500;
const minIsBiggerThanMax = getPrivateMethod('validateSettings', settings);
expect(minIsBiggerThanMax).toThrow();
});
});
private static validateSettings(settings: ISettings): void {
if (settings.min >= settings.max) {
throw new Error("'max' must be greater than 'min'");
}
// if (settings.valueFrom < settings.min) {
// throw new Error("'valueFrom' must be greater than 'min'");
// }
// if (settings.valueFrom > settings.valueTo) {
// throw new Error("'valueFrom' must be less than 'valueTo'");
// }
// if (settings.valueTo > settings.max) {
// throw new Error("'valueTo' must be less than 'max'");
// }
// if (settings.max - settings.min < settings.step) {
// throw new Error(`'step' must be less than ${settings.max - settings.min}`);
// }
}
import { ISettings } from '../RangeSlider/types';
import { Model } from './Model';
let settings: ISettings;
let model: Model;
function getPrivateMethod(methodName: string, settings: ISettings) {
model = new Model(settings);
const modelProto = Object.getPrototypeOf(model);
const result = modelProto[methodName](settings);
return result;
}
describe('validateSettings function check: ', () => {
beforeEach(() => {
settings = {
min: 0,
max: 1500,
valueFrom: 1000,
valueTo: 1490,
isScaleVisible: true,
isTwoRunners: true,
isVertical: false,
isTooltipsVisible: true,
step: 10,
};
});
test('"settings.min >= settings.max" should throw Error', () => {
// тест должен проходить при значениях min > max
// но он проходит и при min < max. Почему?
settings.min = 5000;
settings.max = 1500;
const minIsBiggerThanMax = getPrivateMethod('validateSettings', settings);
expect(() => {
minIsBiggerThanMax();
}).toThrow();
});
});
private validateSettings(settings: ISettings): void {
try {
if (settings.min >= settings.max) {
throw new Error("'max' must be greater than 'min'");
}
// if (settings.valueFrom < settings.min) {
// throw new Error("'valueFrom' must be greater than 'min'");
// }
// if (settings.valueFrom > settings.valueTo) {
// throw new Error("'valueFrom' must be less than 'valueTo'");
// }
// if (settings.valueTo > settings.max) {
// throw new Error("'valueTo' must be less than 'max'");
// }
// if (settings.max - settings.min < settings.step) {
// throw new Error(`'step' must be less than ${settings.max - settings.min}`);
// }
} catch (error) {
console.log(error.message, error.name);
}
}
import { ISettings } from '../RangeSlider/types';
import { Model } from './Model';
let settings: ISettings;
let model: Model;
function getPrivateMethod(methodName: string, settings: ISettings) {
model = new Model(settings);
const modelProto = Object.getPrototypeOf(model);
const result = modelProto[methodName](settings);
return result;
}
describe('validateSettings function check: ', () => {
beforeEach(() => {
settings = {
min: 0,
max: 1500,
valueFrom: 1000,
valueTo: 1490,
isScaleVisible: true,
isTwoRunners: true,
isVertical: false,
isTooltipsVisible: true,
step: 10,
};
});
test('"settings.min >= settings.max" should throw Error', () => {
// тест должен проходить при значениях min > max
// но он проходит и при min < max. Почему?
settings.min = 5000;
settings.max = 1500;
const minIsBiggerThanMax = getPrivateMethod('validateSettings', settings);
expect(() => {
minIsBiggerThanMax();
}).toThrow();
});
});
private validateSettings(settings: ISettings): void {
try {
if (settings.min >= settings.max) {
throw new Error("'max' must be greater than 'min'");
}
// if (settings.valueFrom < settings.min) {
// throw new Error("'valueFrom' must be greater than 'min'");
// }
// if (settings.valueFrom > settings.valueTo) {
// throw new Error("'valueFrom' must be less than 'valueTo'");
// }
// if (settings.valueTo > settings.max) {
// throw new Error("'valueTo' must be less than 'max'");
// }
// if (settings.max - settings.min < settings.step) {
// throw new Error(`'step' must be less than ${settings.max - settings.min}`);
// }
} catch (error) {
console.log(error.message, error.name);
}
}