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

Fe image #9

Merged
merged 6 commits into from
Feb 5, 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
9 changes: 9 additions & 0 deletions frontend/public/assets/images/facebook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/public/assets/images/graph.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions frontend/public/assets/images/rupee.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sonar.organization=dev-madhurendra
sonar.projectName=Short-My-Url-Frontend
sonar.host.url=https://sonarcloud.io
sonar.projectVersion=1.0
sonar.exclusions=**/node_modules/**,**/src/main.tsx, **/src/App.tsx
sonar.exclusions=**/node_modules/**,**/src/main.tsx, **/src/App.tsx,**/*.stories.tsx
sonar.sourceEncoding=UTF-8
sonar.sources=./src
sonar.tests=./src
Expand Down
35 changes: 35 additions & 0 deletions frontend/src/components/atoms/image/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from "react";
import ImageComponent from "./index";
import { Meta, StoryObj } from "@storybook/react";
import facebook from '../../../../public/assets/images/facebook.svg';
import graph from '../../../../public/assets/images/graph.svg';
import rupee from '../../../../public/assets/images/rupee.svg';

export default {
title: 'atoms/Image',
component: ImageComponent,
} as Meta<typeof ImageComponent>;

export const Facebook: StoryObj<typeof ImageComponent> = {
args: {
src: facebook,
height: '60px',
width: '60px',
}
};

export const Graph: StoryObj<typeof ImageComponent> = {
args: {
src: graph,
height: '60px',
width: '60px',
}
};

export const Rupee: StoryObj<typeof ImageComponent> = {
args: {
src: rupee,
height: '60px',
width: '60px',
}
};
29 changes: 29 additions & 0 deletions frontend/src/components/atoms/image/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { render, screen } from "@testing-library/react";
import ImageComponent from "./index";
import facebook from "../../../../public/assets/images/facebook.svg";
import graph from "../../../../public/assets/images/graph.svg";
import "@testing-library/jest-dom";

describe("ImageComponent", () => {
it("renders the image with the provided source", () => {
const src = facebook;
render(<ImageComponent src={src} />);

const imageElement = screen.getByTestId("image");

expect(imageElement).toBeInTheDocument();

});

it("sets the width and height attributes if provided", () => {
const src = graph;
const width = "200";
const height = "150";
render(<ImageComponent src={src} width={width} height={height} />);

const imageElement = screen.getByTestId("image");

expect(imageElement).toHaveAttribute("width", width);
expect(imageElement).toHaveAttribute("height", height);
});
});
20 changes: 20 additions & 0 deletions frontend/src/components/atoms/image/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { IMAGE_DATATESTID } from "../../../utils/constants";

interface ImageComponentProps {
src: string;
height?: string;
width?: string;
}

const ImageComponent = ({ src, height, width }: ImageComponentProps) => {
return (
<img
data-testid={IMAGE_DATATESTID}
src={src}
width={width}
height={height}
></img>
);
};

export default ImageComponent;
4 changes: 2 additions & 2 deletions frontend/src/components/atoms/typography/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { render } from "@testing-library/react";
import MuiTypography from ".";
import { typography_DataTestId } from "../../../utils/constants";
import { TYPOGRAPHY_DATATESTID } from "../../../utils/constants";

test("renders Typography", () => {
const { getByTestId } = render(<MuiTypography text="hello" variant="h1" />);
expect(getByTestId(typography_DataTestId)).toBeDefined();
expect(getByTestId(TYPOGRAPHY_DATATESTID)).toBeDefined();
});
4 changes: 2 additions & 2 deletions frontend/src/components/atoms/typography/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ReactNode } from "react";
import { Typography, TypographyProps } from "@mui/material";
import { typography_DataTestId } from "../../../utils/constants";
import { TYPOGRAPHY_DATATESTID } from "../../../utils/constants";

interface CustomTypographyProps extends TypographyProps {
text: ReactNode;

}
const MuiTypography = ({ variant, sx, text, ...rest }: CustomTypographyProps) => (
<Typography data-testid={typography_DataTestId} variant={variant} sx={sx} {...rest}>
<Typography data-testid={TYPOGRAPHY_DATATESTID} variant={variant} sx={sx} {...rest}>
{text}
</Typography>
);
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

export const typography_DataTestId='typography-component'
export const TYPOGRAPHY_DATATESTID='typography-component'
export const IMAGE_DATATESTID='image'
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading