Updated Tests and Caching

This commit is contained in:
Ahmad 2024-12-31 19:52:59 -05:00
parent 5ba9387411
commit dbecdc0212
No known key found for this signature in database
GPG key ID: 8FD8A93530D182BF
3 changed files with 36 additions and 1 deletions

1
.gitignore vendored
View file

@ -6,6 +6,7 @@
# testing
/coverage
junit.xml
# next.js
/.next/

View file

@ -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(<BoardTitleForm data={mockBoard} />);
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!');
});
});
});

View file

@ -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',
},
],
},
];