feat: add copy functionality for phone and Telegram username in ContactLinks component
- Implemented copy buttons for phone number and Telegram username in the ContactLinks component, enhancing user interaction. - Integrated tooltip feedback to indicate successful copy actions. - Updated tests to cover new copy functionality and ensure proper rendering of copy buttons based on props. - Added localization support for new copy-related strings in the i18n messages.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import { describe, it, expect, beforeEach, vi } from "vitest";
|
||||
import { render, screen, fireEvent } from "@testing-library/react";
|
||||
import { CurrentDutyView } from "./CurrentDutyView";
|
||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { resetAppStore } from "@/test/test-utils";
|
||||
|
||||
vi.mock("@/hooks/use-telegram-auth", () => ({
|
||||
@@ -148,4 +149,37 @@ describe("CurrentDutyView", () => {
|
||||
expect(onBack).toHaveBeenCalled();
|
||||
vi.mocked(fetchDuties).mockResolvedValue([]);
|
||||
});
|
||||
|
||||
it("shows copy phone and copy Telegram buttons when duty has contacts", 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() + 60 * 60 * 1000);
|
||||
const dutyWithContacts = {
|
||||
id: 1,
|
||||
user_id: 1,
|
||||
start_at: start.toISOString(),
|
||||
end_at: end.toISOString(),
|
||||
event_type: "duty" as const,
|
||||
full_name: "Test User",
|
||||
phone: "+79991234567",
|
||||
username: "testuser",
|
||||
};
|
||||
vi.mocked(fetchDuties).mockResolvedValue([dutyWithContacts]);
|
||||
render(
|
||||
<TooltipProvider>
|
||||
<CurrentDutyView onBack={vi.fn()} />
|
||||
</TooltipProvider>
|
||||
);
|
||||
await screen.findByText("Test User", {}, { timeout: 3000 });
|
||||
expect(
|
||||
screen.getByRole("button", { name: /Copy phone number|Скопировать номер/i })
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("button", {
|
||||
name: /Copy Telegram username|Скопировать логин Telegram/i,
|
||||
})
|
||||
).toBeInTheDocument();
|
||||
vi.mocked(fetchDuties).mockResolvedValue([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user