From 8fa7f6374b427751442b1c3adfa282e10267e461 Mon Sep 17 00:00:00 2001 From: ishaan Date: Wed, 18 Sep 2024 15:34:17 -0700 Subject: [PATCH 1/3] feat!: add button atomic component - Added Button.tsx and Button.types.d.ts. - Wrapped MuiButton in new Button component. - Added test suite for button, Button.test.tsx. --- src/components/atoms/Button.tsx | 21 +++++++ src/types/Button.types.d.ts | 12 ++++ tests/components/atoms/Button.test.tsx | 85 ++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 src/components/atoms/Button.tsx create mode 100644 src/types/Button.types.d.ts create mode 100644 tests/components/atoms/Button.test.tsx diff --git a/src/components/atoms/Button.tsx b/src/components/atoms/Button.tsx new file mode 100644 index 0000000..400e80f --- /dev/null +++ b/src/components/atoms/Button.tsx @@ -0,0 +1,21 @@ +'use client'; +import React from 'react'; +import { Button as MuiButton } from '@mui/material'; +import { ButtonProps } from '@components/atoms/Button'; + +const Button: React.FC = ({ + label, + variant = 'contained', + color = 'primary', + size = 'medium', + onClick, + ...props +}: ButtonProps) => { + return ( + + {label} + + ); +}; + +export default Button; \ No newline at end of file diff --git a/src/types/Button.types.d.ts b/src/types/Button.types.d.ts new file mode 100644 index 0000000..493f3cb --- /dev/null +++ b/src/types/Button.types.d.ts @@ -0,0 +1,12 @@ +declare module '@components/atoms/Button' { + import { FC } from 'react'; + import { ButtonProps as MuiButtonProps } from '@mui/material/Button'; + + export interface ButtonProps extends Omit { + label: string; + color?: 'inherit' | 'primary' | 'secondary' | 'success' | 'error' | 'info' | 'warning'; + } + + const Button: FC; + export default Button; +} \ No newline at end of file diff --git a/tests/components/atoms/Button.test.tsx b/tests/components/atoms/Button.test.tsx new file mode 100644 index 0000000..ba688e5 --- /dev/null +++ b/tests/components/atoms/Button.test.tsx @@ -0,0 +1,85 @@ +import React from 'react'; +import { render, screen, fireEvent } from '@testing-library/react'; +import Button from '../../../src/components/atoms/Button'; +import { Button as MuiButton } from '@mui/material'; +import '@testing-library/jest-dom'; + +jest.mock('@mui/material', () => ({ + Button: jest.fn().mockImplementation(({ children, ...props }) => ( + + )), +})); + +describe('Button component', () => { + const defaultProps = { + label: 'Test Button', + variant: 'contained' as const, + color: 'primary' as const, + size: 'medium' as const, + onClick: jest.fn(), + }; + + beforeEach(() => { + (MuiButton as jest.Mock).mockClear(); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + it('should render the button with correct label', () => { + render(