Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions src/constants/appConstants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
SECURITY_RECOMMENDATIONS,
WIDGET_ICONS,
WIDGET_TITLES,
mapOptionsToConstants,
} from "./appConstants";
import { CIADetails } from "../types/cia-services";

describe("Application Constants", () => {
describe("SECURITY_LEVEL_COLORS", () => {
Expand Down Expand Up @@ -115,4 +117,143 @@
).toBeGreaterThan(0);
});
});

describe("mapOptionsToConstants", () => {
const mockOptions: Record<string, CIADetails> = {
None: {

Check failure on line 123 in src/constants/appConstants.test.ts

View workflow job for this annotation

GitHub Actions / build-validation

Type '{ description: string; impact: string; technical: string; capex: number; opex: number; bg: string; text: string; }' is missing the following properties from type 'CIADetails': businessImpact, recommendations

Check failure on line 123 in src/constants/appConstants.test.ts

View workflow job for this annotation

GitHub Actions / build-validation

Type '{ description: string; impact: string; technical: string; capex: number; opex: number; bg: string; text: string; }' is missing the following properties from type 'CIADetails': businessImpact, recommendations
description: "None description",
impact: "None impact",
technical: "None technical",
capex: 0,
opex: 0,
bg: "#fff",
text: "#000",
},
Low: {

Check failure on line 132 in src/constants/appConstants.test.ts

View workflow job for this annotation

GitHub Actions / build-validation

Type '{ description: string; impact: string; technical: string; capex: number; opex: number; bg: string; text: string; }' is missing the following properties from type 'CIADetails': businessImpact, recommendations

Check failure on line 132 in src/constants/appConstants.test.ts

View workflow job for this annotation

GitHub Actions / build-validation

Type '{ description: string; impact: string; technical: string; capex: number; opex: number; bg: string; text: string; }' is missing the following properties from type 'CIADetails': businessImpact, recommendations
description: "Low description",
impact: "Low impact",
technical: "Low technical",
capex: 5,
opex: 2,
bg: "#fef",
text: "#111",
},
Moderate: {

Check failure on line 141 in src/constants/appConstants.test.ts

View workflow job for this annotation

GitHub Actions / build-validation

Type '{ description: string; impact: string; technical: string; capex: number; opex: number; bg: string; text: string; }' is missing the following properties from type 'CIADetails': businessImpact, recommendations

Check failure on line 141 in src/constants/appConstants.test.ts

View workflow job for this annotation

GitHub Actions / build-validation

Type '{ description: string; impact: string; technical: string; capex: number; opex: number; bg: string; text: string; }' is missing the following properties from type 'CIADetails': businessImpact, recommendations
description: "Moderate description",
impact: "Moderate impact",
technical: "Moderate technical",
capex: 10,
opex: 5,
bg: "#eee",
text: "#222",
},
High: {

Check failure on line 150 in src/constants/appConstants.test.ts

View workflow job for this annotation

GitHub Actions / build-validation

Type '{ description: string; impact: string; technical: string; capex: number; opex: number; bg: string; text: string; }' is missing the following properties from type 'CIADetails': businessImpact, recommendations

Check failure on line 150 in src/constants/appConstants.test.ts

View workflow job for this annotation

GitHub Actions / build-validation

Type '{ description: string; impact: string; technical: string; capex: number; opex: number; bg: string; text: string; }' is missing the following properties from type 'CIADetails': businessImpact, recommendations
description: "High description",
impact: "High impact",
technical: "High technical",
capex: 15,
opex: 8,
bg: "#ddd",
text: "#333",
},
"Very High": {

Check failure on line 159 in src/constants/appConstants.test.ts

View workflow job for this annotation

GitHub Actions / build-validation

Type '{ description: string; impact: string; technical: string; capex: number; opex: number; bg: string; text: string; }' is missing the following properties from type 'CIADetails': businessImpact, recommendations

Check failure on line 159 in src/constants/appConstants.test.ts

View workflow job for this annotation

GitHub Actions / build-validation

Type '{ description: string; impact: string; technical: string; capex: number; opex: number; bg: string; text: string; }' is missing the following properties from type 'CIADetails': businessImpact, recommendations
description: "Very High description",
impact: "Very High impact",
technical: "Very High technical",
capex: 20,
opex: 10,
bg: "#ccc",
text: "#444",
},
};

it("returns undefined values when options is null", () => {
const result = mapOptionsToConstants(null as unknown as Record<string, CIADetails>, "description");

expect(Object.values(result).every(v => v === undefined)).toBe(true);
});

it("returns undefined values when options is undefined", () => {
const result = mapOptionsToConstants(undefined as unknown as Record<string, CIADetails>, "description");

expect(Object.values(result).every(v => v === undefined)).toBe(true);
});

it("maps description field correctly", () => {
const result = mapOptionsToConstants(mockOptions, "description");

expect(result.NONE).toBe("None description");
expect(result.LOW).toBe("Low description");
expect(result.MODERATE).toBe("Moderate description");
expect(result.HIGH).toBe("High description");
expect(result.VERY_HIGH).toBe("Very High description");
});

it("maps impact field correctly", () => {
const result = mapOptionsToConstants(mockOptions, "impact");

expect(result.NONE).toBe("None impact");
expect(result.LOW).toBe("Low impact");
expect(result.MODERATE).toBe("Moderate impact");
expect(result.HIGH).toBe("High impact");
expect(result.VERY_HIGH).toBe("Very High impact");
});

it("maps technical field correctly", () => {
const result = mapOptionsToConstants(mockOptions, "technical");

expect(result.NONE).toBe("None technical");
expect(result.LOW).toBe("Low technical");
expect(result.MODERATE).toBe("Moderate technical");
expect(result.HIGH).toBe("High technical");
expect(result.VERY_HIGH).toBe("Very High technical");
});

it("applies transform function when provided", () => {
const transform = (value: string, level: string) => `${level}: ${value}`;
const result = mapOptionsToConstants(mockOptions, "description", transform);

expect(result.NONE).toBe("None: None description");
expect(result.LOW).toBe("Low: Low description");
expect(result.MODERATE).toBe("Moderate: Moderate description");
expect(result.HIGH).toBe("High: High description");
expect(result.VERY_HIGH).toBe("Very High: Very High description");
});

it("applies transform function to numeric fields", () => {
const transform = (value: number) => value * 2;
const result = mapOptionsToConstants(mockOptions, "capex", transform);

Check failure on line 225 in src/constants/appConstants.test.ts

View workflow job for this annotation

GitHub Actions / build-validation

Argument of type '(value: number) => number' is not assignable to parameter of type '(value: number | undefined, level: string) => number'.

Check failure on line 225 in src/constants/appConstants.test.ts

View workflow job for this annotation

GitHub Actions / build-validation

Argument of type '(value: number) => number' is not assignable to parameter of type '(value: number | undefined, level: string) => number'.

expect(result.NONE).toBe(0);
expect(result.LOW).toBe(10);
expect(result.MODERATE).toBe(20);
expect(result.HIGH).toBe(30);
expect(result.VERY_HIGH).toBe(40);
});

it("handles missing options gracefully", () => {
const incompleteOptions: Record<string, CIADetails> = {
Low: mockOptions.Low,
High: mockOptions.High,
};

const result = mapOptionsToConstants(incompleteOptions, "description");

expect(result.NONE).toBeUndefined();
expect(result.LOW).toBe("Low description");
expect(result.MODERATE).toBeUndefined();
expect(result.HIGH).toBe("High description");
expect(result.VERY_HIGH).toBeUndefined();
});

it("returns values without transform when transform is not provided", () => {
const result = mapOptionsToConstants(mockOptions, "capex");

expect(result.NONE).toBe(0);
expect(result.LOW).toBe(5);
expect(result.MODERATE).toBe(10);
expect(result.HIGH).toBe(15);
expect(result.VERY_HIGH).toBe(20);
});
});
});
Loading
Loading