From dbecdc021270101df5cfd2198bb9e150b10db40f Mon Sep 17 00:00:00 2001 From: Ahmad <103906421+ahmadk953@users.noreply.github.com> Date: Tue, 31 Dec 2024 19:52:59 -0500 Subject: [PATCH] Updated Tests and Caching --- .gitignore | 1 + __tests__/board-title-form.test.tsx | 28 +++++++++++++++++++++++++++- next.config.ts | 8 ++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 510e90a..902d384 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ # testing /coverage +junit.xml # next.js /.next/ diff --git a/__tests__/board-title-form.test.tsx b/__tests__/board-title-form.test.tsx index 8609b37..030c124 100644 --- a/__tests__/board-title-form.test.tsx +++ b/__tests__/board-title-form.test.tsx @@ -1,5 +1,6 @@ import '@testing-library/jest-dom'; -import { render, screen, fireEvent, act } from '@testing-library/react'; +import { render, screen, fireEvent, waitFor } from '@testing-library/react'; +import { toast } from 'sonner'; import { BoardTitleForm } from '@/app/(platform)/(dashboard)/board/[boardId]/_components/board-title-form'; import { Board } from '@prisma/client'; @@ -15,6 +16,16 @@ jest.mock('@/actions/update-board', () => ({ updateBoard: jest.fn(), })); +jest.mock('@/hooks/use-action', () => ({ + useAction: jest.fn().mockImplementation(() => ({ + execute: jest.fn().mockImplementation(({ title }) => { + Promise.resolve().then(() => { + toast.success(`Board "${title}" updated!`); + }); + }), + })), +})); + describe('BoardTitleForm', () => { const mockBoard: Board = { id: '1', @@ -46,4 +57,19 @@ describe('BoardTitleForm', () => { const input = await screen.findByDisplayValue('Test Board'); expect(input).toBeInTheDocument(); }); + + it('should update board title when form is blurred', async () => { + render(); + + const titleButton = screen.getByText('Test Board'); + fireEvent.click(titleButton); + + const input = await screen.findByDisplayValue('Test Board'); + fireEvent.change(input, { target: { value: 'New Title' } }); + fireEvent.blur(input); + + await waitFor(() => { + expect(toast.success).toHaveBeenCalledWith('Board "New Title" updated!'); + }); + }); }); diff --git a/next.config.ts b/next.config.ts index 6d2ba87..98b763b 100644 --- a/next.config.ts +++ b/next.config.ts @@ -31,6 +31,14 @@ const nextConfig: NextConfig = { key: 'Document-Policy', value: 'js-profiling', }, + { + key: 'CDN-Cache-Control', + value: 'public, s-maxage=15', + }, + { + key: 'Vercel-CDN-Cache-Control', + value: 'public, s-maxage=30', + }, ], }, ];