feat: companies screen shows codes in capitals and allows case-only renames

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-01 16:22:03 +08:00
1 parent 41c616b3f6
commit 5e5762cdcb
4 files changed
+60 -6

No files matched your search

@@ -19,7 +19,7 @@ Serial. One implementer, in this session.
## 3. Portal
- [ ] 3.1 Companies: code inputs show capitals as typed and the rename compares case-sensitively, so `cv` to `CV` is a change.
- [x] 3.1 Companies: code inputs show capitals as typed and the rename compares case-sensitively, so `cv` to `CV` is a change.
- Depends on: 2.1
- Tests first: typing `cv` shows `CV`; renaming `cv` to `CV` sends the request.
- Scope: `solvway-admin-portal/app/**`
@@ -13,7 +13,7 @@ vi.mock("@/app/lib/AdminAuthContext", () => ({ useAdminAuth: mocks.useAdminAuth
import CompaniesPage from "./page";
beforeEach(() => {
mocks.apiGet.mockReset().mockResolvedValue([{ id: 1, name: "Insight", code: "ins", status: "A" }]);
mocks.apiGet.mockReset().mockResolvedValue([{ id: 1, name: "Insight", code: "INS", status: "A" }]);
mocks.apiPost.mockReset();
mocks.useAdminAuth.mockReset().mockReturnValue({ loading: false, isSuper: true });
});
@@ -24,7 +24,7 @@ describe("CompaniesPage fixes", () => {
await userEvent.click(await screen.findByRole("button", { name: "Change code" }));
const input = screen.getByLabelText("New code");
await userEvent.clear(input);
await userEvent.type(input, " INS ");
await userEvent.type(input, " ins ");
await userEvent.click(screen.getByRole("button", { name: "Confirm" }));
expect(mocks.apiPost).not.toHaveBeenCalled();
expect(screen.getByRole("alert")).toBeInTheDocument();
+3 -3
View File
@@ -39,7 +39,7 @@ function CompanyDialog({ state, onClose, onSaved }: { state: DialogState; onClos
if ((mode === "code" ? newCode : form.code).trim() === "" && (mode === "code" || !form.id)) {
return setError(t("CompCodeRequired"));
}
if (mode === "code" && newCode.trim().toLowerCase() === company.code.toLowerCase()) {
if (mode === "code" && newCode.trim().toUpperCase() === company.code) {
return setError(t("CompCodeUnchanged"));
}
setError(null);
@@ -74,7 +74,7 @@ function CompanyDialog({ state, onClose, onSaved }: { state: DialogState; onClos
<p className="text-sm">{t("CompChangeCodeWarning")}</p>
<div className="space-y-1.5">
<Label htmlFor="company-new-code">{t("CompNewCode")}</Label>
<Input id="company-new-code" value={newCode} onChange={(e) => setNewCode(e.target.value)} disabled={saving} />
<Input id="company-new-code" className="uppercase" value={newCode} onChange={(e) => setNewCode(e.target.value)} disabled={saving} />
</div>
</>
) : (
@@ -86,7 +86,7 @@ function CompanyDialog({ state, onClose, onSaved }: { state: DialogState; onClos
{!form.id && (
<div className="space-y-1.5">
<Label htmlFor="company-code">{t("Code")}</Label>
<Input id="company-code" value={form.code} onChange={(e) => setForm((f) => ({ ...f, code: e.target.value }))} disabled={saving} />
<Input id="company-code" className="uppercase" value={form.code} onChange={(e) => setForm((f) => ({ ...f, code: e.target.value }))} disabled={saving} />
</div>
)}
<div className="space-y-1.5">
@@ -0,0 +1,54 @@
import { render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, it, expect, vi, beforeEach } from "vitest";
const mocks = vi.hoisted(() => ({ apiGet: vi.fn(), apiPost: vi.fn(), useAdminAuth: vi.fn() }));
vi.mock("@/app/lib/clientApi", async (importOriginal) => ({
ApiError: (await importOriginal<typeof import("@/app/lib/clientApi")>()).ApiError,
apiGet: mocks.apiGet,
apiPost: mocks.apiPost,
}));
vi.mock("@/app/lib/AdminAuthContext", () => ({ useAdminAuth: mocks.useAdminAuth }));
import CompaniesPage from "./page";
beforeEach(() => {
mocks.apiGet.mockReset().mockResolvedValue([{ id: 2, name: "Clever", code: "cv", status: "A" }]);
mocks.apiPost.mockReset().mockResolvedValue({ id: 2, code: "CV" });
mocks.useAdminAuth.mockReset().mockReturnValue({ loading: false, isSuper: true });
});
async function openChangeCode() {
render(<CompaniesPage />);
const row = (await screen.findByText("Clever")).closest("tr")!;
await userEvent.click(within(row).getByRole("button", { name: /change code/i }));
return screen.getByLabelText("New code");
}
describe("CompaniesPage company codes in capitals", () => {
it("treats a change of case as a change and posts it", async () => {
const code = await openChangeCode();
await userEvent.clear(code);
await userEvent.type(code, "CV");
await userEvent.click(screen.getByRole("button", { name: /confirm/i }));
await waitFor(() => expect(mocks.apiPost).toHaveBeenCalledWith("/api/companies/2/code", { code: "CV" }));
});
it("still refuses the same code typed in any case", async () => {
mocks.apiGet.mockResolvedValue([{ id: 2, name: "Clever", code: "CV", status: "A" }]);
const code = await openChangeCode();
await userEvent.clear(code);
await userEvent.type(code, "cv");
await userEvent.click(screen.getByRole("button", { name: /confirm/i }));
expect(await screen.findByRole("alert")).toBeInTheDocument();
expect(mocks.apiPost).not.toHaveBeenCalled();
});
it("shows code inputs in capitals", async () => {
const code = await openChangeCode();
expect(code).toHaveClass("uppercase");
await userEvent.keyboard("{Escape}");
await userEvent.click(screen.getByRole("button", { name: /add company/i }));
expect(screen.getByLabelText("Code")).toHaveClass("uppercase");
});
});