Add tests for fontWeight normalization

This commit is contained in:
IllusionMH
2020-09-05 00:48:12 +03:00
parent b918f0d34a
commit 3e0f0331b3
+39 -1
View File
@@ -3,7 +3,7 @@
* @license MIT
*/
import { assert } from 'chai';
import { assert, expect } from 'chai';
import { OptionsService, DEFAULT_OPTIONS } from 'common/services/OptionsService';
describe('OptionsService', () => {
@@ -19,4 +19,42 @@ describe('OptionsService', () => {
assert.equal(new OptionsService({tabStopWidth: 0}).getOption('tabStopWidth'), DEFAULT_OPTIONS.tabStopWidth);
});
});
describe('setOption', () => {
let service: OptionsService;
beforeEach(() => {
service = new OptionsService({});
});
it('applies valid fontWeight option values', () => {
service.setOption('fontWeight', 'bold');
assert.equal(service.getOption('fontWeight'), 'bold', '"bold" keyword value should be applied');
service.setOption('fontWeight', 'normal');
assert.equal(service.getOption('fontWeight'), 'normal', '"normal" keyword value should be applied');
service.setOption('fontWeight', '600');
assert.equal(service.getOption('fontWeight'), '600', 'String numeric values should be applied');
service.setOption('fontWeight', 350);
assert.equal(service.getOption('fontWeight'), 350, 'Values between 1 and 1000 should be applied as is');
service.setOption('fontWeight', 1);
assert.equal(service.getOption('fontWeight'), 1, 'Range should include minimum value: 1');
service.setOption('fontWeight', 1000);
assert.equal(service.getOption('fontWeight'), 1000, 'Range should include maximum value: 1000');
});
it('normalizes invalid fontWeight option values', () => {
service.setOption('fontWeight', 350);
expect(() => service.setOption('fontWeight', 10000)).to.not.throw('', 'fontWeight should be normalized instead of throwing');
assert.equal(service.getOption('fontWeight'), DEFAULT_OPTIONS.fontWeight, 'Values greater than 1000 should be reset to default');
service.setOption('fontWeight', 350);
service.setOption('fontWeight', -10);
assert.equal(service.getOption('fontWeight'), DEFAULT_OPTIONS.fontWeight, 'Values less than 1 should be reset to default');
service.setOption('fontWeight', 350);
service.setOption('fontWeight', 'bold700');
assert.equal(service.getOption('fontWeight'), DEFAULT_OPTIONS.fontWeight, 'Wrong string literals should be reset to default');
});
});
});