From efee5b2187d3359ba67746e110c7d090ccd29013 Mon Sep 17 00:00:00 2001 From: benarba mohammed Date: Tue, 17 Oct 2023 18:18:40 +0200 Subject: [PATCH 1/4] feat(button component): create a reusable button component to use in various part in the project fix #10 --- package-lock.json | 12 +++++++++++- package.json | 3 ++- src/components/Buttons/Button.jsx | 17 +++++++++++++++++ src/components/Buttons/Buttons.jsx | 7 ------- src/components/Buttons/__test__/Button.test.js | 7 +++++++ .../__test__/__snapshots__/Button.test.js.snap | 7 +++++++ 6 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 src/components/Buttons/Button.jsx delete mode 100644 src/components/Buttons/Buttons.jsx create mode 100644 src/components/Buttons/__test__/Button.test.js create mode 100644 src/components/Buttons/__test__/__snapshots__/Button.test.js.snap diff --git a/package-lock.json b/package-lock.json index df6b091..2b50400 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,8 @@ "react-dom": "^18.2.0", "react-icons": "^4.11.0", "react-router-dom": "^6.3.0", - "react-test-renderer": "^18.2.0" + "react-test-renderer": "^18.2.0", + "tailwind-merge": "^1.14.0" }, "devDependencies": { "@commitlint/cli": "^17.7.2", @@ -14835,6 +14836,15 @@ "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", "dev": true }, + "node_modules/tailwind-merge": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-1.14.0.tgz", + "integrity": "sha512-3mFKyCo/MBcgyOTlrY8T7odzZFx+w+qKSMAmdFzRvqBfLlSigU6TZnlFHK0lkMwj9Bj8OYU+9yW9lmGuS0QEnQ==", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/dcastil" + } + }, "node_modules/tailwindcss": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.3.3.tgz", diff --git a/package.json b/package.json index 820f833..ccf81f0 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "react-dom": "^18.2.0", "react-icons": "^4.11.0", "react-router-dom": "^6.3.0", - "react-test-renderer": "^18.2.0" + "react-test-renderer": "^18.2.0", + "tailwind-merge": "^1.14.0" }, "devDependencies": { "@commitlint/cli": "^17.7.2", diff --git a/src/components/Buttons/Button.jsx b/src/components/Buttons/Button.jsx new file mode 100644 index 0000000..f6fec9a --- /dev/null +++ b/src/components/Buttons/Button.jsx @@ -0,0 +1,17 @@ +import React from "react"; +import { twMerge } from "tailwind-merge"; +function Button({ children, className, onClick }) { + return ( + + ); +} + +export default Button; diff --git a/src/components/Buttons/Buttons.jsx b/src/components/Buttons/Buttons.jsx deleted file mode 100644 index 651fc77..0000000 --- a/src/components/Buttons/Buttons.jsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react"; - -function Buttons() { - return
Buttons
; -} - -export default Buttons; diff --git a/src/components/Buttons/__test__/Button.test.js b/src/components/Buttons/__test__/Button.test.js new file mode 100644 index 0000000..da92a17 --- /dev/null +++ b/src/components/Buttons/__test__/Button.test.js @@ -0,0 +1,7 @@ +import renderer from "react-test-renderer"; +import Button from "../Button"; + +it("renders correctly", () => { + const tree = renderer.create( + + + + ); } export default ProductCard; diff --git a/src/components/ProductCard/__test__/ProductCard.test.js b/src/components/ProductCard/__test__/ProductCard.test.js new file mode 100644 index 0000000..2dff3d2 --- /dev/null +++ b/src/components/ProductCard/__test__/ProductCard.test.js @@ -0,0 +1,8 @@ +import renderer from "react-test-renderer"; + +import ProductCard from "../ProductCard"; + +it("renders correctly", () => { + const tree = renderer.create().toJSON(); + expect(tree).toMatchSnapshot(); +}); diff --git a/src/components/ProductCard/__test__/__snapshots__/ProductCard.test.js.snap b/src/components/ProductCard/__test__/__snapshots__/ProductCard.test.js.snap new file mode 100644 index 0000000..a413633 --- /dev/null +++ b/src/components/ProductCard/__test__/__snapshots__/ProductCard.test.js.snap @@ -0,0 +1,93 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders correctly 1`] = ` +
+
+
+ Picture of the product +
+

+ Sale +

+
+
+
+
+

+ Nike Air MX Super 2500 +

+
+

+ category +

+

+ location +

+
+
+

+ $449 +

+ +
+
+
+`; diff --git a/src/pages/index.jsx b/src/pages/index.jsx index 320c4ab..f299904 100644 --- a/src/pages/index.jsx +++ b/src/pages/index.jsx @@ -1,10 +1,13 @@ +import { collection, getDocs } from "firebase/firestore"; import Link from "next/link"; import { useTranslation } from "next-i18next"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import * as React from "react"; -import { db } from "@/util/firebase"; -import { collection, getDocs } from "firebase/firestore"; + +import ProductCard from "@/components/ProductCard/ProductCard"; + import Layout from "@/layout/Layout"; +import { db } from "@/util/firebase"; export default function HomePage() { const { t } = useTranslation("common"); @@ -17,6 +20,7 @@ export default function HomePage() { }); return ( +

{t("test")}