diff --git a/openspec/changes/uppercase-company-codes/tasks.md b/openspec/changes/uppercase-company-codes/tasks.md
index ab94df9..a2b5d6f 100644
--- a/openspec/changes/uppercase-company-codes/tasks.md
+++ b/openspec/changes/uppercase-company-codes/tasks.md
@@ -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/**`
diff --git a/solvway-admin-portal/app/companies/page.fixes.test.tsx b/solvway-admin-portal/app/companies/page.fixes.test.tsx
index 554e350..7fc7e75 100644
--- a/solvway-admin-portal/app/companies/page.fixes.test.tsx
+++ b/solvway-admin-portal/app/companies/page.fixes.test.tsx
@@ -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();
diff --git a/solvway-admin-portal/app/companies/page.tsx b/solvway-admin-portal/app/companies/page.tsx
index 70b7d3c..01564d8 100644
--- a/solvway-admin-portal/app/companies/page.tsx
+++ b/solvway-admin-portal/app/companies/page.tsx
@@ -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
{t("CompChangeCodeWarning")}
- setNewCode(e.target.value)} disabled={saving} />
+ setNewCode(e.target.value)} disabled={saving} />
>
) : (
@@ -86,7 +86,7 @@ function CompanyDialog({ state, onClose, onSaved }: { state: DialogState; onClos
{!form.id && (
- setForm((f) => ({ ...f, code: e.target.value }))} disabled={saving} />
+ setForm((f) => ({ ...f, code: e.target.value }))} disabled={saving} />
)}
diff --git a/solvway-admin-portal/app/companies/page.uppercase.test.tsx b/solvway-admin-portal/app/companies/page.uppercase.test.tsx
new file mode 100644
index 0000000..11dbe74
--- /dev/null
+++ b/solvway-admin-portal/app/companies/page.uppercase.test.tsx
@@ -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()).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();
+ 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");
+ });
+});