-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
madhuredra
committed
Dec 24, 2023
1 parent
a3ed0ba
commit 670727b
Showing
13 changed files
with
183 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
` |