feat: enhance CurrentDutyView with new functionality and improved tests
- Added a button to open the calendar in the no-duty view, triggering the onBack function. - Implemented tests for the new button functionality and error handling in the CurrentDutyView component. - Updated localization messages to include the new "Open calendar" label in both English and Russian. - Refactored layout and styling for better user experience and accessibility.
This commit is contained in:
@@ -57,6 +57,18 @@ describe("CurrentDutyView", () => {
|
||||
expect(screen.queryByText(/Back to calendar|Назад к календарю/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows Open calendar button in no-duty view and it calls onBack", async () => {
|
||||
const onBack = vi.fn();
|
||||
render(<CurrentDutyView onBack={onBack} />);
|
||||
await screen.findByText(/No one is on duty|Сейчас никто не дежурит/i, {}, { timeout: 3000 });
|
||||
const openCalendarBtn = screen.getByRole("button", {
|
||||
name: /Open calendar|Открыть календарь/i,
|
||||
});
|
||||
expect(openCalendarBtn).toBeInTheDocument();
|
||||
fireEvent.click(openCalendarBtn);
|
||||
expect(onBack).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("shows contact info not set when duty has no phone or username", async () => {
|
||||
const { fetchDuties } = await import("@/lib/api");
|
||||
const now = new Date();
|
||||
@@ -81,4 +93,38 @@ describe("CurrentDutyView", () => {
|
||||
).toBeInTheDocument();
|
||||
vi.mocked(fetchDuties).mockResolvedValue([]);
|
||||
});
|
||||
|
||||
it("shows ends_at line when duty is active", async () => {
|
||||
const { fetchDuties } = await import("@/lib/api");
|
||||
const now = new Date();
|
||||
const start = new Date(now.getTime() - 60 * 60 * 1000);
|
||||
const end = new Date(now.getTime() + 2 * 60 * 60 * 1000);
|
||||
const duty = {
|
||||
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([duty]);
|
||||
render(<CurrentDutyView onBack={vi.fn()} />);
|
||||
await screen.findByText("Test User", {}, { timeout: 3000 });
|
||||
expect(
|
||||
screen.getByText(/Until end of shift at|До конца смены в/i)
|
||||
).toBeInTheDocument();
|
||||
vi.mocked(fetchDuties).mockResolvedValue([]);
|
||||
});
|
||||
|
||||
it("error state shows Retry as first button", async () => {
|
||||
const { fetchDuties } = await import("@/lib/api");
|
||||
vi.mocked(fetchDuties).mockRejectedValue(new Error("Network error"));
|
||||
render(<CurrentDutyView onBack={vi.fn()} />);
|
||||
await screen.findByText(/Could not load|Не удалось загрузить/i, {}, { timeout: 3000 });
|
||||
const buttons = screen.getAllByRole("button");
|
||||
expect(buttons[0]).toHaveAccessibleName(/Retry|Повторить/i);
|
||||
vi.mocked(fetchDuties).mockResolvedValue([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user