From 3a095e209606f7d6574360c8e8e904364560b31c Mon Sep 17 00:00:00 2001 From: Ahmad <103906421+ahmadk953@users.noreply.github.com> Date: Sun, 29 Dec 2024 18:50:54 -0500 Subject: [PATCH] Fixed a Small Error and Updated/Added Tests --- .github/workflows/tests.yml | 9 ++++ __tests__/board-title-form.test.tsx | 49 +++++++++++++++++++ __tests__/index.test.tsx | 9 ++++ .../_components/board-title-form.tsx | 8 ++- .../(dashboard)/board/[boardId]/page.tsx | 1 + jest.setup.ts | 10 ---- package.json | 1 + sentry.server.config.ts | 1 - yarn.lock | 31 +++++++++++- 9 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 __tests__/board-title-form.test.tsx diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 643508e..8bf425d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 }} diff --git a/__tests__/board-title-form.test.tsx b/__tests__/board-title-form.test.tsx new file mode 100644 index 0000000..8609b37 --- /dev/null +++ b/__tests__/board-title-form.test.tsx @@ -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(); + + const titleButton = screen.getByText('Test Board'); + expect(titleButton).toBeInTheDocument(); + }); + + it('should switch to edit mode when clicked', async () => { + render(); + + const titleButton = screen.getByText('Test Board'); + fireEvent.click(titleButton); + + const input = await screen.findByDisplayValue('Test Board'); + expect(input).toBeInTheDocument(); + }); +}); diff --git a/__tests__/index.test.tsx b/__tests__/index.test.tsx index b36dfa9..3d6d58e 100644 --- a/__tests__/index.test.tsx +++ b/__tests__/index.test.tsx @@ -8,6 +8,7 @@ describe('Home', () => { const { container } = render(); expect(container).toMatchSnapshot(); }); + it('renders a heading', () => { render(); @@ -15,4 +16,12 @@ describe('Home', () => { expect(heading).toBeInTheDocument(); }); + + it('renders a get started button', () => { + render(); + + const link = screen.getByRole('link', { name: /get tasko for free/i }); + + expect(link).toBeInTheDocument(); + }); }); diff --git a/app/(platform)/(dashboard)/board/[boardId]/_components/board-title-form.tsx b/app/(platform)/(dashboard)/board/[boardId]/_components/board-title-form.tsx index 4d5256a..f1b7a62 100644 --- a/app/(platform)/(dashboard)/board/[boardId]/_components/board-title-form.tsx +++ b/app/(platform)/(dashboard)/board/[boardId]/_components/board-title-form.tsx @@ -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(document.createElement('form')); + const formRef = useRef(null); + useEffect(() => { + formRef.current = document.createElement('form'); + }, []); + const inputRef = useRef(null); const [title, setTitle] = useState(data.title); diff --git a/app/(platform)/(dashboard)/board/[boardId]/page.tsx b/app/(platform)/(dashboard)/board/[boardId]/page.tsx index cabb896..2eca54f 100644 --- a/app/(platform)/(dashboard)/board/[boardId]/page.tsx +++ b/app/(platform)/(dashboard)/board/[boardId]/page.tsx @@ -35,6 +35,7 @@ const BoardIdPage = async (props: BoardIdPageProps) => { orderBy: { order: 'asc', }, + cacheStrategy: { ttl: 30, swr: 60 }, }); return ( diff --git a/jest.setup.ts b/jest.setup.ts index 5beccb8..7b0828b 100644 --- a/jest.setup.ts +++ b/jest.setup.ts @@ -1,11 +1 @@ import '@testing-library/jest-dom'; - -jest.mock('@clerk/nextjs/server', () => { - return { - auth: jest.fn().mockImplementation(() => { - return { - run: () => Promise.resolve({ id: '' }), - }; - }), - }; -}); diff --git a/package.json b/package.json index 558319b..b00c950 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/sentry.server.config.ts b/sentry.server.config.ts index d83b1c3..3695e3e 100644 --- a/sentry.server.config.ts +++ b/sentry.server.config.ts @@ -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. diff --git a/yarn.lock b/yarn.lock index 8df782f..8fa0216 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"