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
26 changes: 26 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: 2

updates:
- package-ecosystem: "npm"
directory: "/FRONTEND"
schedule:
interval: "weekly"

labels:
- "dependencies"

- package-ecosystem: "npm"
directory: "/BACKEND"
schedule:
interval: "weekly"

labels:
- "dependencies"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

labels:
- "dependencies"
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
76 changes: 76 additions & 0 deletions FRONTEND/package-lock.json

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

6 changes: 4 additions & 2 deletions 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 Expand Up @@ -46,7 +47,8 @@
"vite": "^6.3.1",
"vite-plugin-pwa": "^1.3.0",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^1.6.0"
"vitest": "^1.6.0",
"@vitest/coverage-v8": "^1.6.1"
},
"vitest": {
"environment": "jsdom"
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"],
},
},
});
39 changes: 39 additions & 0 deletions e2e/accessibility.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
import { BASE_URL } from "./helpers.js";

test.describe("Accessibility Audits", () => {
test("Homepage should not have serious or critical WCAG violations", async ({
page,
}) => {
await page.goto(BASE_URL);

await expect(page.locator("vite-error-overlay")).toHaveCount(0);

const results = await new AxeBuilder({ page }).analyze();

const severeViolations = results.violations.filter(
(violation) =>
violation.impact === "serious" || violation.impact === "critical"
);

expect(severeViolations).toEqual([]);
});

test("404 page should not have serious or critical WCAG violations", async ({
page,
}) => {
await page.goto(`${BASE_URL}/this-route-does-not-exist`);

await expect(page.locator("vite-error-overlay")).toHaveCount(0);

const results = await new AxeBuilder({ page }).analyze();

const severeViolations = results.violations.filter(
(violation) =>
violation.impact === "serious" || violation.impact === "critical"
);

expect(severeViolations).toEqual([]);
});
});
24 changes: 24 additions & 0 deletions package-lock.json

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

4 changes: 3 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 All @@ -22,6 +23,7 @@
"serverless-http": "^4.0.0"
},
"devDependencies": {
"@axe-core/playwright": "^4.12.1",
"@eslint/js": "^9.22.0",
"@playwright/test": "^1.61.0",
"cross-env": "^7.0.3",
Expand Down
Loading