From 0f387ab843c056c4062b97d3231d676ffe53778b Mon Sep 17 00:00:00 2001 From: Diksha Dabhole Date: Fri, 12 Jun 2026 14:59:10 +0530 Subject: [PATCH 1/2] test(DashboardError-empty-fallback): verify edge cases & empty/missing inputs --- .../dashboard/error.empty-fallback.test.tsx | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 app/(root)/dashboard/error.empty-fallback.test.tsx diff --git a/app/(root)/dashboard/error.empty-fallback.test.tsx b/app/(root)/dashboard/error.empty-fallback.test.tsx new file mode 100644 index 000000000..b670b02eb --- /dev/null +++ b/app/(root)/dashboard/error.empty-fallback.test.tsx @@ -0,0 +1,52 @@ +// app/(root)/dashboard/error.empty-fallback.test.tsx + +import '@testing-library/jest-dom/vitest'; +import { render, screen } from '@testing-library/react'; +import { describe, it, expect, vi } from 'vitest'; +import DashboardError from './error'; + +vi.mock('next/link', () => ({ + default: ({ + children, + ...props + }: React.AnchorHTMLAttributes & { children: React.ReactNode }) => ( + {children} + ), +})); + +describe('DashboardError - Edge Cases & Empty/Missing Inputs', () => { + it('renders the generic emoji when error message is an empty string', () => { + render(); + + expect(screen.getByText('⚠️')).toBeInTheDocument(); + }); + + it('renders the fallback description when error message is an empty string', () => { + render(); + + expect( + screen.getByText('An unexpected error occurred while fetching the dashboard data.') + ).toBeInTheDocument(); + }); + + it('renders the generic heading when error message is an empty string', () => { + render(); + + expect(screen.getByRole('heading', { name: 'Something went wrong' })).toBeInTheDocument(); + }); + + it('renders without errors when the optional digest field is absent', () => { + const error = new Error('Unexpected failure') as Error & { digest?: string }; + + expect(() => render()).not.toThrow(); + + expect(screen.getByText('⚠️')).toBeInTheDocument(); + }); + + it('renders both action controls in the default empty-message fallback state', () => { + render(); + + expect(screen.getByRole('button', { name: /try again/i })).toBeInTheDocument(); + expect(screen.getByRole('link', { name: /go back home/i })).toBeInTheDocument(); + }); +}); From d6d5b5c65c7e84cf7eec06b6a59e5fb35caad28c Mon Sep 17 00:00:00 2001 From: Diksha Dabhole Date: Sat, 13 Jun 2026 15:32:03 +0530 Subject: [PATCH 2/2] resolve ci typecheck failure --- .../dashboard/error.empty-fallback.test.tsx | 52 +++++++++++++++---- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/app/(root)/dashboard/error.empty-fallback.test.tsx b/app/(root)/dashboard/error.empty-fallback.test.tsx index b670b02eb..f09dd3a62 100644 --- a/app/(root)/dashboard/error.empty-fallback.test.tsx +++ b/app/(root)/dashboard/error.empty-fallback.test.tsx @@ -14,25 +14,59 @@ vi.mock('next/link', () => ({ ), })); -describe('DashboardError - Edge Cases & Empty/Missing Inputs', () => { - it('renders the generic emoji when error message is an empty string', () => { - render(); +describe('Dashboard Error Page - Empty & Missing Input Fallbacks', () => { + it('renders successfully when error is null', () => { + expect(() => + render() + ).not.toThrow(); + expect(screen.getByRole('heading', { name: 'Something went wrong' })).toBeInTheDocument(); + expect( + screen.getByText('An unexpected error occurred while fetching the dashboard data.') + ).toBeInTheDocument(); expect(screen.getByText('⚠️')).toBeInTheDocument(); }); - it('renders the fallback description when error message is an empty string', () => { - render(); + it('renders successfully when error is undefined', () => { + expect(() => + render() + ).not.toThrow(); + + expect(screen.getByRole('heading', { name: 'Something went wrong' })).toBeInTheDocument(); + expect( + screen.getByText('An unexpected error occurred while fetching the dashboard data.') + ).toBeInTheDocument(); + }); + + it('renders successfully when error is an empty object', () => { + expect(() => + render() + ).not.toThrow(); + expect(screen.getByRole('heading', { name: 'Something went wrong' })).toBeInTheDocument(); expect( screen.getByText('An unexpected error occurred while fetching the dashboard data.') ).toBeInTheDocument(); }); - it('renders the generic heading when error message is an empty string', () => { - render(); + it('renders successfully when error has no message property', () => { + expect(() => + render() + ).not.toThrow(); expect(screen.getByRole('heading', { name: 'Something went wrong' })).toBeInTheDocument(); + expect( + screen.getByText('An unexpected error occurred while fetching the dashboard data.') + ).toBeInTheDocument(); + }); + + it('renders successfully when error message is an empty string', () => { + expect(() => render()).not.toThrow(); + + expect(screen.getByRole('heading', { name: 'Something went wrong' })).toBeInTheDocument(); + expect( + screen.getByText('An unexpected error occurred while fetching the dashboard data.') + ).toBeInTheDocument(); }); it('renders without errors when the optional digest field is absent', () => { @@ -43,8 +77,8 @@ describe('DashboardError - Edge Cases & Empty/Missing Inputs', () => { expect(screen.getByText('⚠️')).toBeInTheDocument(); }); - it('renders both action controls in the default empty-message fallback state', () => { - render(); + it('renders interactive elements correctly in fallback state', () => { + render(); expect(screen.getByRole('button', { name: /try again/i })).toBeInTheDocument(); expect(screen.getByRole('link', { name: /go back home/i })).toBeInTheDocument();