fix(clinic): render the real insurer logo on the clinic page
The component read item.logo[0].url, a shape the current API never sends, so every insurer rendered the same placeholder. It now reads logo_url and runs it through imageUrl(), since the API returns a path relative to its own host. The old shape is still accepted for records that carry it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
import CustomLoading from "@/app/component/loading/Custom";
|
||||
import ArrowLeftList from "@/components/icons/ArrowLeftList";
|
||||
import { imageUrl } from "@/helper";
|
||||
import { Button } from "@mui/material";
|
||||
import Image from "next/image";
|
||||
import { useRef, useEffect, useState } from "react";
|
||||
@@ -64,8 +65,10 @@ function ListBime({ data }) {
|
||||
className="p-[16px] border border-[#EFEFEF] h-[175px] flex flex-col items-center justify-center gap-[20px]"
|
||||
style={{ minWidth: itemWidth }}
|
||||
>
|
||||
{/* `logo_url` مسیر نسبی روی خودِ API است و باید با دامنهٔ API کامل شود.
|
||||
شکل قدیمی `logo[0].url` برای رکوردهای قدیمی نگه داشته شده. */}
|
||||
<Image
|
||||
src={item.logo?.[0]?.url || "/assets/images/logo.png"}
|
||||
src={imageUrl(item.logo_url || item.logo?.[0]?.url, "/assets/images/logo.png")}
|
||||
height={92}
|
||||
width={92}
|
||||
alt="bime"
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import ListBime from './ListBime';
|
||||
|
||||
// next/image به src خام دست نمیزند تا بشود آن را assert کرد.
|
||||
vi.mock('next/image', () => ({
|
||||
default: ({ src, alt }) => <img src={src} alt={alt} />,
|
||||
}));
|
||||
|
||||
const LOGO = '/uploads/insurances/logo/2026-08/tamin.png';
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.NEXT_PUBLIC_API_URL = 'https://api.example.ir';
|
||||
});
|
||||
|
||||
describe('ListBime', () => {
|
||||
it('لوگوی بیمه را با دامنهٔ API کامل میکند', () => {
|
||||
render(<ListBime data={{ list_bime: [{ name: 'تامین اجتماعی', logo_url: LOGO }] }} />);
|
||||
|
||||
expect(screen.getByAltText('bime')).toHaveAttribute('src', `https://api.example.ir${LOGO}`);
|
||||
});
|
||||
|
||||
it('شکل قدیمی logo[0].url هنوز کار میکند', () => {
|
||||
render(<ListBime data={{ list_bime: [{ name: 'بیمه ایران', logo: [{ url: LOGO }] }] }} />);
|
||||
|
||||
expect(screen.getByAltText('bime')).toHaveAttribute('src', `https://api.example.ir${LOGO}`);
|
||||
});
|
||||
|
||||
it('بیمهٔ بدون لوگو به تصویر پیشفرض میافتد', () => {
|
||||
render(<ListBime data={{ list_bime: [{ name: 'بیمه بیلوگو' }] }} />);
|
||||
|
||||
expect(screen.getByAltText('bime')).toHaveAttribute('src', '/assets/images/logo.png');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user