Show which listing each chat is about
The chat list and header show the listing's type, city and closed/deleted status; the header info button opens the full listing in PostDetailModal with a "show on map" action. Deleted or unpublished listings are marked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
38
src/components/chat/ChatPostInfo.test.jsx
Normal file
38
src/components/chat/ChatPostInfo.test.jsx
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* По какому объявлению чат: подпись в списке/шапке (тип, город, статус)
|
||||
* и кнопка в шапке, открывающая карточку. Удалённое объявление помечается.
|
||||
*/
|
||||
import { render, screen, fireEvent } from "@testing-library/react";
|
||||
import i18n from "../../i18n";
|
||||
import ChatPostMeta from "./ChatPostMeta";
|
||||
import ChatHeader from "./ChatHeader";
|
||||
import { cachePostsFromChats, getPostForChat } from "../../stores/chatPostStore";
|
||||
|
||||
const t = i18n.t.bind(i18n);
|
||||
|
||||
beforeAll(() => i18n.changeLanguage("ru"));
|
||||
|
||||
test("подпись показывает тип, город и закрытый статус", () => {
|
||||
render(<ChatPostMeta post={{ type: "FOUND", status: "CLOSED", city: "Москва" }} t={t} />);
|
||||
expect(screen.getByText("Находка")).toBeTruthy();
|
||||
expect(screen.getByText("Москва")).toBeTruthy();
|
||||
expect(screen.getByText("Закрыто")).toBeTruthy();
|
||||
});
|
||||
|
||||
test("удалённое объявление сохраняет прежний заголовок и помечается", () => {
|
||||
cachePostsFromChats([{ id: 501, postId: 9, post: { id: 9, title: "Шляпа", images: [] } }]);
|
||||
cachePostsFromChats([{ id: 501, postId: 9, post: null }]);
|
||||
|
||||
const post = getPostForChat(501);
|
||||
expect(post).toMatchObject({ id: 9, title: "Шляпа", removed: true });
|
||||
|
||||
render(<ChatPostMeta post={post} t={t} />);
|
||||
expect(screen.getByText("Объявление удалено")).toBeTruthy();
|
||||
});
|
||||
|
||||
test("кнопка в шапке открывает объявление", () => {
|
||||
const onInfo = jest.fn();
|
||||
render(<ChatHeader title="Шляпа" onBack={() => {}} onInfo={onInfo} infoLabel="Объявление этого чата" />);
|
||||
fireEvent.click(screen.getByLabelText("Объявление этого чата"));
|
||||
expect(onInfo).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
Reference in New Issue
Block a user