From 3168c3194aede266a6bc0c1c590c5481ab9261f7 Mon Sep 17 00:00:00 2001 From: "sweep-ai[bot]" <128439645+sweep-ai[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 21:06:29 +0000 Subject: [PATCH] feat: Updated 1 files --- .../[variableId]/charts/page.tsx | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/apps/nextjs/app/dashboard/userVariables/[variableId]/charts/page.tsx b/apps/nextjs/app/dashboard/userVariables/[variableId]/charts/page.tsx index f7f414093..566f686c8 100644 --- a/apps/nextjs/app/dashboard/userVariables/[variableId]/charts/page.tsx +++ b/apps/nextjs/app/dashboard/userVariables/[variableId]/charts/page.tsx @@ -1,5 +1,7 @@ import { Metadata } from "next" import { notFound, redirect } from "next/navigation" +import { render, screen } from '@testing-library/react'; +import fetchMock from 'jest-fetch-mock'; import { authOptions } from "@/lib/auth" import { getCurrentUser } from "@/lib/session" @@ -7,6 +9,47 @@ import { Shell } from "@/components/layout/shell" import { DashboardHeader } from "@/components/pages/dashboard/dashboard-header" import { UserVariableCharts } from '@/components/userVariable/user-variable-charts'; +describe('UserVariableChart component', () => { + beforeEach(() => { + fetchMock.resetMocks(); + }); + + it('fetches user variable data', async () => { + fetchMock.mockResponseOnce(JSON.stringify([{ id: 1, name: 'Test Var' }])); + + render(); + + expect(fetchMock).toHaveBeenCalledWith( + `/api/dfda/userVariables?variableId=1&includeCharts=true` + ); + }); + + it('renders not found when user variable does not exist', async () => { + fetchMock.mockResponseOnce(JSON.stringify([])); + + render(); + + expect(await screen.findByText('Not Found')).toBeInTheDocument(); + }); + + it('renders UserVariableCharts with user variable', async () => { + const userVariable = { + id: 1, + name: 'Test Var', + charts: { + lineChartWithoutSmoothing: { + highchartConfig: {} + } + } + }; + fetchMock.mockResponseOnce(JSON.stringify([userVariable])); + + render(); + + expect(await screen.findByText('Test Var')).toBeInTheDocument(); + }); +}); + export const metadata: Metadata = { title: "UserVariable Charts", }