Files
rustfs-console/tests/lib/object-list-source.test.js

109 lines
5.1 KiB
JavaScript

import test from "node:test"
import assert from "node:assert/strict"
import fs from "node:fs"
test("object list normalizes LastModified through the safe date helper", () => {
const source = fs.readFileSync("components/object/list.tsx", "utf8")
assert.equal(source.includes('import { normalizeDateToIso } from "@/lib/safe-date"'), true)
assert.equal(source.includes("LastModified: normalizeDateToIso(item.LastModified)"), true)
assert.equal(source.includes('item.LastModified ? item.LastModified.toISOString() : ""'), false)
})
test("object list distinguishes access errors from a confirmed empty bucket", () => {
const source = fs.readFileSync("components/object/list.tsx", "utf8")
assert.equal(source.includes('console.error("Failed to fetch objects:", error)'), true)
assert.equal(source.includes('message.error((error as Error)?.message ?? t("Failed to load objects"))'), true)
assert.equal(source.includes("setData([])"), true)
assert.equal(source.includes('setListError(isAccessDeniedError(error) ? "accessDenied" : "loadFailed")'), true)
assert.equal(source.includes('listError === "accessDenied"'), true)
assert.equal(source.includes('t("Access Denied")'), true)
assert.equal(source.includes("{!listError ? ("), true)
})
test("object list lazy loads additional object batches instead of showing a paginator", () => {
const source = fs.readFileSync("components/object/list.tsx", "utf8")
assert.match(source, /useObjectListPagination\(\{ loadMoreRef, nextToken, loading, loadMoreError, loadNextBatch \}\)/)
assert.equal(source.includes("setData((currentRows) => [...currentRows, ...rows])"), true)
assert.equal(source.includes('t("Rows per page")'), false)
assert.equal(source.includes('t("Previous Page")'), false)
assert.equal(source.includes('t("Next Page")'), false)
})
test("object list persists its batch size and virtualizes loaded rows", () => {
const source = fs.readFileSync("components/object/list.tsx", "utf8")
assert.match(source, /OBJECT_LIST_PAGE_SIZE_STORAGE_KEY = "object-list-page-size"/)
assert.match(source, /useLocalStorage<unknown>\(\s+OBJECT_LIST_PAGE_SIZE_STORAGE_KEY/)
assert.match(source, /OBJECT_LIST_PAGE_SIZE_OPTIONS\.map/)
assert.match(source, /virtualizeRows/)
assert.match(source, /aria-labelledby="object-list-page-size-label"/)
})
test("last modified sorting discloses partial results and keeps continuation visible", () => {
const source = fs.readFileSync("components/object/list.tsx", "utf8")
assert.match(source, /\{nextToken \? \(\s+<span[^>]*>\{t\("Loaded objects only"\)\}/)
assert.match(
source,
/\{data\.length > 0 \|\| nextToken \? \(\s+<div[\s\S]*?ref=\{loadMoreRef\}[\s\S]*?<Button[\s\S]*?onClick=\{loadNextBatch\}/,
)
assert.equal(source.includes('t("Load next objects")'), true)
assert.equal(source.includes('t("All objects loaded")'), true)
assert.match(source, /if \(shouldAppend\) \{\s+setLoadMoreError\(true\)\s+\} else \{\s+message\.error/)
assert.equal(source.includes('role={loadMoreError ? "alert" : undefined}'), true)
assert.match(source, /onClick=\{loadNextBatch\}[\s\S]*?\{loadMoreError[\s\S]*?t\("Retry"\)/)
})
test("object list distinguishes filtered-empty states from an empty bucket", () => {
const source = fs.readFileSync("components/object/list.tsx", "utf8")
assert.equal(source.includes("resolveObjectListDisplayState"), true)
assert.equal(source.includes('displayState === "filtered-partial"'), true)
assert.equal(source.includes('displayState === "filtered-loading"'), true)
assert.equal(source.includes("emptyTitle={emptyTitle}"), true)
assert.equal(source.includes("emptyDescription={emptyDescription}"), true)
})
test("object list clears its search when the active bucket or prefix changes", () => {
const source = fs.readFileSync("components/object/list.tsx", "utf8")
assert.match(source, /if \(shouldResetObjectListSearch\(previousScope, listScope\)\) \{\s+setSearchTerm\(""\)\s+\}/)
})
test("object list shows fixed scroll shortcut buttons only when content overflows", () => {
const source = fs.readFileSync("components/object/list.tsx", "utf8")
assert.equal(source.includes("RiArrowUpSLine"), true)
assert.equal(source.includes("RiArrowDownSLine"), true)
assert.equal(
source.includes("setShowScrollShortcuts(document.documentElement.scrollHeight > window.innerHeight)"),
true,
)
assert.equal(source.includes('window.scrollTo({ top: 0, left: 0, behavior: "auto" })'), true)
assert.equal(
source.includes('window.scrollTo({ top: document.documentElement.scrollHeight, left: 0, behavior: "auto" })'),
true,
)
})
test("object download delegates the signed URL to the browser", () => {
for (const path of [
"components/object/list.tsx",
"components/object/info.tsx",
"components/object/view.tsx",
"components/object/versions.tsx",
]) {
const source = fs.readFileSync(path, "utf8")
assert.match(source, /downloadUrl\(url, filename\)/, path)
assert.doesNotMatch(source, /await fetch\(url\)/, path)
assert.doesNotMatch(source, /await response\.blob\(\)/, path)
}
const listSource = fs.readFileSync("components/object/list.tsx", "utf8")
assert.match(listSource, /finally \{\s+loadingMsg\.destroy\(\)/)
})