fix(blog): improve attribution layout and freshness
Deploy Canina / deploy (push) Successful in 4m4s
Deploy Canina / deploy (push) Successful in 4m4s
This commit is contained in:
1 parent
24362b89d7
commit
28485d51f7
6 files changed
+49
-20
No files matched your search
@@ -347,18 +347,18 @@ export default function BlogPage({
|
||||
<p className="text-sm sm:text-base text-medical-gray-500 mb-8 leading-relaxed line-clamp-3">
|
||||
{featuredPost.excerpt}
|
||||
</p>
|
||||
<div className="flex items-center justify-between pt-6 border-t border-medical-gray-100">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-medical-gray-100 rounded-full flex items-center justify-center text-medical-gray-400">
|
||||
<div data-testid="featured-footer" className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-5 pt-6 border-t border-medical-gray-100">
|
||||
<div className="flex min-w-0 items-start gap-3">
|
||||
<div className="w-10 h-10 shrink-0 bg-medical-gray-100 rounded-full flex items-center justify-center text-medical-gray-400">
|
||||
<User className="w-5 h-5" />
|
||||
</div>
|
||||
<div className="text-xs">
|
||||
<div className="font-black text-medical-gray-900">نویسنده: {featuredPost.author}</div>
|
||||
<div className="font-bold text-medical-gray-400">تیم: {featuredPost.authorTeam || BLOG_TEAM_FALLBACK}</div>
|
||||
{featuredPost.authorRole && <div className="font-bold text-medical-gray-400">{featuredPost.authorRole}</div>}
|
||||
<div data-testid="featured-attribution" className="flex min-w-0 flex-col gap-1 text-xs">
|
||||
<div data-testid="featured-author-name" className="font-black text-medical-gray-900 whitespace-nowrap overflow-hidden text-ellipsis">نویسنده: {featuredPost.author}</div>
|
||||
<div data-testid="featured-team-name" className="font-bold text-medical-gray-400 whitespace-nowrap overflow-hidden text-ellipsis">تیم: {featuredPost.authorTeam || BLOG_TEAM_FALLBACK}</div>
|
||||
{featuredPost.authorRole && <div className="font-bold text-medical-gray-400 whitespace-nowrap overflow-hidden text-ellipsis">{featuredPost.authorRole}</div>}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-canina-blue font-black text-sm">
|
||||
<div data-testid="featured-read-more" className="flex shrink-0 items-center gap-2 self-end sm:self-auto text-canina-blue font-black text-sm whitespace-nowrap">
|
||||
<span>مطالعه مقاله کامل</span>
|
||||
<ArrowLeft className="w-4 h-4 group-hover:-translate-x-2 transition-transform" />
|
||||
</div>
|
||||
@@ -433,12 +433,12 @@ export default function BlogPage({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="px-4 sm:px-7 pb-4 sm:pb-6 pt-2.5 border-t border-medical-gray-100 flex items-center justify-between">
|
||||
<div className="text-[11px] font-bold text-medical-gray-500 flex items-center gap-1.5">
|
||||
<User className="w-3.5 h-3.5 text-medical-gray-400" />
|
||||
<span>نویسنده: {post.author}</span><span>تیم: {post.authorTeam || BLOG_TEAM_FALLBACK}</span>
|
||||
<div className="px-4 sm:px-7 pb-4 sm:pb-6 pt-2.5 border-t border-medical-gray-100 flex items-end justify-between gap-3">
|
||||
<div data-testid={`regular-attribution-${post.id}`} className="min-w-0 text-[11px] font-bold text-medical-gray-500 flex flex-col gap-1">
|
||||
<div className="flex min-w-0 items-center gap-1.5"><User className="w-3.5 h-3.5 shrink-0 text-medical-gray-400" /><span className="truncate">نویسنده: {post.author}</span></div>
|
||||
<div className="truncate pr-5">تیم: {post.authorTeam || BLOG_TEAM_FALLBACK}</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-1 text-canina-blue font-black text-xs group-hover:underline">
|
||||
<div className="flex shrink-0 items-center gap-1 text-canina-blue font-black text-xs whitespace-nowrap group-hover:underline">
|
||||
<span>مطالعه</span>
|
||||
<ArrowLeft className="w-3.5 h-3.5 group-hover:-translate-x-1 transition-transform" />
|
||||
</div>
|
||||
|
||||
@@ -21,7 +21,9 @@ const categories=[{id:'joints',name:'Joints',slug:'joints'},{id:'skin',name:'Ski
|
||||
beforeEach(()=>vi.clearAllMocks());
|
||||
describe('BlogPage',()=>{
|
||||
it('renders featured and regular posts as semantic links',()=>{render(<BlogPage blogs={blogs} categories={categories}/>);expect(screen.getAllByRole('heading',{level:2})[0]).toHaveTextContent('Skin article');expect(screen.getByRole('link',{name:/Skin article/})).toHaveAttribute('href','/blog/skin');expect(screen.getByRole('link',{name:/Joint article/})).toHaveAttribute('href','/blog/joint');});
|
||||
it('labels publication, valid material update, author and stable team on featured and regular cards',()=>{const fresh=[{...blogs[0],publishedAt:'2026-01-01T08:00:00Z',contentUpdatedAt:'2026-01-02T08:00:00Z',authorTeam:'Clinical'}, {...blogs[1],publishedAt:'2026-01-02T08:00:00Z',contentUpdatedAt:'2026-01-02T12:00:00Z'}];render(<BlogPage blogs={fresh} categories={categories}/>);expect(screen.getAllByText(/تاریخ انتشار/)).toHaveLength(2);expect(screen.getByText(/آخرین بهروزرسانی/)).toBeInTheDocument();expect(screen.getAllByText(/نویسنده:/)).toHaveLength(2);expect(screen.getByText(/تیم: Clinical/)).toBeInTheDocument();expect(screen.getByText(/تیم: پژوهش و محتوای علمی کنینا/)).toBeInTheDocument();expect(document.querySelectorAll('time[datetime]').length).toBeGreaterThanOrEqual(3);});
|
||||
it('labels publication, including a same-day material update, author and stable team on featured and regular cards',()=>{const fresh=[{...blogs[0],publishedAt:'2026-01-01T08:00:00Z',contentUpdatedAt:'2026-01-02T08:00:00Z',authorTeam:'Clinical'}, {...blogs[1],publishedAt:'2026-01-02T08:00:00Z',contentUpdatedAt:'2026-01-02T12:00:00Z'}];render(<BlogPage blogs={fresh} categories={categories}/>);expect(screen.getAllByText(/تاریخ انتشار/)).toHaveLength(2);expect(screen.getAllByText(/آخرین بهروزرسانی/)).toHaveLength(2);expect(screen.getAllByText(/نویسنده:/)).toHaveLength(2);expect(screen.getByText(/تیم: Clinical/)).toBeInTheDocument();expect(screen.getByText(/تیم: پژوهش و محتوای علمی کنینا/)).toBeInTheDocument();expect(document.querySelectorAll('time[datetime]').length).toBeGreaterThanOrEqual(4);});
|
||||
it('stacks author and team on separate rows and keeps featured action on one line',()=>{render(<BlogPage blogs={blogs} categories={categories}/>);const featuredMeta=screen.getByTestId('featured-attribution');expect(featuredMeta).toHaveClass('flex-col');expect(screen.getByTestId('featured-read-more')).toHaveClass('whitespace-nowrap');const regularMeta=screen.getByTestId('regular-attribution-1');expect(regularMeta).toHaveClass('flex-col');expect(regularMeta.children).toHaveLength(2);});
|
||||
it('keeps the featured footer responsive without forcing attribution or action to wrap',()=>{render(<BlogPage blogs={blogs} categories={categories}/>);expect(screen.getByTestId('featured-footer')).toHaveClass('flex-col','sm:flex-row');expect(screen.getByTestId('featured-author-name')).toHaveClass('whitespace-nowrap');expect(screen.getByTestId('featured-team-name')).toHaveClass('whitespace-nowrap');});
|
||||
it('combines category, excerpt search and tags then resets empty intersection',()=>{render(<BlogPage blogs={blogs} categories={categories}/>);fireEvent.click(screen.getByRole('button',{name:'Joints'}));expect(h.replace).toHaveBeenCalledWith('/blog?categoryId=joints',{scroll:false});expect(screen.queryByText('Skin article')).not.toBeInTheDocument();fireEvent.change(screen.getByPlaceholderText('جستجو در موضوعات، بیماریها، ویتامینها...'),{target:{value:'MOBILITY'}});expect(screen.getByText('Joint article')).toBeInTheDocument();fireEvent.click(screen.getByRole('button',{name:'#coat'}));expect(screen.getByText('هیچ مقالهای با معیارهای جستجوی شما یافت نشد.')).toBeInTheDocument();fireEvent.click(screen.getByRole('button',{name:'پاکسازی همه فیلترها'}));expect(screen.getByText('Skin article')).toBeInTheDocument();expect(screen.getByText('Joint article')).toBeInTheDocument();});
|
||||
it('syncs category with route props',()=>{const view=render(<BlogPage blogs={blogs} categories={categories} initialCategoryId="joints"/>);expect(screen.queryByText('Skin article')).not.toBeInTheDocument();view.rerender(<BlogPage blogs={blogs} categories={categories} initialCategoryId="skin"/>);expect(screen.queryByText('Joint article')).not.toBeInTheDocument();});
|
||||
it('clears search and toggles tags off',()=>{render(<BlogPage blogs={blogs}/>);fireEvent.click(screen.getByRole('button',{name:'#health'}));expect(screen.queryByText('Skin article')).not.toBeInTheDocument();fireEvent.click(screen.getByRole('button',{name:'#health'}));expect(screen.getByText('Skin article')).toBeInTheDocument();fireEvent.change(screen.getByPlaceholderText('جستجو در موضوعات، بیماریها، ویتامینها...'),{target:{value:'missing'}});fireEvent.click(screen.getByRole('button',{name:'پاک کردن'}));expect(screen.getByText('Skin article')).toBeInTheDocument();});
|
||||
|
||||
Reference in new issue
Block a user