- post form: up to 3 verification questions (loss and found) and a "how not to get scammed" note; sent as verificationQuestions JSON - feed card: "I found it" / "It's mine" instead of "Write" for posts with questions; phone shows "after check" until the author approves - chat draft shows ClaimForm; VerificationPanel lets the author approve or reject answers and locks the claimant's input until approval, then offers the author's phone - messages: claim answers card, verification system line, fraudSignal warnings for the recipient; ChatSafetyNotice with new-account mark - tests, README Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
96 lines
4.5 KiB
JavaScript
96 lines
4.5 KiB
JavaScript
/**
|
||
* Номер в карточке: в ленту он не приходит, открывается кнопкой
|
||
* «Показать номер» (proof-of-work на бэкенде). Автор и админ видят номер сразу.
|
||
*/
|
||
import { render, screen, fireEvent } from "@testing-library/react";
|
||
import PostOnFeed from "./PostOnFeed";
|
||
import { useAuthContext } from "../context/AuthContext";
|
||
import { revealPhone } from "../api/phoneApi";
|
||
import "../i18n";
|
||
|
||
jest.mock("../context/AuthContext", () => ({ useAuthContext: jest.fn() }));
|
||
jest.mock("../hooks/useContactSeller", () => ({
|
||
useContactSeller: () => ({ contactSeller: jest.fn(), error: "", clearError: jest.fn() }),
|
||
}));
|
||
jest.mock("../api/phoneApi", () => ({ revealPhone: jest.fn() }));
|
||
|
||
const AD = { id: 7, userId: 2, title: "Ключи", type: "loss", status: "ACTIVE", images: [] };
|
||
const SHOW = /Показать номер|Show number/;
|
||
|
||
beforeEach(() => {
|
||
useAuthContext.mockReturnValue({ isAuthenticated: false, user: null });
|
||
});
|
||
|
||
test("номер открывается по кнопке", async () => {
|
||
revealPhone.mockResolvedValue("+7 (999) 111-22-33");
|
||
render(<PostOnFeed ad={{ ...AD, phoneVisible: true }} />);
|
||
|
||
fireEvent.click(screen.getByText(SHOW));
|
||
|
||
expect(await screen.findByText("+7 (999) 111-22-33")).toBeTruthy();
|
||
expect(revealPhone).toHaveBeenCalledWith(7, expect.anything());
|
||
});
|
||
|
||
test("без согласия автора кнопки нет — только чат", () => {
|
||
render(<PostOnFeed ad={{ ...AD, phoneVisible: false }} />);
|
||
|
||
expect(screen.queryByText(SHOW)).toBeNull();
|
||
});
|
||
|
||
test("у закрытого объявления номер не предлагается", () => {
|
||
render(<PostOnFeed ad={{ ...AD, phoneVisible: true, status: "CLOSED" }} />);
|
||
|
||
expect(screen.queryByText(SHOW)).toBeNull();
|
||
});
|
||
|
||
test("номер, пришедший с объявлением (автор, админ), показывается сразу", () => {
|
||
render(<PostOnFeed ad={{ ...AD, phoneVisible: true, phone: "+7 (900) 000-00-00" }} />);
|
||
|
||
expect(screen.getByText("+7 (900) 000-00-00")).toBeTruthy();
|
||
expect(revealPhone).not.toHaveBeenCalled();
|
||
});
|
||
|
||
test("ошибка показа номера — сообщение", async () => {
|
||
revealPhone.mockRejectedValue(new TypeError("Failed to fetch"));
|
||
render(<PostOnFeed ad={{ ...AD, phoneVisible: true }} />);
|
||
|
||
fireEvent.click(screen.getByText(SHOW));
|
||
|
||
expect(await screen.findByText(/связ|connection|network/i)).toBeTruthy();
|
||
});
|
||
|
||
test("своё объявление в ленте: номер открывается кнопкой, вместо «Написать» — подпись", async () => {
|
||
useAuthContext.mockReturnValue({ isAuthenticated: true, user: { id: 2 } });
|
||
revealPhone.mockResolvedValue("+7 (999) 111-22-33");
|
||
render(<PostOnFeed ad={{ ...AD, phoneVisible: true }} />);
|
||
|
||
expect(screen.queryByText(/^(Написать|Write)$/)).toBeNull();
|
||
expect(screen.getByText(/Ваше объявление|Your listing/)).toBeTruthy();
|
||
fireEvent.click(screen.getByText(SHOW));
|
||
expect(await screen.findByText("+7 (999) 111-22-33")).toBeTruthy();
|
||
});
|
||
|
||
test("находка с контрольными вопросами: вместо номера — «после проверки», кнопка «Это моё»", () => {
|
||
useAuthContext.mockReturnValue({ isAuthenticated: true, user: { id: 5 } });
|
||
render(<PostOnFeed ad={{ ...AD, type: "found", phoneVisible: true, verificationQuestions: ["Что на брелке?"] }} />);
|
||
|
||
expect(screen.queryByText(SHOW)).toBeNull();
|
||
expect(screen.getByText(/Номер — после проверки|Number after check/)).toBeTruthy();
|
||
expect(screen.getByText(/^(Это моё|It's mine)$/)).toBeTruthy();
|
||
});
|
||
|
||
test("потеря с вопросами: нашедший пишет через «Я нашёл», номер — после проверки", () => {
|
||
useAuthContext.mockReturnValue({ isAuthenticated: true, user: { id: 5 } });
|
||
render(<PostOnFeed ad={{ ...AD, phoneVisible: true, verificationQuestions: ["Что выгравировано?"] }} />);
|
||
|
||
expect(screen.queryByText(SHOW)).toBeNull();
|
||
expect(screen.getByText(/^(Я нашёл|I found it)$/)).toBeTruthy();
|
||
});
|
||
|
||
test("автор своей находки с вопросами открывает номер как обычно", () => {
|
||
useAuthContext.mockReturnValue({ isAuthenticated: true, user: { id: 2 } });
|
||
render(<PostOnFeed ad={{ ...AD, type: "found", phoneVisible: true, verificationQuestions: ["Что на брелке?"] }} />);
|
||
|
||
expect(screen.getByText(SHOW)).toBeTruthy();
|
||
});
|