Skip to content

Commit 3e0f033

Browse files
committed
Add tests for fontWeight normalization
1 parent b918f0d commit 3e0f033

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/common/services/OptionsService.test.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @license MIT
44
*/
55

6-
import { assert } from 'chai';
6+
import { assert, expect } from 'chai';
77
import { OptionsService, DEFAULT_OPTIONS } from 'common/services/OptionsService';
88

99
describe('OptionsService', () => {
@@ -19,4 +19,42 @@ describe('OptionsService', () => {
1919
assert.equal(new OptionsService({tabStopWidth: 0}).getOption('tabStopWidth'), DEFAULT_OPTIONS.tabStopWidth);
2020
});
2121
});
22+
describe('setOption', () => {
23+
let service: OptionsService;
24+
beforeEach(() => {
25+
service = new OptionsService({});
26+
});
27+
it('applies valid fontWeight option values', () => {
28+
service.setOption('fontWeight', 'bold');
29+
assert.equal(service.getOption('fontWeight'), 'bold', '"bold" keyword value should be applied');
30+
31+
service.setOption('fontWeight', 'normal');
32+
assert.equal(service.getOption('fontWeight'), 'normal', '"normal" keyword value should be applied');
33+
34+
service.setOption('fontWeight', '600');
35+
assert.equal(service.getOption('fontWeight'), '600', 'String numeric values should be applied');
36+
37+
service.setOption('fontWeight', 350);
38+
assert.equal(service.getOption('fontWeight'), 350, 'Values between 1 and 1000 should be applied as is');
39+
40+
service.setOption('fontWeight', 1);
41+
assert.equal(service.getOption('fontWeight'), 1, 'Range should include minimum value: 1');
42+
43+
service.setOption('fontWeight', 1000);
44+
assert.equal(service.getOption('fontWeight'), 1000, 'Range should include maximum value: 1000');
45+
});
46+
it('normalizes invalid fontWeight option values', () => {
47+
service.setOption('fontWeight', 350);
48+
expect(() => service.setOption('fontWeight', 10000)).to.not.throw('', 'fontWeight should be normalized instead of throwing');
49+
assert.equal(service.getOption('fontWeight'), DEFAULT_OPTIONS.fontWeight, 'Values greater than 1000 should be reset to default');
50+
51+
service.setOption('fontWeight', 350);
52+
service.setOption('fontWeight', -10);
53+
assert.equal(service.getOption('fontWeight'), DEFAULT_OPTIONS.fontWeight, 'Values less than 1 should be reset to default');
54+
55+
service.setOption('fontWeight', 350);
56+
service.setOption('fontWeight', 'bold700');
57+
assert.equal(service.getOption('fontWeight'), DEFAULT_OPTIONS.fontWeight, 'Wrong string literals should be reset to default');
58+
});
59+
});
2260
});

0 commit comments

Comments
 (0)