Files
co-lite/solvway-admin-portal/app/bulletins/page.sorting.test.tsx
T
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
Backend modules from tastefully 8bd93d15: core-libs, core-session,
api-gateway, mobile-api, services-auth, services-system,
services-counter, services-member, services-log, services-email.
solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal
from tastefully 8bd93d15. Copied as tracked files only.

Literal secrets replaced with environment placeholders:
- services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY,
  MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default)
- services-system: JUMIO_TOKEN, JUMIO_SECRET (optional)
- services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed
- core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default
  removed, ipgeolocation key read from IPGEOLOCATION_API_KEY
- services-system EkycAppConfig: commented Jumio credentials removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-26 15:55:45 +08:00

57 lines
2.4 KiB
TypeScript

import { render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, it, expect, vi, beforeEach } from "vitest";
import { memoryRouter } from "@/test/memoryRouter";
vi.mock("next/navigation", async () => (await import("@/test/memoryRouter")).navigationMock);
const auth = vi.hoisted(() => ({ hasModule: vi.fn(() => true), loading: false }));
vi.mock("@/app/lib/AdminAuthContext", () => ({ useAdminAuth: () => ({ hasModule: auth.hasModule, loading: auth.loading }) }));
vi.mock("@/app/lib/services/bulletins", () => ({
listBulletins: vi.fn(),
getBulletin: vi.fn(),
saveBulletin: vi.fn(),
uploadBulletinImage: vi.fn(),
AREA_OPTIONS: [{ value: "A", label: "Admin" }],
}));
import { listBulletins } from "@/app/lib/services/bulletins";
import BulletinsPage from "./page";
const row = {
id: 1, title: "Holiday notice", content: "", dateFrom: "2026-01-01T00:00:00", dateTo: "2026-01-31T00:00:00",
status: "Y", type: "B", areaList: ["A"], countryPrefix: ["60"],
};
beforeEach(() => {
memoryRouter.reset("/bulletins");
auth.hasModule.mockReturnValue(true);
vi.mocked(listBulletins).mockReset().mockResolvedValue({ items: [row], total: 100 } as never);
});
describe("Bulletins — server-side header sorting", () => {
it.each([
["Title", "title"],
["Type", "type"],
["Status", "status"],
])("%s header sorts by %s asc then desc, from page 1", async (header, key) => {
memoryRouter.reset("/bulletins", "page=2");
const user = userEvent.setup();
render(<BulletinsPage />);
await screen.findByText("Holiday notice");
vi.mocked(listBulletins).mockClear();
await user.click(screen.getByRole("button", { name: header }));
await waitFor(() => expect(listBulletins).toHaveBeenLastCalledWith(expect.objectContaining({ sortBy: key, sortDir: "asc", page: 1 })));
expect(memoryRouter.getSearch().get("sortBy")).toBe(key);
expect(memoryRouter.getSearch().has("page")).toBe(false);
await user.click(screen.getByRole("button", { name: header }));
await waitFor(() => expect(listBulletins).toHaveBeenLastCalledWith(expect.objectContaining({ sortBy: key, sortDir: "desc" })));
});
it("the action column has no sort button", async () => {
render(<BulletinsPage />);
await screen.findByText("Holiday notice");
const headers = screen.getAllByRole("columnheader");
expect(within(headers[headers.length - 1]).queryByRole("button")).toBeNull();
});
});