Skip to content
Open
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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ jobs:
NODE_ENV: test
JWT_SECRET: testsecret12345678901234567890123

- name: Run frontend coverage
run: npm run coverage
working-directory: FRONTEND

e2e-tests:
name: Playwright E2E Tests
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ dist-ssr
*.njsproj
*.sln
*.sw?
coverage/
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh

echo "Running frontend tests..."
npm run test --prefix FRONTEND -- --run || exit 1
3 changes: 2 additions & 1 deletion FRONTEND/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview",
"test": "vitest"
"test": "vitest",
"coverage": "vitest run --coverage"
},
"dependencies": {
"@chakra-ui/icons": "^2.0.17",
Expand Down
6 changes: 4 additions & 2 deletions FRONTEND/src/components/ui/QuickViewModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Link } from "react-router-dom";
import { useCartStore } from "../../store/cart";
import { useCurrencyStore } from "../../store/currency";
import { formatPrice } from "../../utils/currency";

import React from "react";
const QuickViewModal = ({ isOpen, onClose, product }) => {
const { addToCart } = useCartStore();
const { currency, rates } = useCurrencyStore();
Expand Down Expand Up @@ -51,7 +51,9 @@ const QuickViewModal = ({ isOpen, onClose, product }) => {
{formatPrice(product.price, currency, rates)}
</Text>

{product.category && <Badge colorScheme="blue">{product.category}</Badge>}
{product.category && (
<Badge colorScheme="blue">{product.category}</Badge>
)}

{product.brand && (
<Text>
Expand Down
2 changes: 1 addition & 1 deletion FRONTEND/src/components/ui/ScrollToTop.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import React, { useEffect, useState } from "react";
import { IconButton, useColorModeValue } from "@chakra-ui/react";
import { LuArrowUp } from "react-icons/lu";

Expand Down
33 changes: 15 additions & 18 deletions FRONTEND/src/components/ui/tests/ProductCard.test.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, it, expect, vi } from "vitest";
Expand Down Expand Up @@ -34,8 +35,7 @@ vi.mock("../../../store/cart", () => ({
}));

vi.mock("../QuickAddModal", () => ({
default: ({ isOpen }) =>
isOpen ? <div>Quick Add Modal</div> : null,
default: ({ isOpen }) => (isOpen ? <div>Quick Add Modal</div> : null),
}));

vi.mock("@chakra-ui/react", async () => {
Expand Down Expand Up @@ -86,22 +86,18 @@ describe("ProductCard", () => {
expect(screen.getByText("Quick Add Modal")).toBeInTheDocument();
});

it("disables Add to Cart button when product is out of stock", () => {
render(
<ProductCard
product={{
...mockProduct,
stock: 0,
}}
/>
);

const addToCartButton = screen.getByRole("button", {
name: `Add ${mockProduct.name} to cart`,
});

expect(addToCartButton).toBeDisabled();
expect(addToCartButton).toHaveTextContent("Out of Stock");
it("disables Add to Cart button when product is out of stock", () => {
render(
<ProductCard
product={{
...mockProduct,
stock: 0,
}}
/>
);

const addToCartButton = screen.getByRole("button", {
name: `Add ${mockProduct.name} to cart`,
});

it("applies correct layout properties and transition styles to the card container", () => {
Expand All @@ -114,3 +110,4 @@ describe("ProductCard", () => {
expect(computedStyle.transition).toBe("all 0.2s ease-in-out");
});
});
});
13 changes: 13 additions & 0 deletions FRONTEND/vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
environment: "jsdom",
globals: true,
setupFiles: "./src/setupTests.js",
coverage: {
provider: "v8",
reporter: ["text", "html"],
},
},
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"build": "npm install && npm install --prefix FRONTEND && npm run build --prefix FRONTEND",
"start": "cross-env NODE_ENV=production node BACKEND/server.js",
"test:e2e": "npx playwright test",
"test:e2e:ui": "npx playwright test --ui"
"test:e2e:ui": "npx playwright test --ui",
"prepare": "husky"
},
"type": "module",
"keywords": [],
Expand Down
Loading