- Replaced the previous webapp with a new Mini App built using Next.js, improving performance and maintainability. - Updated the `.gitignore` to exclude Next.js build artifacts and node modules. - Revised documentation in `AGENTS.md`, `README.md`, and `architecture.md` to reflect the new Mini App structure and technology stack. - Enhanced Dockerfile to support the new build process for the Next.js application. - Updated CI workflow to build and test the Next.js application. - Added new configuration options for the Mini App, including `MINI_APP_SHORT_NAME` for improved deep linking. - Refactored frontend testing setup to accommodate the new structure and testing framework. - Removed legacy webapp files and dependencies to streamline the project.
85 lines
3.2 KiB
TypeScript
85 lines
3.2 KiB
TypeScript
/**
|
|
* Unit tests for CurrentDutyView: no-duty message, duty card with contacts.
|
|
* Ported from webapp/js/currentDuty.test.js renderCurrentDutyContent / showCurrentDutyView.
|
|
*/
|
|
|
|
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
import { render, screen, fireEvent } from "@testing-library/react";
|
|
import { CurrentDutyView } from "./CurrentDutyView";
|
|
import { resetAppStore } from "@/test/test-utils";
|
|
|
|
vi.mock("@/hooks/use-telegram-auth", () => ({
|
|
useTelegramAuth: () => ({
|
|
initDataRaw: "test-init",
|
|
startParam: undefined,
|
|
isLocalhost: true,
|
|
}),
|
|
}));
|
|
|
|
vi.mock("@/lib/api", () => ({
|
|
fetchDuties: vi.fn().mockResolvedValue([]),
|
|
AccessDeniedError: class AccessDeniedError extends Error {
|
|
serverDetail?: string;
|
|
constructor(m: string, d?: string) {
|
|
super(m);
|
|
this.serverDetail = d;
|
|
}
|
|
},
|
|
}));
|
|
|
|
describe("CurrentDutyView", () => {
|
|
beforeEach(() => {
|
|
resetAppStore();
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("shows loading then no-duty message when no active duty", async () => {
|
|
const onBack = vi.fn();
|
|
render(<CurrentDutyView onBack={onBack} />);
|
|
await screen.findByText(/No one is on duty|Сейчас никто не дежурит/i, {}, { timeout: 3000 });
|
|
expect(screen.getByText(/Back to calendar|Назад к календарю/i)).toBeInTheDocument();
|
|
});
|
|
|
|
it("back button calls onBack when clicked", async () => {
|
|
const onBack = vi.fn();
|
|
render(<CurrentDutyView onBack={onBack} />);
|
|
await screen.findByText(/No one is on duty|Сейчас никто не дежурит/i, {}, { timeout: 3000 });
|
|
const buttons = screen.getAllByRole("button", { name: /Back to calendar|Назад к календарю/i });
|
|
fireEvent.click(buttons[buttons.length - 1]);
|
|
expect(onBack).toHaveBeenCalled();
|
|
});
|
|
|
|
it("shows Close button when openedFromPin is true", async () => {
|
|
const onBack = vi.fn();
|
|
render(<CurrentDutyView onBack={onBack} openedFromPin={true} />);
|
|
await screen.findByText(/No one is on duty|Сейчас никто не дежурит/i, {}, { timeout: 3000 });
|
|
expect(screen.getByRole("button", { name: /Close|Закрыть/i })).toBeInTheDocument();
|
|
expect(screen.queryByText(/Back to calendar|Назад к календарю/i)).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("shows contact info not set when duty has no phone or username", async () => {
|
|
const { fetchDuties } = await import("@/lib/api");
|
|
const now = new Date();
|
|
const start = new Date(now.getTime() - 60 * 60 * 1000); // 1 hour ago
|
|
const end = new Date(now.getTime() + 60 * 60 * 1000); // 1 hour from now
|
|
const dutyNoContacts = {
|
|
id: 1,
|
|
user_id: 1,
|
|
start_at: start.toISOString(),
|
|
end_at: end.toISOString(),
|
|
event_type: "duty" as const,
|
|
full_name: "Test User",
|
|
phone: null,
|
|
username: null,
|
|
};
|
|
vi.mocked(fetchDuties).mockResolvedValue([dutyNoContacts]);
|
|
const onBack = vi.fn();
|
|
render(<CurrentDutyView onBack={onBack} />);
|
|
await screen.findByText("Test User", {}, { timeout: 3000 });
|
|
expect(
|
|
screen.getByText(/Contact info not set|Контактные данные не указаны/i)
|
|
).toBeInTheDocument();
|
|
vi.mocked(fetchDuties).mockResolvedValue([]);
|
|
});
|
|
});
|