Fixed a Small Error and Updated/Added Tests

This commit is contained in:
Ahmad 2024-12-29 18:50:54 -05:00
parent 4f205d7584
commit 3a095e2096
No known key found for this signature in database
GPG key ID: 8FD8A93530D182BF
9 changed files with 105 additions and 14 deletions

View file

@ -28,7 +28,16 @@ jobs:
- name: Run tests
run: yarn coverage
- name: Generate junit.xml
run: JEST_JUNIT_CLASSNAME=\"{filepath}\" jest --reporters=jest-junit
- name: Upload results to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload junit.xml to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}

View file

@ -0,0 +1,49 @@
import '@testing-library/jest-dom';
import { render, screen, fireEvent, act } from '@testing-library/react';
import { BoardTitleForm } from '@/app/(platform)/(dashboard)/board/[boardId]/_components/board-title-form';
import { Board } from '@prisma/client';
jest.mock('sonner', () => ({
toast: {
success: jest.fn(),
error: jest.fn(),
},
}));
jest.mock('@/actions/update-board', () => ({
updateBoard: jest.fn(),
}));
describe('BoardTitleForm', () => {
const mockBoard: Board = {
id: '1',
title: 'Test Board',
imageId: 'image1',
imageThumbUrl: 'thumb-url',
imageFullUrl: 'full-url',
imageUserName: 'user1',
imageLinkHTML: 'link-html',
imageDownloadUrl: 'download-url',
createdAt: new Date(),
updatedAt: new Date(),
orgId: 'org1',
};
it('should render correctly in browser environment', () => {
render(<BoardTitleForm data={mockBoard} />);
const titleButton = screen.getByText('Test Board');
expect(titleButton).toBeInTheDocument();
});
it('should switch to edit mode when clicked', async () => {
render(<BoardTitleForm data={mockBoard} />);
const titleButton = screen.getByText('Test Board');
fireEvent.click(titleButton);
const input = await screen.findByDisplayValue('Test Board');
expect(input).toBeInTheDocument();
});
});

View file

@ -8,6 +8,7 @@ describe('Home', () => {
const { container } = render(<Page />);
expect(container).toMatchSnapshot();
});
it('renders a heading', () => {
render(<Page />);
@ -15,4 +16,12 @@ describe('Home', () => {
expect(heading).toBeInTheDocument();
});
it('renders a get started button', () => {
render(<Page />);
const link = screen.getByRole('link', { name: /get tasko for free/i });
expect(link).toBeInTheDocument();
});
});

View file

@ -1,7 +1,7 @@
'use client';
import { toast } from 'sonner';
import { useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { Board } from '@prisma/client';
import { Button } from '@/components/ui/button';
@ -25,7 +25,11 @@ export const BoardTitleForm = ({ data }: BoardTitleFormProps) => {
},
});
const formRef = useRef<HTMLFormElement>(document.createElement('form'));
const formRef = useRef<HTMLFormElement>(null);
useEffect(() => {
formRef.current = document.createElement('form');
}, []);
const inputRef = useRef<HTMLInputElement>(null);
const [title, setTitle] = useState(data.title);

View file

@ -35,6 +35,7 @@ const BoardIdPage = async (props: BoardIdPageProps) => {
orderBy: {
order: 'asc',
},
cacheStrategy: { ttl: 30, swr: 60 },
});
return (

View file

@ -1,11 +1 @@
import '@testing-library/jest-dom';
jest.mock('@clerk/nextjs/server', () => {
return {
auth: jest.fn().mockImplementation(() => {
return {
run: () => Promise.resolve({ id: '' }),
};
}),
};
});

View file

@ -88,6 +88,7 @@
"fluid-tailwind": "^1.0.4",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-junit": "^16.0.0",
"mintlify": "^4.0.300",
"postcss": "^8.4.49",
"prettier": "^3.4.2",

View file

@ -6,7 +6,6 @@ import * as Sentry from '@sentry/nextjs';
Sentry.init({
dsn: 'https://bb697105eaabbc6f70af12e84e936ded@o4508368569368576.ingest.us.sentry.io/4508368582017024',
// integrations: [Sentry.prismaIntegration()],
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for tracing.

View file

@ -10264,6 +10264,18 @@ __metadata:
languageName: node
linkType: hard
"jest-junit@npm:^16.0.0":
version: 16.0.0
resolution: "jest-junit@npm:16.0.0"
dependencies:
mkdirp: "npm:^1.0.4"
strip-ansi: "npm:^6.0.1"
uuid: "npm:^8.3.2"
xml: "npm:^1.0.1"
checksum: 10c0/d813d4d142341c2b51b634db7ad6ceb9849514cb58f96ec5e7e4cf4031a557133490452710c2d9dec9b1dd546334d9ca663e042d3070c3e8f102ce6217bd8e2e
languageName: node
linkType: hard
"jest-leak-detector@npm:^29.7.0":
version: 29.7.0
resolution: "jest-leak-detector@npm:29.7.0"
@ -12051,7 +12063,7 @@ __metadata:
languageName: node
linkType: hard
"mkdirp@npm:^1.0.3":
"mkdirp@npm:^1.0.3, mkdirp@npm:^1.0.4":
version: 1.0.4
resolution: "mkdirp@npm:1.0.4"
bin:
@ -15277,6 +15289,7 @@ __metadata:
fluid-tailwind: "npm:^1.0.4"
jest: "npm:^29.7.0"
jest-environment-jsdom: "npm:^29.7.0"
jest-junit: "npm:^16.0.0"
lodash: "npm:^4.17.21"
lucide-react: "npm:^0.469.0"
mintlify: "npm:^4.0.300"
@ -16163,6 +16176,15 @@ __metadata:
languageName: node
linkType: hard
"uuid@npm:^8.3.2":
version: 8.3.2
resolution: "uuid@npm:8.3.2"
bin:
uuid: dist/bin/uuid
checksum: 10c0/bcbb807a917d374a49f475fae2e87fdca7da5e5530820ef53f65ba1d12131bd81a92ecf259cc7ce317cbe0f289e7d79fdfebcef9bfa3087c8c8a2fa304c9be54
languageName: node
linkType: hard
"uuid@npm:^9.0.0, uuid@npm:^9.0.1":
version: 9.0.1
resolution: "uuid@npm:9.0.1"
@ -16653,6 +16675,13 @@ __metadata:
languageName: node
linkType: hard
"xml@npm:^1.0.1":
version: 1.0.1
resolution: "xml@npm:1.0.1"
checksum: 10c0/04bcc9b8b5e7b49392072fbd9c6b0f0958bd8e8f8606fee460318e43991349a68cbc5384038d179ff15aef7d222285f69ca0f067f53d071084eb14c7fdb30411
languageName: node
linkType: hard
"xmlbuilder@npm:~11.0.0":
version: 11.0.1
resolution: "xmlbuilder@npm:11.0.1"