Files
prowler/ui/lib/region-flags.test.ts
T
Alan Buscaglia 1bf13bf567 fix(ui): code quality improvements for findings grouped view
- Replace `any` with `unknown` + type guards in finding-groups and
  findings-by-resource adapters (4 adapter functions hardened)
- Add unmount cleanup for AbortController in use-resource-detail-drawer
  to prevent memory leaks on mid-flight unmount
- Add try/catch/finally error handling for onBeforeOpen in floating mute
  button to prevent permanent spinner state on network errors
- Replace hardcoded colors (border-gray-300, bg-white, text-slate-950)
  with semantic tokens (border-default-200, bg-background, text-foreground)
  for dark mode compatibility
- Change non-accessible `<p onClick>` to `<button>` with w-full and
  type=button in column-finding-groups for keyboard accessibility
- Fix region flag mapping: asia-east1 (Taiwan) now correctly shows flag_tw
  instead of flag_hk by adding specific rule before Hong Kong regex
- Fix import type usage in adapter files (value imports preserved for
  runtime constants like FINDINGS_ROW_TYPE)
- Restore pageRef.current = 1 in refresh() for error path safety

43 new tests across 7 test files. 50 total tests passing.
TypeScript: 0 errors. ESLint: 0 errors.
Judgment Day: 2 rounds, 0 discrepancies remaining.
2026-03-30 15:45:01 +02:00

72 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { getRegionFlag } from "./region-flags";
// ---------------------------------------------------------------------------
// Fix 6: Taiwan (asia-east1) mapped correctly vs Hong Kong (asia-east2)
// ---------------------------------------------------------------------------
describe("getRegionFlag — Taiwan vs Hong Kong disambiguation", () => {
it("should return 🇹🇼 for GCP asia-east1 (Taiwan)", () => {
// Given/When
const result = getRegionFlag("asia-east1");
// Then
expect(result).toBe("🇹🇼");
});
it("should return 🇭🇰 for GCP asia-east2 (Hong Kong)", () => {
// Given/When
const result = getRegionFlag("asia-east2");
// Then
expect(result).toBe("🇭🇰");
});
it("should return 🇭🇰 for regions containing 'hongkong'", () => {
// Given/When
const result = getRegionFlag("hongkong");
// Then
expect(result).toBe("🇭🇰");
});
it("should NOT return 🇭🇰 for asia-east1", () => {
// Given/When
const result = getRegionFlag("asia-east1");
// Then — confirm it's not Hong Kong flag
expect(result).not.toBe("🇭🇰");
});
});
describe("getRegionFlag — existing regions not broken", () => {
it("should return 🇺🇸 for us-east-1 (AWS)", () => {
expect(getRegionFlag("us-east-1")).toBe("🇺🇸");
});
it("should return 🇪🇺 for eu-west-1 (AWS)", () => {
expect(getRegionFlag("eu-west-1")).toBe("🇪🇺");
});
it("should return 🇯🇵 for ap-northeast-1 (Japan)", () => {
expect(getRegionFlag("ap-northeast-1")).toBe("🇯🇵");
});
it("should return 🇦🇺 for ap-southeast-2 (Australia)", () => {
expect(getRegionFlag("ap-southeast-2")).toBe("🇦🇺");
});
it("should return 🇸🇬 for ap-southeast-1 (Singapore)", () => {
expect(getRegionFlag("ap-southeast-1")).toBe("🇸🇬");
});
it("should return empty string for '-' (unknown/no region)", () => {
expect(getRegionFlag("-")).toBe("");
});
it("should return empty string for empty string", () => {
expect(getRegionFlag("")).toBe("");
});
});