fix(shop): prevent duplicate product card rendering across breakpoints in list viewMode
Deploy Canina / deploy (push) Successful in 2m5s

This commit is contained in:
devops committed 2026-10-17 14:42:44 +00:00
1 parent 5b20bab381
commit f9d70bc196
2 files changed
+26 -8

No files matched your search

@@ -1162,14 +1162,7 @@ export default function ArchivePage({
{section.products.map((p: Product) => (
<React.Fragment key={p.id}>
{viewMode === "list" ? (
<>
<div className="block lg:hidden w-full">
<ArchiveProductListItem product={p} />
</div>
<div className="hidden lg:block h-full">
<ArchiveProductCard product={p} />
</div>
</>
<ArchiveProductListItem product={p} />
) : (
<ArchiveProductCard product={p} />
)}
@@ -321,4 +321,29 @@ describe("ArchivePage Component", () => {
expect(mockPush).toHaveBeenCalledWith("/shop");
});
it("renders exactly one card instance per product in list viewMode to avoid DOM duplication across breakpoints", async () => {
const singleProduct = {
id: "prod-single-1",
slug: "canina-prod-single",
name: "محصول آزمایشی یکتا",
nameFa: "محصول آزمایشی یکتا",
priceValue: 120000,
stock: 10,
categorySlug: "joints",
images: ["/test.png"],
symptoms: [],
main_ingredients: [],
};
render(<ArchivePage initialProducts={[singleProduct as any]} />);
await waitFor(() => {
expect(screen.getAllByText("محصول آزمایشی یکتا").length).toBeGreaterThan(0);
});
const productLinks = screen.getAllByRole("link", { name: /محصول آزمایشی یکتا/i });
expect(productLinks).toHaveLength(1);
});
});