From 35198724463f9b77bafe5ed62fcf161105c20cb4 Mon Sep 17 00:00:00 2001 From: Alexey Grigorev Date: Wed, 18 Nov 2026 15:33:44 +0100 Subject: [PATCH] inventory: make Inventory a standalone top-level surface separate from Bookkeeping /invertory resolved to a bookkeeping sub-view, so the sidebar lit both Bookkeeping and Inventory at once and Inventory read as a child of the ledger. Inventory is now its own workspace view and surface: the route maps /invertory to view 'inventory', the nav button targets that view, and a new inventory surface fetches the items and renders the original ledger record in its own dialog without mounting bookkeeping. The bookkeeping surface drops the inventory section, its SECONDARY_VIEWS entry, and the sidebar nav ownership; the deployed-asset manifest registers the new module. --- backend/src/docs/frontend-assets.json | 1 + frontend/index.html | 2 +- frontend/src/core/workspace.js | 5 +- frontend/src/runtime/application-events.js | 6 +- frontend/src/runtime/application.js | 2 + frontend/src/runtime/surface-composition.js | 6 +- frontend/src/shell/startup-orchestration.js | 2 +- .../surfaces/finance/bookkeeping-ledger.js | 2 +- .../surfaces/finance/bookkeeping-markup.js | 17 +- frontend/src/surfaces/finance/bookkeeping.js | 40 +---- frontend/src/surfaces/finance/index.js | 3 + frontend/src/surfaces/finance/inventory.js | 158 ++++++++++++++++++ .../test/bookkeeping-inventory-nav.test.mjs | 32 +++- frontend/test/finance-surface.test.mjs | 78 ++++----- frontend/test/routing.test.mjs | 2 +- frontend/test/runtime-shell-behavior.test.mjs | 9 +- frontend/test/startup-orchestration.test.mjs | 2 +- 17 files changed, 250 insertions(+), 117 deletions(-) create mode 100644 frontend/src/surfaces/finance/inventory.js diff --git a/backend/src/docs/frontend-assets.json b/backend/src/docs/frontend-assets.json index 9bc0816e6..139048540 100644 --- a/backend/src/docs/frontend-assets.json +++ b/backend/src/docs/frontend-assets.json @@ -118,6 +118,7 @@ "src/surfaces/finance/bookkeeping-views.js", "src/surfaces/finance/bookkeeping.js", "src/surfaces/finance/index.js", + "src/surfaces/finance/inventory.js", "src/surfaces/finance/invoices.js", "src/surfaces/finance/overview.js", "src/surfaces/finance/shared.js", diff --git a/frontend/index.html b/frontend/index.html index 3097fc415..6f26fbcad 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -76,7 +76,7 @@ CRM Finance Bookkeeping - Inventory + Inventory

Knowledge

Operating Model Process Docs diff --git a/frontend/src/core/workspace.js b/frontend/src/core/workspace.js index c44dbe56b..51d27a0ac 100644 --- a/frontend/src/core/workspace.js +++ b/frontend/src/core/workspace.js @@ -29,6 +29,7 @@ export const WORKSPACE_PATH_BY_VIEW = Object.freeze({ users: "/users", finance: "/finance", bookkeeping: "/bookkeeping", + inventory: "/invertory", sponsors: "/sponsors/pipeline", newsletter: "/newsletter", calendar: "/calendar", @@ -63,8 +64,8 @@ export const WORKSPACE_ROUTE_DEFINITIONS = Object.freeze({ tasksSection: "queue", params: ["month", "q", "account", "dir", "category", "needs", "tx", "view", "agreement"], }, - // The inventory page answers on its own bare path under Bookkeeping. - "/invertory": { view: "bookkeeping", tasksSection: "queue", params: [] }, + // Inventory is its own top-level surface; its address is the path. + "/invertory": { view: "inventory", tasksSection: "queue", params: [] }, // Bare /sponsors opens the default tab; every tab and record is a path. // Directory tabs declare their filter/sort/page params so filter state // survives navigation, refresh and back/forward through canonical URLs. diff --git a/frontend/src/runtime/application-events.js b/frontend/src/runtime/application-events.js index cdec586dd..2f6619d51 100644 --- a/frontend/src/runtime/application-events.js +++ b/frontend/src/runtime/application-events.js @@ -49,11 +49,7 @@ export function bindApplicationEvents(context) { button.dataset.workspaceTarget || button.dataset.workspaceView || "tasks", - // A sub-view entry (Bookkeeping → Inventory) addresses its own - // page, so it navigates by href instead of the parent view. - path: button.dataset.bookkeepingView - ? button.getAttribute("href") - : "", + path: "", }, }), ), diff --git a/frontend/src/runtime/application.js b/frontend/src/runtime/application.js index 4527aa3fc..70f4f880c 100644 --- a/frontend/src/runtime/application.js +++ b/frontend/src/runtime/application.js @@ -161,6 +161,7 @@ const { getRenderAdminSurfaceView: () => renderAdminSurfaceView, getRenderBookkeepingSurface: () => renderBookkeepingSurface, getRenderFinanceOverviewSurface: () => renderFinanceOverviewSurface, + getRenderInventorySurface: () => renderInventorySurface, getRenderCalendarSurface: () => renderCalendarSurface, getRenderDocsSurface: () => renderDocsSurface, getRenderInboxSurface: () => inboxSurface?.renderInbox || (() => undefined), @@ -204,6 +205,7 @@ const { canLeaveFinanceSurface, renderBookkeepingSurface, renderFinanceOverviewSurface, + renderInventorySurface, renderSponsorCrmSurface, } = createFinanceSurface({ documentList, diff --git a/frontend/src/runtime/surface-composition.js b/frontend/src/runtime/surface-composition.js index 861a2b45a..3258ddc11 100644 --- a/frontend/src/runtime/surface-composition.js +++ b/frontend/src/runtime/surface-composition.js @@ -120,6 +120,7 @@ export function createSurfaceComposition(context) { getRenderAdminSurfaceView, getRenderBookkeepingSurface, getRenderFinanceOverviewSurface, + getRenderInventorySurface, getRenderCalendarSurface, getRenderDocsSurface, getRenderInboxSurface, @@ -161,6 +162,7 @@ export function createSurfaceComposition(context) { if (view === "admin") return getRenderAdminSurfaceView()(documents); if (view === "users") return context.getRenderUsersSurfaceView()(); if (view === "bookkeeping") return getRenderBookkeepingSurface()(); + if (view === "inventory") return getRenderInventorySurface()(); if (view === "finance") return getRenderFinanceOverviewSurface()(); if (view === "sponsors") return getRenderSponsorCrmSurface()(); if (view === "newsletter") return getRenderNewsletterSurface()(); @@ -285,10 +287,6 @@ export function createSurfaceComposition(context) { body.dataset.workspaceView = activeView; searchInput.placeholder = "Search work and docs"; for (const button of workspaceNavButtons) { - // Sub-view entries (Bookkeeping → Inventory) follow the surface's own - // ?view= state, which changes without a route commit; renderView owns - // them, the generic pass would wrongly light them on every page. - if (button.dataset.bookkeepingView) continue; const active = button.dataset.workspaceView === activeView; button.classList.toggle("is-active", active); if (active) button.setAttribute("aria-current", "page"); diff --git a/frontend/src/shell/startup-orchestration.js b/frontend/src/shell/startup-orchestration.js index 1573328ef..2f148f2f5 100644 --- a/frontend/src/shell/startup-orchestration.js +++ b/frontend/src/shell/startup-orchestration.js @@ -19,7 +19,7 @@ // deferred at bootstrap and shielded from snapshot repaints together, so the // two can never drift apart. export const SELF_LOADING_VIEWS = Object.freeze( - new Set(["bookkeeping", "calendar", "finance", "inbox", "newsletter", "podcast", "sponsors", "users"]), + new Set(["bookkeeping", "calendar", "finance", "inbox", "inventory", "newsletter", "podcast", "sponsors", "users"]), ); // Whether committing this route needs none of the shared snapshots yet. An diff --git a/frontend/src/surfaces/finance/bookkeeping-ledger.js b/frontend/src/surfaces/finance/bookkeeping-ledger.js index 91b8b0c1f..1f85db864 100644 --- a/frontend/src/surfaces/finance/bookkeeping-ledger.js +++ b/frontend/src/surfaces/finance/bookkeeping-ledger.js @@ -10,7 +10,7 @@ import { bookkeepingVendorPresentation } from "./bookkeeping-vendors.js"; // Query parameters the bookkeeping route keeps in the URL. export const LEDGER_PARAMS = ["month", "q", "account", "dir", "category", "needs", "tx", "view"]; -export const SECONDARY_VIEWS = ["files", "package", "invoices", "tuition", "inventory"]; +export const SECONDARY_VIEWS = ["files", "package", "invoices", "tuition"]; // The classification columns: "Type" is stored as `subtype`, "Category" as // `category`. The spreadsheet's Period column is not shown in the table: it diff --git a/frontend/src/surfaces/finance/bookkeeping-markup.js b/frontend/src/surfaces/finance/bookkeeping-markup.js index 4636f0182..64f70f25e 100644 --- a/frontend/src/surfaces/finance/bookkeeping-markup.js +++ b/frontend/src/surfaces/finance/bookkeeping-markup.js @@ -1,10 +1,9 @@ import "../../dakit/collection.js"; // Static shell for the bookkeeping surface. The page is the transaction // list: header with the month navigator and actions, one filter row, the -// table with its detail pane. Inventory is its own page at /invertory -// reached from the sidebar; files, the accountant package/VAT, tuition +// table with its detail pane. Files, the accountant package/VAT, tuition // and forwarded invoices are secondary views (?view=…) reached from the -// ⋯ menu. +// ⋯ menu. Inventory is a separate surface at /invertory. import { financeSectionHead, html } from "./shared.js"; import { periodNavMarkup } from "../period-nav.js"; @@ -148,18 +147,8 @@ export function bookkeepingSurfaceMarkup() { ${backLink}
- diff --git a/frontend/src/surfaces/finance/bookkeeping.js b/frontend/src/surfaces/finance/bookkeeping.js index 33dbaf6d8..e92adaaf4 100644 --- a/frontend/src/surfaces/finance/bookkeeping.js +++ b/frontend/src/surfaces/finance/bookkeeping.js @@ -33,7 +33,6 @@ import { createBookkeepingTransactionModal } from "./bookkeeping-transaction-mod import { importStatementWithReview, confirmStatementReplacement } from "./bookkeeping-statement-import.js"; import { loadStatementLinkIndex } from "./bookkeeping-statement.js"; import { openBookkeepingDialog } from "./bookkeeping-dialogs.js"; -import { createBookkeepingInventory } from "./bookkeeping-inventory.js"; import { createBookkeepingFinance, monthlyLedgerEntries, @@ -91,12 +90,9 @@ export function createBookkeepingSurface(context) { let lens = LENS.test(initial.get("month") || "") ? initial.get("month") : ""; let filters = filtersFromParams(initial); let selectedId = initial.get("tx") || ""; - // Inventory answers on its own /invertory address; the other secondary - // views ride ?view= on the ledger path. - const requestedView = - (locationRef?.pathname || "") === "/invertory" - ? "inventory" - : initial.get("view") || ""; + // Secondary views (files, package/VAT, invoices, tuition) ride ?view= on + // the ledger path; inventory is a separate surface at /invertory. + const requestedView = initial.get("view") || ""; let view = SECONDARY_VIEWS.includes(requestedView) ? requestedView : ""; let defaultLens = "", invoicesMounted = false; const reconciliationCache = new Map(); @@ -158,16 +154,15 @@ export function createBookkeepingSurface(context) { if (view === "tuition" || !historyRef?.replaceState || !locationRef) return; const params = new URLSearchParams(); // The default month (latest with transactions) stays out of the URL. - // Inventory's address is the path, so its view never rides the query. const values = { month: lens === defaultLens ? "" : lens, ...filters, tx: selectedId, - view: view === "inventory" ? "" : view, + view, }; for (const name of LEDGER_PARAMS) if (values[name]) params.set(name, values[name]); const query = params.toString(); - const next = `${view === "inventory" ? "/invertory" : "/bookkeeping"}${query ? `?${query}` : ""}`; + const next = `/bookkeeping${query ? `?${query}` : ""}`; if (`${locationRef.pathname}${locationRef.search}` !== next) historyRef.replaceState(historyRef.state, "", next); } @@ -229,17 +224,6 @@ export function createBookkeepingSurface(context) { } function renderView() { surface.dataset.bkView = view || "transactions"; - // The sidebar's Inventory entry lives outside the surface and follows - // the in-page view, which changes without a route commit. It is owned - // through the surface's own document, so mounts under a DOM subset - // without a sidebar simply skip it. - const navItems = surface.ownerDocument?.querySelectorAll("[data-bookkeeping-view]") ?? []; - for (const item of navItems) { - const active = item.dataset.bookkeepingView === view; - item.classList.toggle("is-active", active); - if (active) item.setAttribute("aria-current", "page"); - else item.removeAttribute("aria-current"); - } surface.querySelector("[data-bk-main]").hidden = Boolean(view); surface.classList.toggle("dk-fill", !view); surface.querySelectorAll("[data-secondary]").forEach((section) => { @@ -250,7 +234,6 @@ export function createBookkeepingSurface(context) { invoicesMounted = true; mountInvoiceReview(surface.querySelector("[data-invoice-review]"), context); } - if (view === "inventory") inventory.renderInventory(); } function optionList(select, values, allLabel, current) { select.innerHTML = [ @@ -609,19 +592,6 @@ export function createBookkeepingSurface(context) { }, }); - const inventory = createBookkeepingInventory({ - surface, - api, - escapeHtml, - safeAction, - setStatus: (text) => { - status.textContent = text; - }, - todayIsoDate, - // Inventory rows link back to the ledger record they came from. - openTransaction: (id) => openTransaction(id), - }); - const navigation = mountBookkeepingNavigation({ surface, status, setLens, lensEntries, todayIsoDate, prepareExemptions: () => financeSummary.ensure(), diff --git a/frontend/src/surfaces/finance/index.js b/frontend/src/surfaces/finance/index.js index b34d6b29d..b64b18e24 100644 --- a/frontend/src/surfaces/finance/index.js +++ b/frontend/src/surfaces/finance/index.js @@ -1,5 +1,6 @@ import { createBookkeepingSurface } from "./bookkeeping.js"; import { createFinanceOverviewSurface } from "./overview.js"; +import { createInventorySurface } from "./inventory.js"; import { createSponsorCrmSurface } from "./sponsors.js"; import "./bookkeeping-statement.js"; import "./bookkeeping-transaction-dialog.js"; @@ -7,6 +8,7 @@ import "./bookkeeping-transaction-modal.js"; export function createFinanceSurface(context) { const bookkeeping = createBookkeepingSurface(context); + const inventory = createInventorySurface(context); const sponsors = createSponsorCrmSurface(context); const overview = createFinanceOverviewSurface(context); @@ -14,6 +16,7 @@ export function createFinanceSurface(context) { canLeaveFinanceSurface: sponsors.canLeaveFinanceSurface, renderBookkeepingSurface: bookkeeping.renderBookkeepingSurface, renderFinanceOverviewSurface: overview.renderFinanceOverviewSurface, + renderInventorySurface: inventory.renderInventorySurface, renderSponsorCrmSurface: sponsors.renderSponsorCrmSurface, }; } diff --git a/frontend/src/surfaces/finance/inventory.js b/frontend/src/surfaces/finance/inventory.js new file mode 100644 index 000000000..8a007b245 --- /dev/null +++ b/frontend/src/surfaces/finance/inventory.js @@ -0,0 +1,158 @@ +// Inventory surface: the company's physical property at /invertory, fully +// separate from the bookkeeping ledger surface. Items derive from ledger +// expenses (2022+), each row keeps its provenance link, and the record dialog +// fetches the original ledger transaction directly instead of reaching into +// the bookkeeping surface. +import { createBookkeepingInventory } from "./bookkeeping-inventory.js"; +import { createBookkeepingTransactionModal } from "./bookkeeping-transaction-modal.js"; +import { + INVOICE_SOURCE_PREFIX, + linkedEvidenceDocuments, + suggestionLoader, + suggestionsMarkup, +} from "./bookkeeping-ledger.js"; +import { formatAmount } from "./bookkeeping-format.js"; +import { html } from "./shared.js"; + +export function inventorySurfaceMarkup() { + return html`
+

Inventory

+ +
+

Physical purchases from the ledger since 2022 — computers, phones, audio, furniture. Scan the ledger after new expenses land.

+

+
Loading inventory…
+ + `; +} + +export function createInventorySurface(context) { + const { + documentList, + escapeHtml, + humanizeOptionLabel, + request, + setRouteTitle, + todayIsoDate, + workApiUrl, + } = context; + + async function renderInventorySurface() { + documentList.replaceChildren(); + const surface = document.createElement("section"); + surface.className = "bookkeeping-surface inventory-surface"; + surface.innerHTML = inventorySurfaceMarkup(); + documentList.append(surface); + setRouteTitle("Inventory"); + + const dialog = surface.querySelector("[data-inventory-transaction-dialog]"); + const status = surface.querySelector("[data-inventory-status]"); + const api = (path, options = {}) => + request(workApiUrl(`/api/bookkeeping${path}`), { + headers: { + "content-type": "application/json", + ...(options.headers || {}), + }, + ...options, + }); + + let statusTimer = null; + const setStatus = (text) => { + status.textContent = text; + clearTimeout(statusTimer); + if (text) statusTimer = setTimeout(() => { status.textContent = ""; }, 6000); + }; + async function safeAction(action, fallback) { + try { + await action(); + } catch (error) { + setStatus(`${fallback}: ${error.message}`); + } + } + function openDocument(id) { + // The tab opens inside the click task; waiting for the URL first gets + // it blocked as a popup. + const tab = globalThis.open?.("", "_blank"); + void safeAction(async () => { + const fromInvoice = String(id).startsWith(INVOICE_SOURCE_PREFIX); + const result = fromInvoice + ? await api(`/invoices/${encodeURIComponent(String(id).slice(INVOICE_SOURCE_PREFIX.length))}/document`) + : await api(`/documents/${encodeURIComponent(id)}/download?disposition=inline`); + const url = fromInvoice ? result.url : result.downloadUrl; + if (tab) tab.location.href = url; + }, "Could not open the file"); + } + + // The record dialog owns its data: the transaction itself, plus the + // evidence lists the first dialog open needs for invoice buttons. + const records = new Map(); + let evidence = null; + let selectedId = ""; + async function loadRecord(id) { + if (!evidence) { + const [docResult, linkResult] = await Promise.all([api("/documents"), api("/links")]); + evidence = { documents: docResult.items || [], links: linkResult.items || [] }; + } + const record = records.get(id) || await api(`/transactions/${encodeURIComponent(id)}`); + records.set(id, record); + return record; + } + + const suggestions = suggestionLoader({ + load: (id) => api(`/transactions/${encodeURIComponent(id)}/suggestions`), + holder: (id) => (selectedId === id ? dialog.querySelector("[data-suggestions]") : null), + render: (result) => suggestionsMarkup({ suggestions: result, humanize: humanizeOptionLabel, e: escapeHtml }), + }); + + const transactionModal = createBookkeepingTransactionModal({ + dialog, + request, + workApiUrl, + api, + escapeHtml, + formatAmount, + suggestions, + getSelectedId: () => selectedId, + getEntry: (id) => records.get(id) || null, + getAttached: (id) => { + const record = records.get(id); + if (!record || !evidence) return []; + return linkedEvidenceDocuments(record, evidence.links, evidence.documents); + }, + openDocument: (id) => openDocument(id), + refreshEvidence: async () => { + evidence = null; + records.delete(selectedId); + await loadRecord(selectedId); + }, + safeAction, + setStatus, + onClose: () => { + selectedId = ""; + }, + }); + + async function openTransaction(id) { + try { + const record = await loadRecord(id); + selectedId = id; + transactionModal.render(record); + } catch (error) { + setStatus(`Could not open the ledger record: ${error.message}`); + } + } + + const inventory = createBookkeepingInventory({ + surface, + api, + escapeHtml, + safeAction, + setStatus, + todayIsoDate, + openTransaction, + }); + await inventory.renderInventory(); + } + + return { renderInventorySurface }; +} diff --git a/frontend/test/bookkeeping-inventory-nav.test.mjs b/frontend/test/bookkeeping-inventory-nav.test.mjs index 3d7bc09e4..2ba46d228 100644 --- a/frontend/test/bookkeeping-inventory-nav.test.mjs +++ b/frontend/test/bookkeeping-inventory-nav.test.mjs @@ -2,6 +2,8 @@ import { test } from "node:test"; import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { bookkeepingSurfaceMarkup } from "../src/surfaces/finance/bookkeeping-markup.js"; +import { inventorySurfaceMarkup } from "../src/surfaces/finance/inventory.js"; +import { WORKSPACE_PATH_BY_VIEW, WORKSPACE_ROUTE_DEFINITIONS } from "../src/core/workspace.js"; function shell() { globalThis.dakitCollection = { @@ -10,17 +12,23 @@ function shell() { return bookkeepingSurfaceMarkup(); } -test("the sidebar hangs Inventory under Bookkeeping, addressed at /invertory", () => { +test("Inventory is its own top-level nav entry addressed at /invertory", () => { const index = readFileSync(new URL("../index.html", import.meta.url), "utf8"); - const item = index.match(/]*data-bookkeeping-view="inventory"[^>]*>[\s\S]*?<\/a>/)?.[0] ?? ""; + const item = index.match(/]*id="inventory-nav-button"[^>]*>[\s\S]*?<\/a>/)?.[0] ?? ""; assert.match(item, /href="\/invertory"/); - assert.doesNotMatch(item, /bookkeeping\?view=inventory/); - assert.match(item, /data-workspace-view="bookkeeping"/); + assert.match(item, /data-workspace-view="inventory"/); + assert.doesNotMatch(item, /data-workspace-view="bookkeeping"/); + assert.doesNotMatch(item, /data-bookkeeping-view/); assert.match(item, /class="dk-nav-item workspace-nav-button"/); assert.doesNotMatch(item, /dk-nav-item--sub/); assert.match(item, />Inventory<\/span>/); }); +test("/invertory resolves to its own inventory view, not a bookkeeping sub-view", () => { + assert.equal(WORKSPACE_ROUTE_DEFINITIONS["/invertory"].view, "inventory"); + assert.equal(WORKSPACE_PATH_BY_VIEW.inventory, "/invertory"); +}); + test("the bookkeeping surface has no in-page view tabs: the sidebar navigates", () => { assert.doesNotMatch(shell(), /data-bk-view-tabs/); }); @@ -35,8 +43,16 @@ test("the ⋯ menu keeps the accountant actions and other views but drops Invent assert.doesNotMatch(menu, /data-view-link="inventory"/); }); -test("the inventory section keeps its back link now that the tab bar is gone", () => { - const section = shell().match(/
/)?.[0] ?? ""; - assert.match(section, /data-secondary="inventory"/); - assert.match(section, /bk-back/); +test("the bookkeeping surface has no inventory section left", () => { + const markup = shell(); + assert.doesNotMatch(markup, /data-secondary="inventory"/); + assert.doesNotMatch(markup, /data-inventory-scan/); + assert.doesNotMatch(markup, /data-inventory\b/); +}); + +test("the inventory surface owns its scan action, table host and record dialog", () => { + const markup = inventorySurfaceMarkup(); + assert.match(markup, /data-inventory-scan/); + assert.match(markup, /data-inventory\b/); + assert.match(markup, /]*data-inventory-transaction-dialog/); }); diff --git a/frontend/test/finance-surface.test.mjs b/frontend/test/finance-surface.test.mjs index 8c55bb6ae..5fbd81563 100644 --- a/frontend/test/finance-surface.test.mjs +++ b/frontend/test/finance-surface.test.mjs @@ -455,6 +455,7 @@ describe("Finance surface boundary", () => { "canLeaveFinanceSurface", "renderBookkeepingSurface", "renderFinanceOverviewSurface", + "renderInventorySurface", "renderSponsorCrmSurface", ]); }); @@ -572,16 +573,8 @@ describe("Finance surface boundary", () => { assert.ok(requests.some(({ url }) => requestPath(url) === "/api/reconcile/months/2026-08")); }); - test("opening /invertory mounts the inventory page and keeps its bare address", async () => { - const replaced = []; - const { document: doc, finance, requests } = createHarness({ - locationRef: { pathname: "/invertory", search: "" }, - historyRef: { state: null, replaceState: (state, _title, url) => replaced.push(url) }, - setupSurface: (surface) => { - const section = new FakeElement("section"); - section.dataset.secondary = "inventory"; - surface.setQueryAll("[data-secondary]", [section]); - }, + test("the inventory surface mounts standalone and fetches its items", async () => { + const { document: doc, finance, requests, routeTitles } = createHarness({ request: async (url) => { const path = requestPath(url); if (path === "/api/bookkeeping/inventory") return { items: [{ @@ -591,56 +584,63 @@ describe("Finance surface boundary", () => { source: { transactionId: "tx-1", description: "MacBook Pro 14", counterparty: "Amazon", date: "2026-03-19", amount: "1813.58", currency: "EUR", amountEur: "1813.58" }, }] }; - if (["/api/bookkeeping/transactions", "/api/bookkeeping/documents", "/api/bookkeeping/links", - "/api/bookkeeping/accounts", "/api/bookkeeping/reports", "/api/bookkeeping/invoices"].includes(path)) - return { items: [] }; - if (path === "/api/finance/summary") return { entries: [], months: [], totals: {} }; throw new Error(`Unexpected request: ${url}`); }, }); - await finance.renderBookkeepingSurface(); + await finance.renderInventorySurface(); await settle(); + assert.equal(routeTitles.at(-1), "Inventory"); assert.ok(requests.some(({ url }) => requestPath(url) === "/api/bookkeeping/inventory")); - const section = doc.surface.querySelectorAll("[data-secondary]")[0]; - assert.equal(section.hidden, false, "the inventory section is the visible view"); - assert.equal(doc.surface.querySelector("[data-bk-main]").hidden, true, "the ledger pane is hidden"); assert.match(doc.surface.querySelector("[data-inventory]").innerHTML, /Laptop/); - assert.deepEqual(replaced, [], "/invertory is already canonical; nothing rewrites it"); + assert.deepEqual( + requests.filter(({ url }) => requestPath(url) === "/api/bookkeeping/transactions"), + [], + "the inventory surface never loads the ledger", + ); }); - test("leaving the inventory page returns the ledger to /bookkeeping", async () => { - const replaced = []; - const { document: doc, finance } = createHarness({ - locationRef: { pathname: "/invertory", search: "" }, - historyRef: { state: null, replaceState: (state, _title, url) => replaced.push(url) }, - setupSurface: (surface) => { - const section = new FakeElement("section"); - section.dataset.secondary = "inventory"; - surface.setQueryAll("[data-secondary]", [section]); - }, + test("clicking an inventory record fetches and opens the original ledger transaction", async () => { + const { document: doc, finance, requests } = createHarness({ request: async (url) => { const path = requestPath(url); - if (path === "/api/bookkeeping/inventory") return { items: [] }; - if (["/api/bookkeeping/transactions", "/api/bookkeeping/documents", "/api/bookkeeping/links", - "/api/bookkeeping/accounts", "/api/bookkeeping/reports", "/api/bookkeeping/invoices"].includes(path)) + if (path === "/api/bookkeeping/inventory") return { items: [{ + id: "inv-laptop", transactionId: "tx-1", name: "Laptop", type: "computer", vendor: "Amazon", + acquisitionDate: "2026-03-19", amount: "1813.58", currency: "EUR", amountEur: "1813.58", + status: "in-use", + source: { transactionId: "tx-1", description: "MacBook Pro 14", counterparty: "Amazon", + date: "2026-03-19", amount: "1813.58", currency: "EUR", amountEur: "1813.58" }, + }] }; + if (path === "/api/bookkeeping/transactions/tx-1") + return { id: "tx-1", counterparty: "Amazon", transactionDate: "2026-03-19", + description: "MacBook Pro 14", amount: "-1813.58", currency: "EUR", + amountEur: "-1813.58", entryType: "expense" }; + if (path === "/api/bookkeeping/documents" || path === "/api/bookkeeping/links") return { items: [] }; - if (path === "/api/finance/summary") return { entries: [], months: [], totals: {} }; + if (path === "/api/bookkeeping/transactions/tx-1/suggestions") + return { documents: [], sponsor: { deals: [] } }; + if (path.startsWith("/api/reconcile/months/")) return { month: { rows: [] } }; throw new Error(`Unexpected request: ${url}`); }, }); - await finance.renderBookkeepingSurface(); + await finance.renderInventorySurface(); await settle(); - await doc.surface.dispatch("click", { + await doc.surface.querySelector("[data-inventory]").dispatch("click", { target: { closest: (selector) => - selector === "[data-view-link]" ? { dataset: { viewLink: "" } } : null, + selector === "[data-inv]" ? { dataset: { inv: "inv-laptop" } } : null, }, }); - assert.deepEqual(replaced, ["/bookkeeping"]); - assert.equal(doc.surface.querySelectorAll("[data-secondary]")[0].hidden, true); - assert.equal(doc.surface.querySelector("[data-bk-main]").hidden, false); + await settle(); + await settle(); + const dialog = doc.surface.querySelector("[data-inventory-transaction-dialog]"); + assert.match(dialog.innerHTML, /Amazon/); + assert.match(dialog.innerHTML, /MacBook Pro 14/); + assert.ok( + requests.some(({ url }) => requestPath(url) === "/api/bookkeeping/transactions/tx-1"), + "the record dialog fetches the original ledger transaction", + ); }); test("keeps sponsor alert failures truthful and retries pages without duplicates", async () => { diff --git a/frontend/test/routing.test.mjs b/frontend/test/routing.test.mjs index f69d7a9dd..15dcfb824 100644 --- a/frontend/test/routing.test.mjs +++ b/frontend/test/routing.test.mjs @@ -94,7 +94,7 @@ describe("canonical workspace routing", () => { test("the inventory page answers on its own /invertory address", () => { const route = parseWorkspaceLocation("/invertory", browserLocation("/invertory")); - assert.equal(route.view, "bookkeeping"); + assert.equal(route.view, "inventory"); assert.equal(route.canonicalUrl, "/invertory"); assert.equal(route.normalized, false); }); diff --git a/frontend/test/runtime-shell-behavior.test.mjs b/frontend/test/runtime-shell-behavior.test.mjs index 040298d6a..85501b4ba 100644 --- a/frontend/test/runtime-shell-behavior.test.mjs +++ b/frontend/test/runtime-shell-behavior.test.mjs @@ -419,8 +419,7 @@ function createBindingDom() { dom.workspaceNavButtons = [element("home-nav", "button")]; dom.workspaceNavButtons[0].dataset.workspaceTarget = "tasks"; const inventoryNav = element("inventory-nav", "button"); - inventoryNav.dataset.workspaceView = "bookkeeping"; - inventoryNav.dataset.bookkeepingView = "inventory"; + inventoryNav.dataset.workspaceView = "inventory"; inventoryNav.setAttribute("href", "/invertory"); dom.workspaceNavButtons.push(inventoryNav); dom.tasksNavSectionButtons = [element("cards-nav", "button")]; @@ -877,10 +876,10 @@ describe("runtime and shell production behavior", () => { await dom.tasksNavSectionButtons[0].click(); assert.equal(calls.some(([name, path]) => name === "navigate" && path === "/tasks/cards"), true); - // The Inventory entry is a sub-view of Bookkeeping: its click navigates - // to its own address instead of the bare parent view. + // Inventory is its own workspace view: the click asks for it, and the + // canonical address for that view is /invertory. await dom.workspaceNavButtons[1].click(); - assert.equal(calls.some(([name, path]) => name === "navigate" && path === "/invertory"), true); + assert.equal(calls.some(([name, view]) => name === "workspace" && view === "inventory"), true); assert.equal(calls.some(([name, view]) => name === "workspace" && view === "bookkeeping"), false); await dom.editor.dispatch("input"); assert.equal(calls.some(([name]) => name === "storeDraft"), true); diff --git a/frontend/test/startup-orchestration.test.mjs b/frontend/test/startup-orchestration.test.mjs index 818b19c66..53174635e 100644 --- a/frontend/test/startup-orchestration.test.mjs +++ b/frontend/test/startup-orchestration.test.mjs @@ -47,7 +47,7 @@ describe("startup route classification", () => { test("defers every self-loading view and nothing else", () => { assert.deepEqual( [...SELF_LOADING_VIEWS].sort(), - ["bookkeeping", "calendar", "finance", "inbox", "newsletter", "podcast", "sponsors", "users"], + ["bookkeeping", "calendar", "finance", "inbox", "inventory", "newsletter", "podcast", "sponsors", "users"], ); for (const view of SELF_LOADING_VIEWS) { assert.equal(isStartupDeferredRoute({ view }), true, view);