mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-19 15:54:09 +02:00
CODEBASE: Validate theme, editor theme, and styles (#1789)
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { assertAndSanitizeMainTheme } from "../../../src/JsonSchema/JSONSchemaAssertion";
|
||||
import { JsonSchemaValidator } from "../../../src/JsonSchema/JsonSchemaValidator";
|
||||
import { defaultTheme } from "../../../src/Themes/Themes";
|
||||
|
||||
const validHexColor = "#FFF";
|
||||
const invalidHexColor = "#FFFF";
|
||||
|
||||
function getCloneOfDefaultMainTheme() {
|
||||
return structuredClone(defaultTheme) as unknown as Record<string, unknown>;
|
||||
}
|
||||
|
||||
describe("Valid", () => {
|
||||
test("Default main theme", () => {
|
||||
expect(JsonSchemaValidator.MainTheme(getCloneOfDefaultMainTheme())).toStrictEqual(true);
|
||||
});
|
||||
test("Partial theme", () => {
|
||||
const theme = {
|
||||
primary: validHexColor,
|
||||
};
|
||||
expect(JsonSchemaValidator.MainTheme(theme)).toStrictEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Invalid", () => {
|
||||
for (const key of Object.keys(defaultTheme)) {
|
||||
test(`Invalid ${key}`, () => {
|
||||
const theme = getCloneOfDefaultMainTheme();
|
||||
theme[key] = invalidHexColor;
|
||||
expect(JsonSchemaValidator.MainTheme(theme)).toStrictEqual(false);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("assertAndSanitizeMainTheme", () => {
|
||||
test("Unknown properties are removed", () => {
|
||||
const theme = {
|
||||
primary: validHexColor,
|
||||
unknownColor1: validHexColor,
|
||||
};
|
||||
assertAndSanitizeMainTheme(theme);
|
||||
expect(theme.unknownColor1).toStrictEqual(undefined);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user