diff --git a/app/(dashboard)/browser/page.tsx b/app/(dashboard)/browser/page.tsx index 822dfa9b..cdfbf63b 100644 --- a/app/(dashboard)/browser/page.tsx +++ b/app/(dashboard)/browser/page.tsx @@ -18,11 +18,9 @@ import { useObject } from "@/hooks/use-object" import { usePermissions } from "@/hooks/use-permissions" import { useDialog } from "@/lib/feedback/dialog" import { useMessage } from "@/lib/feedback/message" -import { formatDateTime } from "@/lib/functions" +import { formatDateTime, formatInteger, niceBytes } from "@/lib/functions" import { normalizeDateToIso } from "@/lib/safe-date" -import { getAccountBucketUsage, getAccountBucketScanStatus } from "@/lib/account-bucket-usage" -import type { AccountBucketScanStatus } from "@/lib/account-bucket-usage" -import { BucketUsageValue, BucketScanNotice } from "@/components/buckets/usage-value" +import { getAccountBucketUsage } from "@/lib/account-bucket-usage" import { BucketNameCell, type BucketNameRow } from "@/components/buckets/name-cell" import { loadBucketPolicyStatuses } from "@/lib/bucket-policy-status" import { BrowserContent } from "./content" @@ -31,9 +29,8 @@ import type { ColumnDef } from "@tanstack/react-table" interface BucketRow { Name: string CreationDate: string - Unmeasured?: boolean Count?: number - ScanStatus?: AccountBucketScanStatus + Size?: string SizeBytes?: number IsPublic?: boolean } @@ -149,24 +146,22 @@ function BrowserBucketsPage() { const usageLoading = accountInfoLoading || !hasFetchedPolicy const bucketUsage = useMemo(() => getAccountBucketUsage(userInfo), [userInfo]) - const scanStatuses = useMemo(() => getAccountBucketScanStatus(userInfo), [userInfo]) const rowsWithUsage = useMemo( () => data.map((row) => { const usage = bucketUsage.get(row.Name) - const ScanStatus = scanStatuses.get(row.Name) const BucketHref = `/browser?bucket=${encodeURIComponent(row.Name)}` - if (!usage) return { ...row, BucketHref, ScanStatus, Unmeasured: usage === null } + if (!usage) return { ...row, BucketHref } return { ...row, BucketHref, - ScanStatus, Count: usage.objectsCount, + Size: niceBytes(String(usage.sizeBytes)), SizeBytes: usage.sizeBytes, } }), - [bucketUsage, scanStatuses, data], + [bucketUsage, data], ) const filteredData = useMemo( () => @@ -196,15 +191,14 @@ function BrowserBucketsPage() { header: () => t("Object Count"), accessorKey: "Count", meta: { align: "end" }, - cell: ({ row }) => ( - - ), + cell: ({ row }) => + typeof row.original.Count === "number" ? ( + formatInteger(row.original.Count) + ) : usageLoading ? ( + + ) : ( + "--" + ), }, { header: () => t("Size"), @@ -212,15 +206,8 @@ function BrowserBucketsPage() { meta: { align: "end" }, // use numeric bytes for sorting via accessorFn, but display the formatted string accessorFn: (row) => (typeof row.SizeBytes === "number" ? row.SizeBytes : undefined), - cell: ({ row }) => ( - - ), + cell: ({ row }) => + row.original.Size ?? (usageLoading ? : "--"), }, ) @@ -337,8 +324,6 @@ function BrowserBucketsPage() { usageAvailable={!usageLoading && Array.isArray(userInfo?.buckets)} /> - - getAccountBucketUsage(userInfo), [userInfo]) - const scanStatuses = React.useMemo(() => getAccountBucketScanStatus(userInfo), [userInfo]) const rowsWithUsage = React.useMemo( () => data.map((row) => { const usage = bucketUsage.get(row.Name) - const ScanStatus = scanStatuses.get(row.Name) const BucketHref = getBucketHref(row.Name) - if (!usage) return { ...row, BucketHref, ScanStatus, Unmeasured: usage === null } + if (!usage) return { ...row, BucketHref } return { ...row, BucketHref, - ScanStatus, Count: usage.objectsCount, + Size: niceBytes(String(usage.sizeBytes)), SizeBytes: usage.sizeBytes, } }), - [bucketUsage, scanStatuses, data, getBucketHref], + [bucketUsage, data, getBucketHref], ) const filteredData = React.useMemo( () => @@ -169,30 +164,22 @@ export function BucketList({ title, emptyDescription, getBucketHref }: BucketLis header: () => t("Object Count"), accessorKey: "Count", meta: { align: "end" }, - cell: ({ row }) => ( - - ), + cell: ({ row }) => + typeof row.original.Count === "number" ? ( + formatInteger(row.original.Count) + ) : usageLoading ? ( + + ) : ( + "--" + ), }, { header: () => t("Size"), id: "SizeBytes", meta: { align: "end" }, accessorFn: (row) => (typeof row.SizeBytes === "number" ? row.SizeBytes : undefined), - cell: ({ row }) => ( - - ), + cell: ({ row }) => + row.original.Size ?? (usageLoading ? : "--"), }, { header: () => t("Access Policy"), @@ -235,8 +222,6 @@ export function BucketList({ title, emptyDescription, getBucketHref }: BucketLis {title} - - - - - {row.original.Name} - - - + + + {row.original.Name} + ) } diff --git a/components/buckets/usage-value.tsx b/components/buckets/usage-value.tsx deleted file mode 100644 index 9cf5bfc0..00000000 --- a/components/buckets/usage-value.tsx +++ /dev/null @@ -1,113 +0,0 @@ -"use client" - -import { useEffect, useRef } from "react" -import { useTranslation } from "react-i18next" -import { Spinner } from "@/components/ui/spinner" -import { formatDateTime, formatInteger, niceBytes } from "@/lib/functions" -import type { AccountBucketScanStatus } from "@/lib/account-bucket-usage" - -interface BucketUsageValueProps { - value?: number - kind: "objects" | "size" - status?: AccountBucketScanStatus - loading: boolean - unmeasured?: boolean -} - -export function BucketUsageValue({ value, kind, status, loading, unmeasured }: BucketUsageValueProps) { - const { t } = useTranslation() - const progress = status?.progress - const observed = kind === "objects" ? progress?.objectsCount : progress?.sizeBytes - const format = (number: number) => (kind === "objects" ? formatInteger(number) : niceBytes(String(number))) - - if (typeof value !== "number" && typeof observed !== "number") { - if (progress) return — - return loading ? ( - - ) : ( - t(unmeasured ? "Not measured" : "Unavailable") - ) - } - - return ( -
- {typeof value === "number" ? format(value) : t("{value} scanned", { value: format(observed!) })} - {typeof value === "number" && typeof observed === "number" && ( - {t("{value} scanned", { value: format(observed) })} - )} -
- ) -} - -export function BucketUsageStatus({ bucketName, status }: { bucketName: string; status?: AccountBucketScanStatus }) { - const { t } = useTranslation() - const progress = status?.progress - const timestamp = (milliseconds: number) => formatDateTime(new Date(milliseconds).toISOString()) - const liveRegion = useRef(null) - - const stage = progress - ? t( - { - enumerating: "Enumerating objects", - scanning: "Scan in progress", - awaiting_sources: "Waiting for scanner sources", - completed: "Traversal complete", - }[progress.stage], - ) - : undefined - - const announcement = progress - ? [ - t("Scan progress for {bucket}", { bucket: bucketName }), - stage, - progress && t("Checkpoint: {time}", { time: timestamp(progress.updatedAt) }), - typeof progress?.objectsCount === "number" && - `${t("Object Count")}: ${t("{value} scanned", { value: formatInteger(progress.objectsCount) })}`, - typeof progress?.sizeBytes === "number" && - `${t("Size")}: ${t("{value} scanned", { value: niceBytes(String(progress.sizeBytes)) })}`, - status?.updatedAt && t("Last complete scan: {time}", { time: timestamp(status.updatedAt) }), - ] - .filter(Boolean) - .join(". ") - : "" - - useEffect(() => { - // Register the empty live region before publishing its first message. - const timer = setTimeout(() => { - if (liveRegion.current && liveRegion.current.textContent !== announcement) { - liveRegion.current.textContent = announcement - } - }, 0) - return () => clearTimeout(timer) - }, [announcement]) - - return ( - <> - - {(progress || status?.updatedAt) && ( -
- {progress && ( - <> - {stage} - - - )} - {status?.updatedAt && ( - - )} -
- )} - - ) -} - -export function BucketScanNotice({ statuses }: { statuses: Map }) { - const { t } = useTranslation() - return [...statuses.values()].some((status) => status.progress?.objectsCount !== undefined) ? ( -

{t("Scanned usage is not the bucket total.")}

- ) : null -} diff --git a/docs/ui-review/scanner-progress/after-desktop-placeholders.jpg b/docs/ui-review/scanner-progress/after-desktop-placeholders.jpg new file mode 100644 index 00000000..4d0ca123 Binary files /dev/null and b/docs/ui-review/scanner-progress/after-desktop-placeholders.jpg differ diff --git a/tests/hooks/use-permissions-refresh.test.ts b/tests/hooks/use-permissions-refresh.test.ts index 0defee4d..b88549ec 100644 --- a/tests/hooks/use-permissions-refresh.test.ts +++ b/tests/hooks/use-permissions-refresh.test.ts @@ -8,7 +8,6 @@ import { flexRender, type CellContext } from "@tanstack/react-table" import ts from "typescript" import type { usePermissions as UsePermissions } from "../../hooks/use-permissions" import type { PermissionRequest, PermissionResult } from "../../lib/effective-permissions" -import { formatDateTime } from "../../lib/functions" const mocksKey = Symbol.for("browser-permission-refresh") const mockExports: Record = { @@ -58,13 +57,9 @@ function moduleUrl(path: string, overrides: Record = {}) { } const permissionsUrl = moduleUrl("hooks/use-permissions.tsx") -const usageValueUrl = moduleUrl("components/buckets/usage-value.tsx") const overrides = { "@/hooks/use-permissions": permissionsUrl, - "@/components/buckets/usage-value": usageValueUrl, - "@/components/buckets/name-cell": moduleUrl("components/buckets/name-cell.tsx", { - "@/components/buckets/usage-value": usageValueUrl, - }), + "@/components/buckets/name-cell": moduleUrl("components/buckets/name-cell.tsx"), } const { PermissionsProvider, usePermissions } = (await import( permissionsUrl @@ -473,226 +468,64 @@ test("manual refresh and returning to Browser still force fresh buckets and acco }) for (const surface of ["Browser", "BucketList"] as const) { - for (const hasCompleteUsage of [false, true]) { - test(`${surface} ${hasCompleteUsage ? "retains complete usage alongside" : "shows only"} replaceable scanner progress`, async (t) => { - t.mock.timers.enable({ apis: ["setTimeout"] }) - const mounted = await mountBrowser(t, { surface }) - const info = (objects: number, size: number) => ({ - policy, - buckets: [ - { - name: "test-bucket", - ...(hasCompleteUsage - ? { objects: 90, size: 900, usage_value_state: "carried", usage_updated_at: 1700000000000 } - : {}), - scan_progress: { - stage: "scanning", - updated_at: 1800000000000, - objects, - size, - sources_observed: 1, - sources_total: 2, - }, - }, - ], - }) - let liveStatus: ReturnType = null - const assertSample = (objects: number, size: number) => { - const row = JSON.parse(mounted.container.querySelector("output")!.textContent)[0] - const name = mounted.container.querySelector('[data-bucket="test-bucket"] [data-metric="Name"]')! - const count = mounted.container.querySelector('[data-bucket="test-bucket"] [data-metric="Count"]')! - const capacity = mounted.container.querySelector('[data-bucket="test-bucket"] [data-metric="SizeBytes"]')! - const status = name.querySelector('[role="status"]')! - assert.ok(status, "the Name cell contains the shared scanner status") - if (liveStatus) assert.ok(status === liveStatus, "refresh must update the existing live-region node") - liveStatus = status - assert.deepEqual( - Array.from(count.querySelectorAll(".tabular-nums > span"), (span) => span.textContent), - hasCompleteUsage ? ["90", `${objects} scanned`] : [`${objects} scanned`], - ) - assert.deepEqual( - Array.from(capacity.querySelectorAll(".tabular-nums > span"), (span) => span.textContent), - hasCompleteUsage ? ["900.0 B", `${size}.0 B scanned`] : [`${size}.0 B scanned`], - ) - assert.ok(status.classList.contains("sr-only"), "announcements stay separate from the visible status") - assert.equal( - status.textContent, - `Scan progress for test-bucket. Scan in progress. Checkpoint: ${formatDateTime(1800000000000)}. Object Count: ${objects} scanned. Size: ${size}.0 B scanned${hasCompleteUsage ? `. Last complete scan: ${formatDateTime(1700000000000)}` : ""}`, - ) - assert.deepEqual( - Array.from(name.querySelectorAll("time"), (time) => time.dateTime), - [1800000000000, ...(hasCompleteUsage ? [1700000000000] : [])].map((time) => new Date(time).toISOString()), - ) - assert.ok( - Array.from(name.querySelectorAll("span")).some( - (span) => span.textContent === "Scan in progress" && !span.closest(".sr-only"), - ), - "the stage also remains visible outside the live span", - ) - assert.equal( - name.querySelector("a")?.getAttribute("href"), - surface === "Browser" ? "/browser?bucket=test-bucket" : "/custom-buckets/test-bucket", - ) - assert.equal(status.getAttribute("aria-live"), "polite") - assert.equal(status.getAttribute("aria-atomic"), "true") - assert.equal(status.hasAttribute("aria-label"), false) - assert.equal(mounted.container.querySelectorAll('[data-bucket="test-bucket"] [role="status"]').length, 1) - assert.deepEqual(mounted.container.textContent.match(/Scanned usage is not the bucket total\./g), [ - "Scanned usage is not the bucket total.", - ]) - if (hasCompleteUsage) { - assert.deepEqual([row.Count, row.SizeBytes], [90, 900]) - assert.match(status.textContent, /Last complete scan:/) - } else { - assert.equal(Object.hasOwn(row, "Count"), false) - assert.equal(Object.hasOwn(row, "SizeBytes"), false) - assert.doesNotMatch(status.textContent, /Last complete scan:/) - } - } - - const first = info(7, 71) - const next = info(9, 91) - await mounted.resolve(0, first) - const registeredStatus = mounted.container.querySelector('[data-metric="Name"] [role="status"]')! - assert.ok(registeredStatus, "the initial render registers a live region") - assert.equal(registeredStatus.textContent, "", "the live region registers before its first announcement") - let mutations = 0 - const observer = new mounted.browser.MutationObserver((records) => { - mutations += records.length - }) - observer.observe(registeredStatus, { childList: true, characterData: true, subtree: true }) - t.after(() => observer.disconnect()) - const takeMutations = () => { - const count = mutations + observer.takeRecords().length - mutations = 0 - return count - } - if (surface === "Browser") { - await mounted.resolve(1, first) - assert.ok( - mounted.container.querySelector('[data-metric="Name"] [role="status"]') === registeredStatus, - "the initial loading transition retains the empty live region", - ) - } - await mounted.flushAnnouncements() - assert.ok(takeMutations() > 0, "the first announcement is a later mutation of the registered node") - assertSample(7, 71) - let previous = first - for (const response of [first, next, next]) { - const requestIndex = mounted.requests.length - const previousAnnouncement: string = registeredStatus.textContent - await mounted.refresh() - assert.ok( - mounted.container.querySelector('[data-metric="Name"] [role="status"]') === registeredStatus, - "the loading state keeps the same live-region node", - ) - assert.equal(registeredStatus.textContent, previousAnnouncement) - await mounted.resolve(requestIndex, structuredClone(response)) - assert.equal(registeredStatus.textContent, previousAnnouncement, "new content waits for the next task") - await mounted.flushAnnouncements() - assertSample(response.buckets[0].scan_progress.objects, response.buckets[0].scan_progress.size) - if (response === previous) assert.equal(takeMutations(), 0, "an identical response must not announce again") - else assert.ok(takeMutations() > 0, "a changed response updates the existing announcement") - previous = response - } - }) - } - - test(`${surface} clears and restores its registered announcement without publishing superseded samples`, async (t) => { - t.mock.timers.enable({ apis: ["setTimeout"] }) - const bucketName = "bucket &prefix=other/路径" - const mounted = await mountBrowser(t, { surface, bucketName }) - const idle = { - policy, - buckets: [ - { name: bucketName, objects: 90, size: 900, usage_value_state: "carried", usage_updated_at: 1700000000000 }, - ], - } - const sample = (objects: number, size: number) => ({ + test(`${surface} renders complete bucket statistics without scanner details`, async (t) => { + const mounted = await mountBrowser(t, { surface }) + const info = { policy, buckets: [ { - ...idle.buckets[0], + name: "test-bucket", + objects: 90, + size: 900, scan_progress: { stage: "scanning", updated_at: 1800000000000, - objects, - size, + objects: 7, + size: 71, sources_observed: 1, sources_total: 2, }, }, ], - }) - await mounted.resolve(0, idle) - const liveStatus = mounted.container.querySelector('[data-metric="Name"] [role="status"]')! - assert.ok(liveStatus) - assert.equal(liveStatus.textContent, "") - if (surface === "Browser") await mounted.resolve(1, idle) - await mounted.flushAnnouncements() - assert.equal(liveStatus.textContent, "", "old complete measurements alone do not announce active progress") - const link = mounted.container.querySelector('[data-metric="Name"] a')! - assert.equal(link.textContent, bucketName) + } + await mounted.resolve(0, info) + if (surface === "Browser") await mounted.resolve(1, info) + + const row = JSON.parse(mounted.container.querySelector("output")!.textContent)[0] + const name = mounted.container.querySelector('[data-bucket="test-bucket"] [data-metric="Name"]')! + const count = mounted.container.querySelector('[data-bucket="test-bucket"] [data-metric="Count"]')! + const capacity = mounted.container.querySelector('[data-bucket="test-bucket"] [data-metric="SizeBytes"]')! + + assert.deepEqual([row.Count, row.SizeBytes], [90, 900]) + assert.equal(name.textContent, "test-bucket") + assert.equal(count.textContent, "90") + assert.equal(capacity.textContent, "900.0 B") + assert.equal(name.querySelector('[role="status"]'), null) + assert.doesNotMatch(mounted.container.textContent, /scanned|Scan progress|Checkpoint|Last complete scan/) assert.equal( - link.getAttribute("href"), - surface === "Browser" - ? `/browser?bucket=${encodeURIComponent(bucketName)}` - : `/custom-buckets/${encodeURIComponent(bucketName)}`, + name.querySelector("a")?.getAttribute("href"), + surface === "Browser" ? "/browser?bucket=test-bucket" : "/custom-buckets/test-bucket", ) - const replace = async (response: unknown) => { - const index = mounted.requests.length - await mounted.refresh() - await mounted.resolve(index, response) - assert.ok( - mounted.container.querySelector('[data-metric="Name"] [role="status"]') === liveStatus, - "loading and progress disappearance must not replace the live span", - ) - } - const first = sample(7, 71) - await replace(first) - assert.equal(liveStatus.textContent, "", "restored content is deferred after the empty node is registered") - await mounted.flushAnnouncements() - const firstAnnouncement = liveStatus.textContent - assert.match(firstAnnouncement, /Object Count: 7 scanned/) - assert.match(firstAnnouncement, /Size: 71.0 B scanned/) - await replace(idle) - assert.equal(liveStatus.textContent, firstAnnouncement, "clearing also happens in the next task") - await mounted.flushAnnouncements() - assert.equal(liveStatus.textContent, "") - assert.match(mounted.container.querySelector('[data-metric="Name"] time')!.textContent, /Last complete scan:.*2023/) - assert.doesNotMatch(mounted.container.textContent, /Scan in progress|Scanned usage is not the bucket total/) + const link = name.querySelector("a") + const requestIndex = mounted.requests.length + await mounted.refresh() + await mounted.resolve(requestIndex, info) + assert.equal(name.querySelector("a"), link) + }) - await replace(first) - assert.equal(liveStatus.textContent, "") - await mounted.flushAnnouncements() - assert.equal(liveStatus.textContent, firstAnnouncement, "the same sample can announce after a real clear") - await replace(sample(9, 91)) - await replace(sample(11, 111)) - assert.equal(liveStatus.textContent, firstAnnouncement, "pending writes remain deferred across rapid responses") - await mounted.flushAnnouncements() - assert.match(liveStatus.textContent, /Object Count: 11 scanned/) - assert.match(liveStatus.textContent, /Size: 111.0 B scanned/) - assert.doesNotMatch(liveStatus.textContent, /Object Count: (7|9) scanned/) + test(`${surface} renders missing bucket statistics as placeholders`, async (t) => { + const mounted = await mountBrowser(t, { surface }) + const info = { policy, buckets: [{ name: "test-bucket" }] } + await mounted.resolve(0, info) + if (surface === "Browser") await mounted.resolve(1, info) - await replace(sample(13, 131)) - await replace(idle) - await mounted.flushAnnouncements() - assert.equal(liveStatus.textContent, "", "removing progress cancels a pending announcement") - assert.deepEqual( - Array.from( - mounted.container.querySelectorAll('[data-metric="Count"] .tabular-nums > span'), - (span) => span.textContent, - ), - ["90"], - ) - assert.deepEqual( - Array.from( - mounted.container.querySelectorAll('[data-metric="SizeBytes"] .tabular-nums > span'), - (span) => span.textContent, - ), - ["900.0 B"], - ) + const count = mounted.container.querySelector('[data-bucket="test-bucket"] [data-metric="Count"]')! + const capacity = mounted.container.querySelector('[data-bucket="test-bucket"] [data-metric="SizeBytes"]')! + + assert.equal(count.textContent, "--") + assert.equal(capacity.textContent, "--") + assert.doesNotMatch(mounted.container.textContent, /Not measured|Unavailable/) }) } diff --git a/tests/lib/bucket-usage-value.test.ts b/tests/lib/bucket-usage-value.test.ts deleted file mode 100644 index 33d19708..00000000 --- a/tests/lib/bucket-usage-value.test.ts +++ /dev/null @@ -1,118 +0,0 @@ -import test from "node:test" -import assert from "node:assert/strict" -import { readFileSync } from "node:fs" -import * as React from "react" -import { renderToStaticMarkup } from "react-dom/server" -import ts from "typescript" - -const moduleUrl = (source: string) => `data:text/javascript,${encodeURIComponent(source)}` -const imports: Record = { - react: import.meta.resolve("react"), - "react/jsx-runtime": import.meta.resolve("react/jsx-runtime"), - "react-i18next": moduleUrl( - `import { createInstance } from "${import.meta.resolve("i18next")}"; const instance = createInstance(); await instance.init({lng:"en", resources:{en:{translation:${readFileSync(new URL("../../i18n/locales/en-US.json", import.meta.url), "utf8")}}}, interpolation:{escapeValue:false,prefix:"{",suffix:"}"}}); export const useTranslation = () => ({t:instance.t.bind(instance)});`, - ), - "@/components/ui/spinner": moduleUrl( - `import React from "${import.meta.resolve("react")}"; export const Spinner = () => React.createElement("span", {role: "status", "aria-label": "Loading"});`, - ), - "@/lib/functions": new URL("../../lib/functions.ts", import.meta.url).href, -} -const source = ts - .transpileModule(readFileSync(new URL("../../components/buckets/usage-value.tsx", import.meta.url), "utf8"), { - compilerOptions: { module: ts.ModuleKind.ESNext, jsx: ts.JsxEmit.ReactJSX }, - }) - .outputText.replace(/from "([^"]+)"/g, (_, specifier: string) => { - assert.ok(imports[specifier], `Unexpected import: ${specifier}`) - return `from "${imports[specifier]}"` - }) -const { BucketUsageValue, BucketUsageStatus, BucketScanNotice } = await import(moduleUrl(source)) -const progress = { - stage: "scanning", - updatedAt: 1800000000000, - objectsCount: 7, - sizeBytes: 71, - sourcesObserved: 1, - sourcesTotal: 2, -} -const render = (props: Record) => - renderToStaticMarkup( - React.createElement( - "div", - null, - React.createElement(BucketUsageValue, { kind: "objects", loading: false, ...props }), - React.createElement(BucketUsageStatus, { bucketName: props.bucketName ?? "bucket", status: props.status }), - React.createElement(BucketScanNotice, { statuses: new Map(props.status ? [["bucket", props.status]] : []) }), - ), - ) - -test("first scan shows observed counts with an explicit incomplete-total explanation", () => { - const html = render({ status: { progress } }) - assert.match(html, /7 scanned/) - assert.match(html, /Scan in progress/) - assert.match(html, /Scanned usage is not the bucket total/) - assert.match(html, /Checkpoint:/) -}) - -test("rescan keeps the complete total and shows progress independently", () => { - const html = render({ value: 90, status: { updatedAt: 1700000000000, progress } }) - assert.match(html, />90<\/span>/) - assert.match(html, /Last complete scan:/) - assert.match(html, /7 scanned/) - assert.doesNotMatch(html, />97<\/span>/) -}) - -test("enumeration cannot render an empty bucket and waiting sources remain explicit", () => { - const html = render({ - status: { progress: { ...progress, stage: "enumerating", objectsCount: undefined, sizeBytes: undefined } }, - }) - assert.match(html, /Enumerating objects/) - assert.doesNotMatch(html, /0 scanned/) - assert.match( - render({ status: { progress: { ...progress, stage: "awaiting_sources" } } }), - /Waiting for scanner sources/, - ) -}) - -test("loading, missing measurement, failed coverage and confirmed empty usage stay distinct", () => { - assert.match(render({ loading: true }), /aria-label="Loading"/) - assert.match(render({ unmeasured: true }), /Not measured/) - assert.match(render({}), /Unavailable/) - assert.match(render({ value: 0 }), />0<\/span>/) -}) - -test("capacity and completed traversal stay diagnostic and announce each bucket once", () => { - const status = { progress: { ...progress, stage: "completed", sizeBytes: 1024, sourcesObserved: 2 } } - const size = render({ bucketName: "bucket", kind: "size", status }) - assert.match(size, /1.0 KiB scanned/) - assert.match(size, /Traversal complete/) - assert.match(size, /Scanned usage is not the bucket total/) - assert.equal(size.match(/aria-live/g)?.length, 1) - const count = render({ bucketName: "bucket", status }) - assert.match(count, /aria-live="polite"/) - assert.doesNotMatch(count, /aria-label/) -}) - -test("server rendering registers one empty live span before any announcement content", () => { - for (const status of [ - undefined, - { updatedAt: 1700000000000 }, - { progress }, - { updatedAt: 1700000000000, progress }, - { progress: { ...progress, stage: "enumerating", objectsCount: undefined, sizeBytes: undefined } }, - ]) { - const html = renderToStaticMarkup(React.createElement(BucketUsageStatus, { bucketName: "bucket", status })) - const live = html.match(/]*role="status"[^>]*>(.*?)<\/span>/s) - assert.equal(live?.[1], "", "the live span starts empty even when a scan sample already exists") - assert.match(live![0], /class="sr-only"/) - assert.match(live![0], /aria-live="polite"/) - assert.match(live![0], /aria-atomic="true"/) - assert.doesNotMatch(live![0], /aria-label/) - assert.equal(html.match(/role="status"/g)?.length, 1) - } -}) - -test("complete measurement and checkpoint retain their separate date values", () => { - const html = render({ value: 90, status: { updatedAt: 1700000000000, progress } }) - assert.match(html, /Last complete scan: [^<]*2023/) - assert.match(html, /Checkpoint: [^<]*2027/) -})