mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-11-02 22:01:09 +08:00
refactor(config): cleanup handling for fontSize, tapeMargin and maxLineWidth (@fehmer) (#6775)
merge this after #6751 and the command builder pr - remove configOverride - add handling to config migration
This commit is contained in:
parent
be1774e219
commit
3ddb3c68c1
4 changed files with 47 additions and 35 deletions
|
|
@ -1042,9 +1042,6 @@ describe("Config", () => {
|
|||
it("setFontSize", () => {
|
||||
expect(Config.setFontSize(1)).toBe(true);
|
||||
|
||||
//gets converted
|
||||
expect(Config.setFontSize(-1)).toBe(true);
|
||||
|
||||
expect(Config.setFontSize(0)).toBe(false);
|
||||
expect(Config.setFontSize("5" as any)).toBe(false);
|
||||
expect(Config.setFontSize("invalid" as any)).toBe(false);
|
||||
|
|
@ -1053,11 +1050,6 @@ describe("Config", () => {
|
|||
expect(Config.setMaxLineWidth(0)).toBe(true);
|
||||
expect(Config.setMaxLineWidth(50)).toBe(true);
|
||||
expect(Config.setMaxLineWidth(50.5)).toBe(true);
|
||||
|
||||
//gets converted
|
||||
expect(Config.setMaxLineWidth(10)).toBe(true);
|
||||
expect(Config.setMaxLineWidth(10_000)).toBe(true);
|
||||
expect(Config.setMaxLineWidth("invalid" as any)).toBe(false);
|
||||
});
|
||||
it("setCustomBackground", () => {
|
||||
expect(Config.setCustomBackground("http://example.com/test.png")).toBe(
|
||||
|
|
|
|||
|
|
@ -209,6 +209,35 @@ describe("config.ts", () => {
|
|||
given: { fontSize: 15 },
|
||||
expected: { fontSize: 15 },
|
||||
},
|
||||
{
|
||||
given: { fontSize: -0.5 },
|
||||
expected: { fontSize: 1 },
|
||||
},
|
||||
{
|
||||
given: { tapeMargin: 9.5 },
|
||||
expected: { tapeMargin: 10 },
|
||||
},
|
||||
{
|
||||
given: { tapeMargin: 25 },
|
||||
expected: { tapeMargin: 25 },
|
||||
},
|
||||
{
|
||||
given: { tapeMargin: 90.5 },
|
||||
expected: { tapeMargin: 90 },
|
||||
},
|
||||
{
|
||||
given: { maxLineWidth: 0 },
|
||||
expected: { maxLineWidth: 0 },
|
||||
},
|
||||
|
||||
{
|
||||
given: { maxLineWidth: 19 },
|
||||
expected: { maxLineWidth: 20 },
|
||||
},
|
||||
{
|
||||
given: { maxLineWidth: 1001 },
|
||||
expected: { maxLineWidth: 1000 },
|
||||
},
|
||||
])(`$given`, ({ given, expected }) => {
|
||||
const description = `given: ${JSON.stringify(
|
||||
given
|
||||
|
|
|
|||
|
|
@ -500,16 +500,6 @@ export const configMetadata: ConfigMetadataObject = {
|
|||
icon: "fa-tape",
|
||||
displayString: "tape margin",
|
||||
changeRequiresRestart: false,
|
||||
overrideValue: ({ value }) => {
|
||||
//TODO move to migration after settings validation
|
||||
if (value < 10) {
|
||||
value = 10;
|
||||
}
|
||||
if (value > 90) {
|
||||
value = 90;
|
||||
}
|
||||
return value;
|
||||
},
|
||||
},
|
||||
smoothLineScroll: {
|
||||
icon: "fa-align-left",
|
||||
|
|
@ -548,29 +538,12 @@ export const configMetadata: ConfigMetadataObject = {
|
|||
changeRequiresRestart: false,
|
||||
triggerResize: true,
|
||||
displayString: "max line width",
|
||||
overrideValue: ({ value }) => {
|
||||
//TODO move to migration after settings validation
|
||||
if (value < 20 && value !== 0) {
|
||||
value = 20;
|
||||
}
|
||||
if (value > 1000) {
|
||||
value = 1000;
|
||||
}
|
||||
return value;
|
||||
},
|
||||
},
|
||||
fontSize: {
|
||||
icon: "fa-font",
|
||||
changeRequiresRestart: false,
|
||||
triggerResize: true,
|
||||
displayString: "font size",
|
||||
overrideValue: ({ value }) => {
|
||||
//TODO move to migration after settings validation
|
||||
if (value < 0) {
|
||||
value = 1;
|
||||
}
|
||||
return value;
|
||||
},
|
||||
},
|
||||
fontFamily: {
|
||||
icon: "fa-font",
|
||||
|
|
|
|||
|
|
@ -154,6 +154,8 @@ export function replaceLegacyValues(
|
|||
}
|
||||
|
||||
configObj.fontSize = newValue;
|
||||
} else if (configObj.fontSize !== undefined && configObj.fontSize < 0) {
|
||||
configObj.fontSize = 1;
|
||||
}
|
||||
|
||||
if (
|
||||
|
|
@ -198,5 +200,21 @@ export function replaceLegacyValues(
|
|||
}
|
||||
}
|
||||
|
||||
if (configObj.tapeMargin !== undefined) {
|
||||
if (configObj.tapeMargin < 10) {
|
||||
configObj.tapeMargin = 10;
|
||||
} else if (configObj.tapeMargin > 90) {
|
||||
configObj.tapeMargin = 90;
|
||||
}
|
||||
}
|
||||
|
||||
if (configObj.maxLineWidth !== undefined) {
|
||||
if (configObj.maxLineWidth < 20 && configObj.maxLineWidth !== 0) {
|
||||
configObj.maxLineWidth = 20;
|
||||
} else if (configObj.maxLineWidth > 1000) {
|
||||
configObj.maxLineWidth = 1000;
|
||||
}
|
||||
}
|
||||
|
||||
return configObj;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue