This commit is contained in:
1 parent
159e4a4cbf
commit
24362b89d7
3 files changed
+3
-3
No files matched your search
@@ -21,7 +21,7 @@ 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, 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('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();});
|
||||
|
||||
@@ -113,7 +113,7 @@ describe("BlogPreviewSection Component", () => {
|
||||
expect(screen.getByText("نویسنده: دکتر مریم اکبری")).toBeInTheDocument();
|
||||
// Default fallback author
|
||||
expect(screen.getByText("نویسنده: کنینا")).toBeInTheDocument();
|
||||
expect(screen.getAllByText("تیم: تیم پژوهش و محتوای علمی کنینا")).toHaveLength(2);
|
||||
expect(screen.getAllByText("تیم: پژوهش و محتوای علمی کنینا")).toHaveLength(2);
|
||||
|
||||
// Verify aria-label links with full title context
|
||||
const link1 = screen.getByLabelText("مطالعه مقاله: اهمیت کلسیم و مفاصل در رشد توله سگ ژرمن شپرد");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export const BLOG_TEAM_FALLBACK = "تیم پژوهش و محتوای علمی کنینا";
|
||||
export const BLOG_TEAM_FALLBACK = "پژوهش و محتوای علمی کنینا";
|
||||
export function publicationDate(blog:any): string | undefined { return blog?.publishedAt || blog?.createdAt; }
|
||||
function persianDay(value:string): string { return new Intl.DateTimeFormat("fa-IR-u-ca-persian-nu-latn",{year:"numeric",month:"2-digit",day:"2-digit",timeZone:"Asia/Tehran"}).format(new Date(value)); }
|
||||
export function validContentUpdatedAt(blog:any): string | undefined { const published=publicationDate(blog), updated=blog?.contentUpdatedAt; if(!published||!updated) return undefined; const p=new Date(published),u=new Date(updated); return Number.isFinite(p.getTime())&&Number.isFinite(u.getTime())&&u>p&&persianDay(updated)!==persianDay(published)?updated:undefined; }
|
||||
|
||||
Reference in new issue
Block a user