Task Summary
Add computing-unit.util.spec.ts covering the pure resource-parsing / conversion / validation helpers exported from computing-unit.util.ts. These are plain functions — no Angular TestBed needed.
Background
frontend/src/app/common/util/computing-unit.util.ts exports ~15 pure helpers that parse Kubernetes CPU & memory resource strings (e.g. "500Mi", "1000m"), compute usage percentages, validate a unit name, and derive UI status/colors. None of them are directly unit-tested today.
export function parseResourceUnit(resource: string): string { ... } // "500Mi" -> "Mi"
export function parseResourceNumber(resource: string): number { ... } // "2Gi" -> 2
export function cpuResourceConversion(from: string, toUnit: string): string { ... }
export function memoryPercentage(usage: string, limit: string): number { ... }
export function validateName(trimmedName: string): string | null { ... }
Behavior to pin
| Function |
Contract |
parseResourceUnit |
"500Mi" → "Mi"; "2" → ""; "" and "NaN" → "NaN"; garbage → "" |
parseResourceNumber |
"2Gi" → 2; "1.5Gi" → 1.5; "" / "NaN" → 0 |
cpuResourceConversion |
"1000m" → "1.0000" cores (empty target unit); respects the n/u/m/"" scale ladder and per-unit precision |
cpuPercentage / memoryPercentage |
return 0 when either arg is "N/A" or the limit is ≤ 0; otherwise clamp the result at 100 |
findNearestValidStep |
returns 1 on an empty step list; returns the value when present; otherwise the closest step |
validateName |
"" → empty-name error; a 129-char name → too-long error; a valid name → null |
getComputingUnitBadgeColor |
"Running" → "green", "Pending" → "gold", else "red" |
isComputingUnitShmTooLarge |
true only when the requested shared-memory (normalized to Mi) exceeds the selected memory |
Follow size-formatter.util.spec.ts in the same folder as the style template (plain describe/it/expect, run with ng test).
Scope
- New spec:
frontend/src/app/common/util/computing-unit.util.spec.ts.
- No production-code changes.
Task Type
Task Summary
Add
computing-unit.util.spec.tscovering the pure resource-parsing / conversion / validation helpers exported fromcomputing-unit.util.ts. These are plain functions — no AngularTestBedneeded.Background
frontend/src/app/common/util/computing-unit.util.tsexports ~15 pure helpers that parse Kubernetes CPU & memory resource strings (e.g."500Mi","1000m"), compute usage percentages, validate a unit name, and derive UI status/colors. None of them are directly unit-tested today.Behavior to pin
parseResourceUnit"500Mi"→"Mi";"2"→"";""and"NaN"→"NaN"; garbage →""parseResourceNumber"2Gi"→2;"1.5Gi"→1.5;""/"NaN"→0cpuResourceConversion"1000m"→"1.0000"cores (empty target unit); respects then/u/m/""scale ladder and per-unit precisioncpuPercentage/memoryPercentage0when either arg is"N/A"or the limit is ≤ 0; otherwise clamp the result at100findNearestValidStep1on an empty step list; returns the value when present; otherwise the closest stepvalidateName""→ empty-name error; a 129-char name → too-long error; a valid name →nullgetComputingUnitBadgeColor"Running"→"green","Pending"→"gold", else"red"isComputingUnitShmTooLargetrueonly when the requested shared-memory (normalized to Mi) exceeds the selected memoryFollow
size-formatter.util.spec.tsin the same folder as the style template (plaindescribe/it/expect, run withng test).Scope
frontend/src/app/common/util/computing-unit.util.spec.ts.Task Type