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

✨ Developed atom for home page #11

Merged
merged 2 commits into from
Dec 24, 2023
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
19 changes: 0 additions & 19 deletions frontend/.storybook/main.ts

This file was deleted.

15 changes: 0 additions & 15 deletions frontend/.storybook/preview.ts

This file was deleted.

3 changes: 1 addition & 2 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<title>Madhurendra's Tech Odyssey</title>
</head>
<body>
<div id="root"></div>
Expand Down
5,680 changes: 3,045 additions & 2,635 deletions frontend/package-lock.json

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,11 @@
"json-server": "^0.17.4",
"react": "^18.2.0",
"react-bootstrap": "^2.9.1",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-router-dom": "^6.21.1",
"react-toggle-dark-mode": "^1.1.1"
},
"devDependencies": {
"@storybook/addon-essentials": "^7.6.6",
"@storybook/addon-interactions": "^7.6.6",
"@storybook/addon-links": "^7.6.6",
"@storybook/addon-onboarding": "^1.0.10",
"@storybook/blocks": "^7.6.6",
"@storybook/react": "^7.6.6",
"@storybook/react-vite": "^7.6.6",
"@storybook/test": "^7.6.6",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^14.1.2",
"@types/jest": "^29.5.11",
Expand Down
1 change: 0 additions & 1 deletion frontend/public/vite.svg

This file was deleted.

4 changes: 3 additions & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react'
import './App.css'
import { DarkModeSwitch } from 'react-toggle-dark-mode'

function App() {

return (
<div>
Hi
<DarkModeSwitch onChange={() => {} } checked={false} />
</div>
)
}
Expand Down
Empty file.
Empty file.
6 changes: 2 additions & 4 deletions frontend/src/components/atoms/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import React from "react";
import { Button, ButtonProps } from "@mui/material";

export interface IButtonProps extends ButtonProps {}
import { Button } from "@mui/material";
import { IButtonProps } from "../../../interfaces/types";

const MuiButton = ({ ...buttonProps }: IButtonProps) =>
<Button {...buttonProps} />;
Expand Down
34 changes: 34 additions & 0 deletions frontend/src/components/atoms/Icon/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from "react";
import Icon from ".";
import { screen, render } from "@testing-library/react";
import "@testing-library/jest-dom"
import { ICON_ALT, ICON_COMPONENT } from "../../../utils/constants";

describe("Icon Tests", () => {
it("should render icon with src", () => {
render(<Icon src="../public/assets/png/icon.png" />)
const iconElement = screen.getByTestId(ICON_COMPONENT)
expect(iconElement).toBeDefined()
})
it("should render with alt text", () => {
render(<Icon src="../public/assets/png/icon.png" />)
const iconElement = screen.getByAltText(ICON_ALT)
expect(iconElement).toBeInTheDocument()
})
it("should render with custom style", () => {
const CustomStyle = {
color: "red",
fontSize:"20px"
}
render(<Icon src="../public/assets/png/icon.png" sx={CustomStyle} />)
const iconElement = screen.getByTestId(ICON_COMPONENT)
expect(iconElement).toHaveStyle(CustomStyle)
})
it("should click on icon", () => {
const mockClick = jest.fn()
render(<Icon src="../public/assets/png/icon.png" onClick={mockClick} />)
const iconElement = screen.getByTestId(ICON_COMPONENT)
iconElement.click()
expect(mockClick).toHaveBeenCalledTimes(1)
})
})
20 changes: 20 additions & 0 deletions frontend/src/components/atoms/Icon/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import { StyledIcon } from '../../../utils/styled'
import { IIconProps } from '../../../interfaces/types'
import { ICON_ALT, ICON_COMPONENT } from '../../../utils/constants'

const Icon = ({ src, width, height, onClick, sx}: IIconProps) => {
return (
<StyledIcon
data-testid={ICON_COMPONENT}
style={sx}
src={src}
width={width}
height={height}
alt={ICON_ALT}
onClick={onClick}
/>
)
}

export default Icon
45 changes: 45 additions & 0 deletions frontend/src/components/atoms/Toggle/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom';
import DarkModeToggle from '.';
import { IDarkModeToggle } from '../../../interfaces/types';
import { DARK_MODE_TOGGLE_COMPONENT } from '../../../utils/constants';

describe('DarkModeToggle Component Tests', () => {
const defaultProps: IDarkModeToggle = {
checked: false,
onChange: jest.fn(),
};

it('renders the DarkModeToggle component with default props', () => {
const { getByTestId } = render(<DarkModeToggle {...defaultProps} />);
const darkModeToggle = getByTestId(DARK_MODE_TOGGLE_COMPONENT);

expect(darkModeToggle).toBeInTheDocument();
expect(darkModeToggle).not.toBeChecked()
});

it('renders the DarkModeToggle component with custom props', () => {
const customProps: IDarkModeToggle = {
...defaultProps,
checked: true,
size: 150,
styles: { backgroundColor: 'red' },
};

const { getByTestId } = render(<DarkModeToggle {...customProps} />);
const darkModeToggle = getByTestId(DARK_MODE_TOGGLE_COMPONENT);

expect(darkModeToggle).toBeInTheDocument();
expect(darkModeToggle).toHaveStyle({ backgroundColor: 'red' });
});

it('invokes the onChange callback when toggled', () => {
const { getByTestId } = render(<DarkModeToggle {...defaultProps} />);
const darkModeToggle = getByTestId(DARK_MODE_TOGGLE_COMPONENT);

fireEvent.click(darkModeToggle);

expect(defaultProps.onChange).toHaveBeenCalled();
});
});
20 changes: 20 additions & 0 deletions frontend/src/components/atoms/Toggle/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import { DarkModeSwitch } from 'react-toggle-dark-mode';
import { IDarkModeToggle } from '../../../interfaces/types';
import { DARK_MODE_TOGGLE_COMPONENT } from '../../../utils/constants';


const DarkModeToggle = (props: IDarkModeToggle) => {

return (
<DarkModeSwitch
data-testid = {DARK_MODE_TOGGLE_COMPONENT}
style={props.styles}
checked={props.checked}
onChange={props.onChange}
size={props.size}
/>
)
}

export default DarkModeToggle
24 changes: 24 additions & 0 deletions frontend/src/components/atoms/Typography/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react"
import { render, screen } from "@testing-library/react"
import '@testing-library/jest-dom';
import Typography from "."


describe("Typography Tests", () => {
it("should render typography with text", () => {
render(<Typography text="Hello" />)
const typographyElement = screen.getByText("Hello")
expect(typographyElement).toBeInTheDocument()
})

it("should render typography with text", () => {
const CustomStyle = {
color: "red",
fontSize:"20px"
}
render(<Typography text="Styled Text" sx={CustomStyle} />)
const typographyElement = screen.getByText("Styled Text")
expect(typographyElement).toHaveStyle(CustomStyle)
})

})
7 changes: 7 additions & 0 deletions frontend/src/components/atoms/Typography/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react'
import { Typography as MuiTypography } from '@mui/material'
import { ITypgraphyProps } from '../../../interfaces/types'

const Typography = ({text,...props}: ITypgraphyProps) => <MuiTypography {...props}>{text}</MuiTypography>

export default Typography
20 changes: 20 additions & 0 deletions frontend/src/interfaces/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ButtonProps, TypographyProps } from "@mui/material";
import { CSSProperties } from "react";

export interface IButtonProps extends ButtonProps {}
export interface ITypgraphyProps extends TypographyProps {
text: string
}
export interface IIconProps {
sx?:CSSProperties
width?: string
height?: string
src: string
onClick?: () => void
}
export interface IDarkModeToggle {
styles?: CSSProperties
checked: boolean
onChange: () => void
size?: number
}
3 changes: 3 additions & 0 deletions frontend/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const ICON_ALT = "icon"
export const ICON_COMPONENT = "icon-component"
export const DARK_MODE_TOGGLE_COMPONENT = "dark-mode-toggle"
5 changes: 5 additions & 0 deletions frontend/src/utils/styled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import styled from '@emotion/styled'

export const StyledIcon = styled.img`
cursor: pointer;
`
4 changes: 2 additions & 2 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import react from '@vitejs/plugin-react-swc'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})
plugins: [react()]
})