fix(reference): show the result count only for a settled list (08-09)

The count status said "checking results" next to a failure alert, and the
sample judged the state from `data` instead of `state.base`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-26 01:06:43 +09:00
co-authored by Claude Opus 5.5
parent dbe6b769bf
commit 9d61eacdc7
3 changed files with 46 additions and 8 deletions
@@ -14,7 +14,6 @@ export const REFERENCE_MESSAGE_CATALOGS = Object.freeze({
"reference.list.create": "새 항목 만들기",
"reference.list.refresh": "새로고침",
"reference.list.resultCount": "총 {count}개 항목",
"reference.list.resultPending": "결과 확인 중",
"reference.form.back": "목록으로 돌아가기",
"reference.form.title": "Reference resource 만들기",
"reference.form.description":
@@ -60,7 +59,6 @@ export const REFERENCE_MESSAGE_CATALOGS = Object.freeze({
"reference.list.create": "Create item",
"reference.list.refresh": "Refresh",
"reference.list.resultCount": "Total items: {count}",
"reference.list.resultPending": "Checking results",
"reference.form.back": "Back to the list",
"reference.form.title": "Create a reference resource",
"reference.form.description":
@@ -44,13 +44,14 @@ export default function ReferenceResourcePage() {
</Button>
}
resultCount={
query.data
? // Feature keys carry no parameter types, so the count goes
// through the untyped resolver.
resolveMessage(locale, "reference.list.resultCount", {
count: query.data.length,
// 08-09. Counted only from a settled result: a loading, idle or
// failed list has nothing to count. Feature keys carry no parameter
// types, so the count goes through the untyped resolver.
query.state.base === "success" || query.state.base === "empty"
? resolveMessage(locale, "reference.list.resultCount", {
count: query.data?.length ?? 0,
})
: message("reference.list.resultPending")
: null
}
>
<AsyncSurface
@@ -208,6 +208,45 @@ describe("reference feature page states", () => {
expect(listResources).not.toHaveBeenCalled();
});
// 08-09. The count is a status only once there is a result to count.
it("shows the result count only for a loaded list", async () => {
const resultCount = () =>
document.querySelector(".collection-page__result-count");
let resolveList:
| ((result: ReferenceResult<readonly ReferenceResourceView[]>) => void)
| undefined;
const loading = renderReference(
inputWith({
listResources: () =>
new Promise((resolve) => {
resolveList = resolve;
}),
}),
);
expect(await screen.findByLabelText("불러오는 중")).toBeVisible();
expect(resultCount()).toBeNull();
resolveList?.({
ok: true,
value: [{ resourceId: "reference-1", title: "Loaded", createdAt: null }],
});
expect(await screen.findByText("Loaded")).toBeVisible();
expect(resultCount()).toHaveTextContent("총 1개 항목");
loading.unmount();
renderReference(
inputWith({
listResources: async () => ({
ok: false,
error: createFailure("SERVER_FAILURE", "LIST_REFERENCE_RESOURCES", 0),
}),
}),
);
expect(await screen.findByRole("alert")).toHaveTextContent(
"요청을 완료하지 못했습니다.",
);
expect(resultCount()).toBeNull();
});
it("renders backend forbidden even when the client access hint allowed entry", async () => {
const user = userEvent.setup();
renderReference(