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

redirect user when they click log out to the home page #91

Closed
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
2 changes: 1 addition & 1 deletion jest.setup.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import "@testing-library/jest-dom/extend-expect";
import '@testing-library/jest-dom'
315 changes: 243 additions & 72 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
"@commitlint/config-conventional": "^17.7.0",
"@svgr/webpack": "^8.1.0",
"@tailwindcss/typography": "^0.5.10",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
"@types/jest": "^29.5.8",
"@types/react": "^18.2.28",
"autoprefixer": "^10.4.16",
"cz-conventional-changelog": "^3.3.0",
Expand All @@ -56,6 +58,7 @@
"git-cz": "^4.9.0",
"husky": "^8.0.3",
"jest": "^29.7.0",
"jest-dom": "^4.0.0",
"jest-environment-jsdom": "^29.7.0",
"lint-staged": "^14.0.1",
"next-sitemap": "^4.2.3",
Expand All @@ -65,7 +68,9 @@
"prettier": "^3.0.3",
"react-test-renderer": "^18.2.0",
"standard-version": "^9.5.0",
"tailwindcss": "^3.3.3"
"tailwindcss": "^3.3.3",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
},
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx}": [
Expand Down
Binary file added public/images/about.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/login-pic.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
516 changes: 516 additions & 0 deletions public/images/login.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/components/blogcard/BlogCard.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const BlogCard = ({ blog }) => {
return (
<div className='bg-white shadow-md rounded-xl ml-2 mr-2 mb-2 mt-2 px-2 py-2 verflow-hidden'>
<div
data-testid='blog-card'
className='bg-white shadow-md rounded-xl ml-2 mr-2 mb-2 mt-2 px-2 py-2 verflow-hidden'
>
<div className='relative '>
<div className='bg-green-500 text-white absolute bottom-0 left-0 py-0 px-0 rounded-tr-lg'>
<p className='text-sm bg-green ml-0 px-3 py-2'>
Expand Down
2 changes: 1 addition & 1 deletion src/components/developeravatar/DeveloperAvatar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Link from "next/link";
const DeveloperAvatar = ({ name, avatarUrl, description, href }) => {
return (
<Link href={href}>
<div className='text-center flex flex-col items-center justify-center w-full md:w-80 rounded-lg p-4 border border-gray hover:bg-slate-100'>
<div className='text-center flex flex-col items-center justify-center w-full md:w-80 rounded-lg p-4 hover:bg-slate-100'>
<div className=' relative w-32 h-32 md:w-20 md:h-20 lg:w-36 lg:h-36 mb-2 mx-auto '>
<Image
src={avatarUrl}
Expand Down
13 changes: 12 additions & 1 deletion src/components/navbar/AccountMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@ import Link from "next/link";
import { useState } from "react";
import { BiLogOut } from "react-icons/bi";
import { MdAccountCircle } from "react-icons/md";
import { useRouter } from "next/router";
import { reload } from "firebase/auth";

const AccountMenu = ({ logout }) => {
const [openMenu, setOpenMenu] = useState(false);
const router = useRouter();

const handleLogout = () => {
// Perform logout action (call the provided logout function)
logout();

// Redirect to the home page
router.push("/");
};

return (
<div className='relative items-center justify-end hidden md:flex '>
Expand Down Expand Up @@ -38,7 +49,7 @@ const AccountMenu = ({ logout }) => {
</div>
</Link>
<button
onClick={logout}
onClick={handleLogout}
className='text-red whitespace-nowrap hover:opacity-75'
>
<div className='flex flex-row items-center gap-4 '>
Expand Down
Binary file added src/pics/loginmale.zip
Binary file not shown.
Binary file added src/pics/loginpic.zip
Binary file not shown.
Binary file not shown.
42 changes: 42 additions & 0 deletions test/articlecard.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { render, screen } from "@testing-library/react";
import ArticleCard from "@/components/articlecard/ArticleCard";

describe("ArticleCard", () => {
const mockArticle = {
title: "Test Article",
description: "This is a test article description.",
imageUrl: "/test-image.jpg",
articleUrl: "/test-article",
};

it("renders with content on the left by default", () => {
render(<ArticleCard {...mockArticle} />);
const titleElement = screen.getByText("Test Article");
const descriptionElement = screen.getByText("This is a test article description.");
const imageElement = screen.getByAltText("Test Article");
const buttonElement = screen.getByText("Read more");

expect(titleElement).toBeInTheDocument();
expect(descriptionElement).toBeInTheDocument();
expect(imageElement).toBeInTheDocument();
expect(buttonElement).toBeInTheDocument();
});

it("renders with content on the right when textOnleft is true", () => {
render(<ArticleCard {...mockArticle} textOnleft />);
const titleElement = screen.getByText("Test Article");
const descriptionElement = screen.getByText("This is a test article description.");
const imageElement = screen.getByAltText("Test Article");
const buttonElement = screen.getByText("Read more");

expect(titleElement).toBeInTheDocument();
expect(descriptionElement).toBeInTheDocument();
expect(imageElement).toBeInTheDocument();
expect(buttonElement).toBeInTheDocument();
});

it("does not render a Read more button when articleUrl is not provided", () => {
render(<ArticleCard title="Test Article" description="This is a test article description." imageUrl="/test-image.jpg" />);
const buttonElement = screen.queryByText("Read more");
});
});
49 changes: 49 additions & 0 deletions test/blogcard.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { render, screen } from "@testing-library/react";
import BlogCard from "@/components/blogcard/BlogCard";

describe("BlogCard", () => {
const mockBlog = {
title: "Test Blog",
description: "This is a test blog description.",
date: "2023-10-26",
image: "/test-image.jpg",
};

it("renders blog card with correct content", () => {
render(<BlogCard blog={mockBlog} />);

const titleElement = screen.getByText("Test Blog");
const descriptionElement = screen.getByText("This is a test blog description.");
const dateElement = screen.getByText("2023-10-26");
const imageElement = screen.getByAltText("Test Blog");

expect(titleElement).toBeInTheDocument();
expect(descriptionElement).toBeInTheDocument();
expect(dateElement).toBeInTheDocument();
expect(imageElement).toBeInTheDocument();
});

it("renders blog card with correct styles", () => {
render(<BlogCard blog={mockBlog} />);

const cardElement = screen.getByTestId("blog-card"); // Use a data-testid
const dateBadgeElement = screen.getByText("2023-10-26");

expect(cardElement).toHaveClass("bg-white");
expect(cardElement).toHaveClass("shadow-md");
expect(cardElement).toHaveClass("rounded-xl");
expect(cardElement).toHaveClass("ml-2");
expect(cardElement).toHaveClass("mr-2");
expect(cardElement).toHaveClass("mb-2");
expect(cardElement).toHaveClass("mt-2");
expect(cardElement).toHaveClass("px-2");
expect(cardElement).toHaveClass("py-2");
expect(cardElement).toHaveClass("verflow-hidden");

expect(dateBadgeElement).toHaveClass("text-sm");
expect(dateBadgeElement).toHaveClass("bg-green");
expect(dateBadgeElement).toHaveClass("ml-0");
expect(dateBadgeElement).toHaveClass("px-3");
expect(dateBadgeElement).toHaveClass("py-2");
});
});
49 changes: 49 additions & 0 deletions test/button.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// button.test.js

import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import Button from "@/components/button/Button";

describe("Button", () => {
it("renders a button with default style", () => {
render(<Button>Click me</Button>);
const buttonElement = screen.getByRole("button");

expect(buttonElement).toBeInTheDocument();
expect(buttonElement).toHaveClass("bg-green", "text-white");
});

it("renders a link with default style when href is provided", () => {
render(<Button href="/path">Go to path</Button>);
const linkElement = screen.getByRole("link");

expect(linkElement).toBeInTheDocument();
expect(linkElement).toHaveClass("bg-green", "text-white");
});

it("renders a button with outlinePrimary style", () => {
render(<Button variant="outlinePrimary">Click me</Button>);
const buttonElement = screen.getByRole("button");

expect(buttonElement).toBeInTheDocument();
expect(buttonElement).toHaveClass("bg-transparent", "border-green", "text-green");
});

it("renders a button with outlineSecondary style", () => {
render(<Button variant="outlineSecondary">Click me</Button>);
const buttonElement = screen.getByRole("button");

expect(buttonElement).toBeInTheDocument();
expect(buttonElement).toHaveClass("bg-transparent", "border-red", "text-red");
});

it("triggers the onClick handler when the button is clicked", () => {
const handleClick = jest.fn();
render(<Button onClick={handleClick}>Click me</Button>);
const buttonElement = screen.getByRole("button");

userEvent.click(buttonElement);

expect(handleClick).toHaveBeenCalledTimes(0);
});
});
63 changes: 63 additions & 0 deletions test/delete-warning.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import DeleteWarning from "@/components/delete-warning/index";
import { deleteDocData } from "@/lib/firebase/firestoreFunctions";

jest.mock("@/lib/firebase/firestoreFunctions", () => ({
deleteDocData: jest.fn(),
}));

describe("DeleteWarning", () => {
const mockItem = {
id: "123",
// Add other properties as needed for your item
};

const mockSetDeleteWarningItem = jest.fn();
const mockSetItems = jest.fn();
const mockItems = [
// Sample items for testing
{ id: "123", name: "Item 1" },
{ id: "456", name: "Item 2" },
// Add more items as needed
];

it("calls deleteDocData and updates state when 'Delete' button is clicked", async () => {
render(
<DeleteWarning
setDeleteWarningItem={mockSetDeleteWarningItem}
deleteWarningItem={mockItem.id}
setItems={mockSetItems}
items={mockItems}
/>
);

const deleteButton = screen.getByText("Delete");
userEvent.click(deleteButton);

// Wait for asynchronous operations to complete
await waitFor(() => {
expect(deleteDocData).toHaveBeenCalledWith("items", mockItem.id);
expect(mockSetItems).toHaveBeenCalledWith(
mockItems.filter((item) => item.id !== mockItem.id)
);
expect(mockSetDeleteWarningItem).toHaveBeenCalledWith(false);
});
});

it("cancels deletion when 'Cancel' button is clicked", () => {
render(
<DeleteWarning
setDeleteWarningItem={mockSetDeleteWarningItem}
deleteWarningItem={mockItem.id}
setItems={mockSetItems}
items={mockItems}
/>
);

const cancelButton = screen.getByText("Cancel");
userEvent.click(cancelButton);

expect(mockSetDeleteWarningItem).toHaveBeenCalledWith(false);
});
});
Loading