feat: enhance admin and contact components with new functionality

- Updated `AdminPage` to conditionally display duty reassignment instructions based on visible groups, improving user guidance.
- Refactored `AdminDutyList` to streamline the display of duties, enhancing visual clarity and organization.
- Introduced `openPhoneLink` and `triggerHapticLight` functions in `ContactLinks` for improved phone link interaction and haptic feedback.
- Added unit tests for `openPhoneLink` to ensure correct functionality and handling of various phone number formats.
- Enhanced existing tests for `ContactLinks` to verify new phone link behavior, ensuring robust testing coverage.
This commit is contained in:
2026-03-06 13:26:04 +03:00
parent 02a586a1c5
commit 6da6c87d3c
6 changed files with 148 additions and 18 deletions

View File

@@ -3,14 +3,26 @@
* Ported from webapp/js/contactHtml.test.js buildContactLinksHtml.
*/
import { describe, it, expect, beforeEach } from "vitest";
import { render, screen } from "@testing-library/react";
import { describe, it, expect, beforeEach, vi } from "vitest";
import { render, screen, fireEvent } from "@testing-library/react";
import { ContactLinks } from "./ContactLinks";
import { resetAppStore } from "@/test/test-utils";
const openPhoneLinkMock = vi.fn();
const triggerHapticLightMock = vi.fn();
vi.mock("@/lib/open-phone-link", () => ({
openPhoneLink: (...args: unknown[]) => openPhoneLinkMock(...args),
}));
vi.mock("@/lib/telegram-haptic", () => ({
triggerHapticLight: () => triggerHapticLightMock(),
}));
describe("ContactLinks", () => {
beforeEach(() => {
resetAppStore();
openPhoneLinkMock.mockClear();
triggerHapticLightMock.mockClear();
});
it("returns null when phone and username are missing", () => {
@@ -57,4 +69,17 @@ describe("ContactLinks", () => {
expect(link).toBeInTheDocument();
expect(link?.textContent).toContain("@alice");
});
it("calls openPhoneLink and triggerHapticLight when phone link is clicked", () => {
render(
<ContactLinks phone="+79991234567" username={null} showLabels={false} />
);
const telLink = document.querySelector<HTMLAnchorElement>('a[href^="tel:"]');
expect(telLink).toBeInTheDocument();
fireEvent.click(telLink!);
expect(openPhoneLinkMock).toHaveBeenCalledWith("+79991234567");
expect(triggerHapticLightMock).toHaveBeenCalled();
});
});