diff --git a/src/shared/constants/sidebarVisibility.ts b/src/shared/constants/sidebarVisibility.ts index 613d3805a8..42aed0cfdc 100644 --- a/src/shared/constants/sidebarVisibility.ts +++ b/src/shared/constants/sidebarVisibility.ts @@ -195,6 +195,13 @@ const OMNI_PROXY_ITEMS: readonly SidebarItemDefinition[] = [ subtitleKey: "providerQuotaSubtitle", icon: "tune", }, + { + id: "costs-quota-share", + href: "/dashboard/costs/quota-share", + i18nKey: "costsQuotaShare", + subtitleKey: "costsQuotaShareSubtitle", + icon: "pie_chart", + }, ]; const COMPRESSION_CONTEXT_GROUP: SidebarItemGroup = { @@ -454,13 +461,6 @@ const COSTS_ITEMS: readonly SidebarItemDefinition[] = [ subtitleKey: "costsBudgetSubtitle", icon: "savings", }, - { - id: "costs-quota-share", - href: "/dashboard/costs/quota-share", - i18nKey: "costsQuotaShare", - subtitleKey: "costsQuotaShareSubtitle", - icon: "pie_chart", - }, ]; const AUDIT_GROUP: SidebarItemGroup = { diff --git a/tests/unit/sidebar-quota-share-placement.test.ts b/tests/unit/sidebar-quota-share-placement.test.ts new file mode 100644 index 0000000000..8118e5ade6 --- /dev/null +++ b/tests/unit/sidebar-quota-share-placement.test.ts @@ -0,0 +1,77 @@ +/** + * tests/unit/sidebar-quota-share-placement.test.ts + * + * Task 3 — source-scan assertions for Quota Share nav item placement. + * + * Asserts that `costs-quota-share` sits immediately after `quota` (Provider Quota) + * in the SAME array, and is no longer in the costs section array. + * + * Pattern mirrors: tests/unit/quota-groups-ui.test.ts (readFileSync style) + * + * Node.js native test runner — no DOM setup required. + */ + +import test from "node:test"; +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { join, dirname } from "node:path"; +import { fileURLToPath } from "node:url"; + +const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", ".."); + +const SIDEBAR_PATH = join(ROOT, "src/shared/constants/sidebarVisibility.ts"); + +const src = readFileSync(SIDEBAR_PATH, "utf8"); + +// ── Placement order: costs-quota-share must come AFTER quota ───────────────── + +test("sidebar: costs-quota-share appears after quota in source", () => { + const idxQuota = src.indexOf('id: "quota"'); + const idxQuotaShare = src.indexOf('id: "costs-quota-share"'); + assert.ok(idxQuota >= 0, 'Could not find id: "quota" in sidebarVisibility.ts'); + assert.ok(idxQuotaShare >= 0, 'Could not find id: "costs-quota-share" in sidebarVisibility.ts'); + assert.ok( + idxQuotaShare > idxQuota, + `costs-quota-share (idx ${idxQuotaShare}) must appear AFTER quota (idx ${idxQuota})` + ); +}); + +// ── Same array: no array-close ]; between quota and costs-quota-share ───────── + +test("sidebar: no array close ]; between quota and costs-quota-share (same array)", () => { + const idxQuota = src.indexOf('id: "quota"'); + const idxQuotaShare = src.indexOf('id: "costs-quota-share"'); + assert.ok(idxQuota >= 0, 'Could not find id: "quota"'); + assert.ok(idxQuotaShare >= 0, 'Could not find id: "costs-quota-share"'); + const between = src.slice(idxQuota, idxQuotaShare); + assert.ok( + !between.includes("];"), + `There must be NO array-close ]; between quota and costs-quota-share. Found one, meaning they are in different arrays.\nSlice between them:\n${between}` + ); +}); + +// ── Costs section no longer contains costs-quota-share ─────────────────────── + +test("sidebar: costs section does not have costs-quota-share right after costs-budget", () => { + // costs-budget and costs-quota-share should NOT be close neighbours (within 200 chars) + const idxBudget = src.indexOf('id: "costs-budget"'); + const idxQuotaShare = src.indexOf('id: "costs-quota-share"'); + assert.ok(idxBudget >= 0, 'Could not find id: "costs-budget"'); + assert.ok(idxQuotaShare >= 0, 'Could not find id: "costs-quota-share"'); + const gap = Math.abs(idxQuotaShare - idxBudget); + assert.ok( + gap > 200, + `costs-quota-share must NOT be immediately after costs-budget in the costs section (gap: ${gap} chars, expected > 200)` + ); +}); + +// ── Exactly one occurrence of costs-quota-share ─────────────────────────────── + +test("sidebar: exactly one occurrence of costs-quota-share", () => { + const occurrences = src.split('id: "costs-quota-share"').length - 1; + assert.equal( + occurrences, + 1, + `Expected exactly 1 occurrence of id: "costs-quota-share", found ${occurrences}` + ); +});