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:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user