Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add component tests #7

Merged
merged 6 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": [
["next/babel"],
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
]
}
203 changes: 203 additions & 0 deletions __tests__/__snapshots__/ui-snapshots.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`UI Component Snapshots button matches snapshot 1`] = `
<DocumentFragment>
<button
class="bg-blue-500 text-white p-2 rounded"
/>
</DocumentFragment>
`;

exports[`UI Component Snapshots edit-task-modal matches snapshot 1`] = `<DocumentFragment />`;

exports[`UI Component Snapshots invite-user-modal matches snapshot 1`] = `<DocumentFragment />`;

exports[`UI Component Snapshots next-logo matches snapshot 1`] = `
<DocumentFragment>
<svg
aria-label="Next.js logotype"
height="68"
role="img"
viewBox="0 0 394 79"
width="100"
>
<path
d="M261.919 0.0330722H330.547V12.7H303.323V79.339H289.71V12.7H261.919V0.0330722Z"
fill="currentColor"
/>
<path
d="M149.052 0.0330722V12.7H94.0421V33.0772H138.281V45.7441H94.0421V66.6721H149.052V79.339H80.43V12.7H80.4243V0.0330722H149.052Z"
fill="currentColor"
/>
<path
d="M183.32 0.0661486H165.506L229.312 79.3721H247.178L215.271 39.7464L247.127 0.126654L229.312 0.154184L206.352 28.6697L183.32 0.0661486Z"
fill="currentColor"
/>
<path
d="M201.6 56.7148L192.679 45.6229L165.455 79.4326H183.32L201.6 56.7148Z"
fill="currentColor"
/>
<path
clip-rule="evenodd"
d="M80.907 79.339L17.0151 0H0V79.3059H13.6121V16.9516L63.8067 79.339H80.907Z"
fill="currentColor"
fill-rule="evenodd"
/>
<path
d="M333.607 78.8546C332.61 78.8546 331.762 78.5093 331.052 77.8186C330.342 77.1279 329.991 76.2917 330 75.3011C329.991 74.3377 330.342 73.5106 331.052 72.8199C331.762 72.1292 332.61 71.7838 333.607 71.7838C334.566 71.7838 335.405 72.1292 336.115 72.8199C336.835 73.5106 337.194 74.3377 337.204 75.3011C337.194 75.9554 337.028 76.5552 336.696 77.0914C336.355 77.6368 335.922 78.064 335.377 78.373C334.842 78.6911 334.252 78.8546 333.607 78.8546Z"
fill="currentColor"
/>
<path
d="M356.84 45.4453H362.872V68.6846C362.863 70.8204 362.401 72.6472 361.498 74.1832C360.585 75.7191 359.321 76.8914 357.698 77.7185C356.084 78.5364 354.193 78.9546 352.044 78.9546C350.079 78.9546 348.318 78.6001 346.75 77.9094C345.182 77.2187 343.937 76.1826 343.024 74.8193C342.101 73.456 341.649 71.7565 341.649 69.7207H347.691C347.7 70.6114 347.903 71.3838 348.29 72.0291C348.677 72.6744 349.212 73.1651 349.895 73.5105C350.586 73.8559 351.38 74.0286 352.274 74.0286C353.243 74.0286 354.073 73.8286 354.746 73.4196C355.419 73.0197 355.936 72.4199 356.296 71.6201C356.646 70.8295 356.831 69.8479 356.84 68.6846V45.4453Z"
fill="currentColor"
/>
<path
d="M387.691 54.5338C387.544 53.1251 386.898 52.0254 385.773 51.2438C384.638 50.4531 383.172 50.0623 381.373 50.0623C380.11 50.0623 379.022 50.2532 378.118 50.6258C377.214 51.0075 376.513 51.5164 376.033 52.1617C375.554 52.807 375.314 53.5432 375.295 54.3703C375.295 55.061 375.461 55.6608 375.784 56.1607C376.107 56.6696 376.54 57.0968 377.103 57.4422C377.656 57.7966 378.274 58.0874 378.948 58.3237C379.63 58.56 380.313 58.76 380.995 58.9236L384.14 59.6961C385.404 59.9869 386.631 60.3778 387.802 60.8776C388.973 61.3684 390.034 61.9955 390.965 62.7498C391.897 63.5042 392.635 64.413 393.179 65.4764C393.723 66.5397 394 67.7848 394 69.2208C394 71.1566 393.502 72.8562 392.496 74.3285C391.491 75.7917 390.043 76.9369 388.143 77.764C386.252 78.582 383.965 79 381.272 79C378.671 79 376.402 78.6002 374.493 77.8004C372.575 77.0097 371.08 75.8463 370.001 74.3194C368.922 72.7926 368.341 70.9294 368.258 68.7391H374.235C374.318 69.8842 374.687 70.8386 375.314 71.6111C375.95 72.3745 376.78 72.938 377.795 73.3197C378.819 73.6923 379.962 73.8832 381.226 73.8832C382.545 73.8832 383.707 73.6832 384.712 73.2924C385.708 72.9016 386.492 72.3564 387.055 71.6475C387.627 70.9476 387.913 70.1206 387.922 69.1754C387.913 68.312 387.654 67.5939 387.156 67.0304C386.649 66.467 385.948 65.9944 385.053 65.6127C384.15 65.231 383.098 64.8856 381.899 64.5857L378.081 63.6223C375.323 62.9225 373.137 61.8592 371.541 60.4323C369.937 59.0054 369.143 57.115 369.143 54.7429C369.143 52.798 369.678 51.0894 370.758 49.6261C371.827 48.1629 373.294 47.0268 375.148 46.2179C377.011 45.4 379.114 45 381.456 45C383.836 45 385.92 45.4 387.719 46.2179C389.517 47.0268 390.929 48.1538 391.952 49.5897C392.976 51.0257 393.511 52.6707 393.539 54.5338H387.691Z"
fill="currentColor"
/>
</svg>
</DocumentFragment>
`;

exports[`UI Component Snapshots supabase-logo matches snapshot 1`] = `
<DocumentFragment>
<svg
aria-label="Supabase logo"
fill="none"
height="30"
viewBox="0 0 115 23"
width="140"
xmlns="http://www.w3.org/2000/svg"
>
<g
clip-path="url(#clip0_4671_51136)"
>
<g
clip-path="url(#clip1_4671_51136)"
>
<path
d="M13.4028 21.8652C12.8424 22.5629 11.7063 22.1806 11.6928 21.2898L11.4954 8.25948H20.3564C21.9614 8.25948 22.8565 10.0924 21.8585 11.3353L13.4028 21.8652Z"
fill="url(#paint0_linear_4671_51136)"
/>
<path
d="M13.4028 21.8652C12.8424 22.5629 11.7063 22.1806 11.6928 21.2898L11.4954 8.25948H20.3564C21.9614 8.25948 22.8565 10.0924 21.8585 11.3353L13.4028 21.8652Z"
fill="url(#paint1_linear_4671_51136)"
fill-opacity="0.2"
/>
<path
d="M9.79895 0.89838C10.3593 0.200591 11.4954 0.582929 11.5089 1.47383L11.5955 14.5041H2.84528C1.24026 14.5041 0.345103 12.6711 1.34316 11.4283L9.79895 0.89838Z"
fill="#3ECF8E"
/>
</g>
<path
d="M30.5894 13.3913C30.7068 14.4766 31.7052 16.3371 34.6026 16.3371C37.1279 16.3371 38.3418 14.7479 38.3418 13.1976C38.3418 11.8022 37.3824 10.6588 35.4836 10.2712L34.1131 9.98049C33.5846 9.88359 33.2323 9.5929 33.2323 9.12777C33.2323 8.58512 33.7804 8.17818 34.4656 8.17818C35.5618 8.17818 35.9729 8.89521 36.0513 9.45725L38.2243 8.97275C38.1069 7.94561 37.1867 6.22083 34.446 6.22083C32.3709 6.22083 30.844 7.63555 30.844 9.34094C30.844 10.6781 31.6856 11.7828 33.5454 12.1898L34.8179 12.4805C35.5618 12.6355 35.8555 12.9844 35.8555 13.4107C35.8555 13.9146 35.4444 14.3603 34.583 14.3603C33.4476 14.3603 32.8797 13.6626 32.8212 12.9068L30.5894 13.3913Z"
fill="currentColor"
/>
<path
d="M46.6623 16.0464H49.1486C49.1094 15.717 49.0506 15.0581 49.0506 14.3216V6.51154H46.4468V12.0542C46.4468 13.1588 45.7813 13.934 44.6263 13.934C43.4126 13.934 42.8643 13.0813 42.8643 12.0154V6.51154H40.2606V12.5387C40.2606 14.6123 41.5918 16.2984 43.9215 16.2984C44.9393 16.2984 46.0556 15.9108 46.5841 15.0193C46.5841 15.4069 46.6231 15.8526 46.6623 16.0464Z"
fill="currentColor"
/>
<path
d="M54.433 19.7286V15.1162C54.9027 15.7558 55.8817 16.279 57.213 16.279C59.9341 16.279 61.7545 14.1472 61.7545 11.2596C61.7545 8.43021 60.1298 6.29842 57.3108 6.29842C55.8623 6.29842 54.7855 6.93792 54.3548 7.67439V6.51159H51.8295V19.7286H54.433ZM59.19 11.279C59.19 12.9845 58.133 13.9728 56.8017 13.9728C55.4708 13.9728 54.394 12.9651 54.394 11.279C54.394 9.59299 55.4708 8.6046 56.8017 8.6046C58.133 8.6046 59.19 9.59299 59.19 11.279Z"
fill="currentColor"
/>
<path
d="M63.229 13.4495C63.229 14.9417 64.4818 16.3177 66.5375 16.3177C67.9662 16.3177 68.8865 15.6588 69.3758 14.9029C69.3758 15.2712 69.4149 15.7944 69.4737 16.0464H71.862C71.8033 15.7169 71.7449 15.0386 71.7449 14.5348V9.84482C71.7449 7.92622 70.6093 6.22083 67.5555 6.22083C64.9713 6.22083 63.5811 7.86807 63.4248 9.36033L65.7347 9.84482C65.8131 9.0115 66.4395 8.29445 67.5747 8.29445C68.6713 8.29445 69.1998 8.85646 69.1998 9.53475C69.1998 9.86421 69.0238 10.1355 68.4755 10.2131L66.1068 10.5619C64.5015 10.7945 63.229 11.744 63.229 13.4495ZM67.0854 14.3991C66.2438 14.3991 65.8325 13.8565 65.8325 13.2945C65.8325 12.558 66.361 12.1898 67.0268 12.0929L69.1998 11.7634V12.1898C69.1998 13.8759 68.1818 14.3991 67.0854 14.3991Z"
fill="currentColor"
/>
<path
d="M76.895 16.0465V14.8837C77.4038 15.6976 78.4217 16.279 79.7531 16.279C82.4941 16.279 84.2951 14.1278 84.2951 11.2403C84.2951 8.4108 82.6701 6.25965 79.851 6.25965C78.4217 6.25965 77.3648 6.8798 76.934 7.55806V2.01546H74.3696V16.0465H76.895ZM81.6911 11.2596C81.6911 13.0038 80.6341 13.9728 79.3028 13.9728C77.9912 13.9728 76.895 12.9845 76.895 11.2596C76.895 9.51543 77.9912 8.56584 79.3028 8.56584C80.6341 8.56584 81.6911 9.51543 81.6911 11.2596Z"
fill="currentColor"
/>
<path
d="M85.7692 13.4495C85.7692 14.9417 87.022 16.3177 89.0776 16.3177C90.5065 16.3177 91.4269 15.6588 91.916 14.9029C91.916 15.2712 91.9554 15.7944 92.014 16.0464H94.4023C94.3439 15.7169 94.2851 15.0386 94.2851 14.5348V9.84482C94.2851 7.92622 93.1495 6.22083 90.0955 6.22083C87.5115 6.22083 86.1216 7.86807 85.965 9.36033L88.2747 9.84482C88.3533 9.0115 88.9798 8.29445 90.1149 8.29445C91.2115 8.29445 91.74 8.85646 91.74 9.53475C91.74 9.86421 91.5638 10.1355 91.0156 10.2131L88.647 10.5619C87.0418 10.7945 85.7692 11.744 85.7692 13.4495ZM89.6258 14.3991C88.784 14.3991 88.3727 13.8565 88.3727 13.2945C88.3727 12.558 88.9012 12.1898 89.5671 12.0929L91.74 11.7634V12.1898C91.74 13.8759 90.722 14.3991 89.6258 14.3991Z"
fill="currentColor"
/>
<path
d="M96.087 13.3913C96.2042 14.4766 97.2028 16.3371 100.1 16.3371C102.626 16.3371 103.839 14.7479 103.839 13.1976C103.839 11.8022 102.88 10.6588 100.981 10.2712L99.6105 9.98049C99.082 9.88359 98.7299 9.5929 98.7299 9.12777C98.7299 8.58512 99.2778 8.17818 99.963 8.17818C101.06 8.17818 101.471 8.89521 101.549 9.45725L103.722 8.97275C103.604 7.94561 102.684 6.22083 99.9436 6.22083C97.8683 6.22083 96.3416 7.63555 96.3416 9.34094C96.3416 10.6781 97.183 11.7828 99.043 12.1898L100.316 12.4805C101.06 12.6355 101.353 12.9844 101.353 13.4107C101.353 13.9146 100.942 14.3603 100.081 14.3603C98.9451 14.3603 98.3776 13.6626 98.3188 12.9068L96.087 13.3913Z"
fill="currentColor"
/>
<path
d="M107.794 10.1937C107.852 9.32158 108.596 8.31381 109.947 8.31381C111.435 8.31381 112.062 9.24406 112.101 10.1937H107.794ZM112.355 12.6743C112.042 13.527 111.376 14.1278 110.163 14.1278C108.87 14.1278 107.794 13.2169 107.735 11.9573H114.626C114.626 11.9184 114.665 11.5309 114.665 11.1626C114.665 8.10064 112.884 6.22083 109.908 6.22083C107.441 6.22083 105.17 8.19753 105.17 11.2402C105.17 14.4572 107.5 16.3371 110.143 16.3371C112.512 16.3371 114.039 14.9611 114.528 13.3138L112.355 12.6743Z"
fill="currentColor"
/>
</g>
<defs>
<lineargradient
gradientUnits="userSpaceOnUse"
id="paint0_linear_4671_51136"
x1="11.4954"
x2="19.3439"
y1="11.1486"
y2="14.4777"
>
<stop
stop-color="#249361"
/>
<stop
offset="1"
stop-color="#3ECF8E"
/>
</lineargradient>
<lineargradient
gradientUnits="userSpaceOnUse"
id="paint1_linear_4671_51136"
x1="8.00382"
x2="11.5325"
y1="6.42177"
y2="13.1398"
>
<stop />
<stop
offset="1"
stop-opacity="0"
/>
</lineargradient>
<clippath
id="clip0_4671_51136"
>
<rect
fill="currentColor"
height="21.8943"
transform="translate(0.922119 0.456161)"
width="113.85"
/>
</clippath>
<clippath
id="clip1_4671_51136"
>
<rect
fill="currentColor"
height="21.8943"
transform="translate(0.919006 0.497101)"
width="21.3592"
/>
</clippath>
</defs>
</svg>
</DocumentFragment>
`;

exports[`UI Component Snapshots task-board matches snapshot 1`] = `
<DocumentFragment>
<div
class="p-4"
>
<h2
class="text-xl font-bold"
>
Task Board
</h2>
</div>
</DocumentFragment>
`;

exports[`UI Component Snapshots taskboard matches snapshot 1`] = `
<DocumentFragment>
<div>
<h1>
Task Board Component
</h1>
</div>
</DocumentFragment>
`;
3 changes: 1 addition & 2 deletions __tests__/about-page.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { act } from 'react';
import { render, screen } from '@testing-library/react';
import {act, render, screen} from '@testing-library/react';
import '@testing-library/jest-dom';
import { ThemeProvider } from '../__mocks__/themeContext';

Expand Down
23 changes: 23 additions & 0 deletions __tests__/component-count.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import fs from 'fs';
import path from 'path';

describe('Project File Structure', () => {

it('should not have test files outside __tests__ directory', () => {
const rootDir = path.resolve(__dirname, '..');
const allFiles = fs.readdirSync(rootDir, { withFileTypes: true })
.filter(dirent => dirent.isFile() && !dirent.name.startsWith('.'))
.map(dirent => dirent.name);

const testFilesOutside = allFiles.filter(file =>
(file.endsWith('.test.ts') || file.endsWith('.test.tsx')) &&
!file.startsWith('__tests__')
);

if (testFilesOutside.length > 0) {
console.log('Test files found outside __tests__ directory:', testFilesOutside);
}

expect(testFilesOutside).toEqual([]);
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom';
import EditTaskModal from '../edit-task-modal';
import EditTaskModal from '../components/edit-task-modal';

// Mock the next/navigation module
jest.mock('next/navigation', () => ({
useRouter: () => ({
push: jest.fn(),
}),
usePathname: () => '/',
}));

describe('EditTaskModal', () => {
const mockOnClose = jest.fn();
Expand Down Expand Up @@ -71,4 +79,4 @@ describe('EditTaskModal', () => {

expect(mockOnClose).toHaveBeenCalled();
});
});
});
62 changes: 62 additions & 0 deletions __tests__/project-structure.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import fs from 'fs';
import path from 'path';

const projectRoot = process.cwd();

function getFilesInDirectory(dir: string, recursive = false): string[] {
try {
const entries = fs.readdirSync(dir, { withFileTypes: true });
let files = entries
.filter(dirent => dirent.isFile())
.map(dirent => path.join(dir, dirent.name));

if (recursive) {
const directories = entries.filter(dirent => dirent.isDirectory());
for (const directory of directories) {
files = files.concat(getFilesInDirectory(path.join(dir, directory.name), true));
}
}

return files;
} catch (error) {
console.error(`Error reading directory ${dir}:`, error);
return [];
}
}

const expectedStructure: Record<string, string[]> = {
'app': ['layout.tsx', 'page.tsx', 'globals.css', 'favicon.ico', 'header.tsx', 'opengraph-image.png', 'taskboard.module.css', 'twitter-image.png'],
'app/login': ['page.tsx'],
'app/dashboard': ['page.tsx'],
'utils': ['auth.ts', 'cn.ts', 'supabaseClient.ts', 'utils.ts'],
'public': [], // Remove 'favicon.ico' from here
};

describe('Project File Structure', () => {
test('should have the correct file structure', () => {
const errors: string[] = [];

Object.entries(expectedStructure).forEach(([dirPath, expectedFiles]) => {
const fullPath = path.join(projectRoot, dirPath);
const actualFiles = getFilesInDirectory(fullPath);

const missingFiles = expectedFiles.filter(file => !actualFiles.includes(path.join(fullPath, file)));
const unexpectedFiles = actualFiles.filter(file => !expectedFiles.includes(path.basename(file)));

if (missingFiles.length > 0) {
errors.push(`Missing files in ${dirPath}:\n${missingFiles.map(file => ` - ${file}`).join('\n')}`);
}

if (unexpectedFiles.length > 0) {
errors.push(`Unexpected files in ${dirPath}:\n${unexpectedFiles.map(file => ` - ${path.basename(file)}`).join('\n')}`);
}
});

if (errors.length > 0) {
console.error('File structure errors:');
errors.forEach(error => console.error(error));
}

expect(errors).toEqual([]);
});
});
Loading
Loading