From a4346bebfc6bc046f5ba53d898d3b5965a13d701 Mon Sep 17 00:00:00 2001 From: Aanya Date: Wed, 3 Jun 2026 18:35:41 +0530 Subject: [PATCH 1/2] test: add type compiler tests for tooltipUtils --- .../tooltipUtils.type-compiler.test.ts | 58 +++++++++++++++++++ package-lock.json | 1 - 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 components/dashboard/tooltipUtils.type-compiler.test.ts diff --git a/components/dashboard/tooltipUtils.type-compiler.test.ts b/components/dashboard/tooltipUtils.type-compiler.test.ts new file mode 100644 index 00000000..d46aefc2 --- /dev/null +++ b/components/dashboard/tooltipUtils.type-compiler.test.ts @@ -0,0 +1,58 @@ +import { describe, expectTypeOf, it } from 'vitest'; +import type { ActivityData } from '@/types/dashboard'; + +describe('tooltipUtils type compiler tests', () => { + it('validates ActivityData structure correctly', () => { + const validData: ActivityData = { + date: '2024-01-01', + count: 5, + intensity: 2, + }; + + expectTypeOf(validData.date).toBeString(); + expectTypeOf(validData.count).toBeNumber(); + expectTypeOf(validData.intensity).toBeNumber(); + }); + + it('ensures ActivityData array typing works', () => { + const data: ActivityData[] = [ + { + date: '2024-01-01', + count: 1, + intensity: 1, + }, + ]; + + expectTypeOf(data).toBeArray(); + }); + + it('accepts optional compatible values safely', () => { + const data: ActivityData = { + date: '2024-01-02', + count: 0, + intensity: 0, + }; + + expectTypeOf(data.count).toEqualTypeOf(); + }); + it('rejects invalid property types during compilation', () => { + expectTypeOf().toBeObject(); + + const invalidCount: ActivityData = { + date: '2024-01-01', + // @ts-expect-error count must be number + count: 'five', + intensity: 2, + }; + }); + + it('rejects missing required properties', () => { + expectTypeOf().toBeObject(); + + // @ts-expect-error intensity is required + const invalidData: ActivityData = { + date: '2024-01-01', + count: 5, + }; + }); +}); diff --git a/package-lock.json b/package-lock.json index 0259b992..f468167e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,6 @@ "dependencies": { "@resvg/resvg-js": "^2.6.2", "@tailwindcss/postcss": "^4.2.2", - "@unrs/resolver-binding-linux-x64-gnu": "*", "@vercel/analytics": "^1.6.1", "dompurify": "^3.4.7", "framer-motion": "^12.38.0", From 7ba78595bfc4c551c9942dc24afe34da4f3d817c Mon Sep 17 00:00:00 2001 From: Aanya Date: Thu, 4 Jun 2026 02:04:36 +0530 Subject: [PATCH 2/2] test(RefreshButton): verify responsive multi-device layouts --- ...reshButton.responsive-breakpoints.test.tsx | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 components/dashboard/RefreshButton.responsive-breakpoints.test.tsx diff --git a/components/dashboard/RefreshButton.responsive-breakpoints.test.tsx b/components/dashboard/RefreshButton.responsive-breakpoints.test.tsx new file mode 100644 index 00000000..261153f6 --- /dev/null +++ b/components/dashboard/RefreshButton.responsive-breakpoints.test.tsx @@ -0,0 +1,76 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { render, screen, fireEvent } from '@testing-library/react'; +import RefreshButton from './RefreshButton'; + +// Mock next/navigation +const pushMock = vi.fn(); +const refreshMock = vi.fn(); + +vi.mock('next/navigation', () => ({ + useRouter: () => ({ + push: pushMock, + refresh: refreshMock, + }), + useSearchParams: () => ({ + get: vi.fn(() => null), + }), +})); + +// Mock sonner +vi.mock('sonner', () => ({ + toast: { + success: vi.fn(), + }, +})); + +describe('RefreshButton responsive breakpoints', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('renders refresh button text', () => { + render(); + + expect(screen.getByText('Refresh Data')).toBeDefined(); + }); + + it('renders refresh button with accessible label', () => { + render(); + + expect(screen.getByLabelText('Refresh dashboard contribution data')).toBeDefined(); + }); + + it('renders button element correctly', () => { + render(); + + expect( + screen.getByRole('button', { + name: /refresh dashboard contribution data/i, + }) + ).toBeDefined(); + }); + + it('calls router push when clicked', () => { + render(); + + fireEvent.click( + screen.getByRole('button', { + name: /refresh dashboard contribution data/i, + }) + ); + + expect(pushMock).toHaveBeenCalled(); + }); + + it('calls router refresh when clicked', () => { + render(); + + fireEvent.click( + screen.getByRole('button', { + name: /refresh dashboard contribution data/i, + }) + ); + + expect(refreshMock).toHaveBeenCalled(); + }); +});