Skip to content

Commit

Permalink
Merge pull request #417 from COS301-SE-2024/Test/web/test
Browse files Browse the repository at this point in the history
Test/web/test
  • Loading branch information
Rethakgetse-Manaka authored Oct 1, 2024
2 parents 72a2934 + f1a46f8 commit e7499db
Show file tree
Hide file tree
Showing 19 changed files with 956 additions and 226 deletions.
Binary file modified frontend/occupi-web/bun.lockb
Binary file not shown.
7 changes: 4 additions & 3 deletions frontend/occupi-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"@react-three/fiber": "^8.17.6",
"@react-three/postprocessing": "^2.16.2",
"@remixicon/react": "^4.2.0",
"@testing-library/jest-dom": "^6.4.6",
"@testing-library/react": "^16.0.0",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
"@tremor/react": "^3.17.4",
"@types/babel__core": "^7.20.5",
Expand All @@ -45,6 +45,7 @@
"@types/uuid": "^10.0.0",
"axios": "^1.7.2",
"axios-cookiejar-support": "^5.0.2",
"axios-mock-adapter": "^2.0.0",
"body-parser": "^1.20.2",
"bun-types": "^1.1.17",
"centrifuge": "^5.2.2",
Expand Down Expand Up @@ -91,7 +92,7 @@
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "",
"vitest": "^1.6.0",
"zustand": "^4.5.4"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { render, screen, cleanup } from '@testing-library/react';
import AboutComponent from './AboutComponent';

// Run cleanup after each test to ensure the DOM is cleaned up
afterEach(() => {
cleanup();
});

// Test if the logo is rendered correctly
test('renders the logo', () => {
render(<AboutComponent />);
const logo = screen.getByTestId('Logo'); // Adjust if needed
expect(logo).toBeDefined();
});

// Test if the heading "Occupi." is rendered correctly
test('renders the heading "Occupi."', () => {
render(<AboutComponent />);
const heading = screen.getByText(/Occupi\./i); // Case-insensitive match
expect(heading).toBeDefined();
});

// Test if the tagline "Predict. Plan. Perfect" is rendered
test('renders the tagline "Predict. Plan. Perfect"', () => {
render(<AboutComponent />);
const tagline = screen.getByText(/Predict\. Plan\. Perfect/i); // Match tagline text
expect(tagline).toBeDefined();
});

// Test if the version information is rendered
test('renders the version info "version: 0.9.0"', () => {
render(<AboutComponent />);
const versionText = screen.getByText(/version: 0.9.0/i);
expect(versionText).toBeDefined();
});

// Test if platform info "Web" is rendered
test('renders the platform info "Web"', () => {
render(<AboutComponent />);
const platformText = screen.getByText(/Web/i);
expect(platformText).toBeDefined();
});

// Test if browser info "Chrome 18.0.4" is rendered
test('renders the browser info "Chrome 18.0.4"', () => {
render(<AboutComponent />);
const browserText = screen.getByText(/Chrome 18.0.4/i);
expect(browserText).toBeDefined();
});

// Test if the privacy policy link is rendered
test('renders the privacy policy link', () => {
render(<AboutComponent />);
const privacyPolicyLink = screen.getByText(/privacy policy/i);
expect(privacyPolicyLink).toBeDefined();
});

// Test if the terms of service link is rendered
test('renders the terms of service link', () => {
render(<AboutComponent />);
const termsLink = screen.getByText(/terms of service/i);
expect(termsLink).toBeDefined();
});

// Test if the user manual link is rendered
test('renders the user manual link', () => {
render(<AboutComponent />);
const userManualLink = screen.getByText(/user manual/i);
expect(userManualLink).toBeDefined();
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { OccupiLogo } from "@assets/index";
import { motion } from "framer-motion";


const AboutComponent = () => {
return (
<div>
<div className="flex flex-col items-center">

<div className="fixed w-40 h-40 flex flex-col items-center justify-center ">
<div className="fixed w-40 h-40 flex flex-col items-center justify-center " data-testid='Logo'>
<motion.div
animate={{ rotate: 360 }}
transition={{ repeat: Infinity, duration: 2, ease: "linear" }}
>
<OccupiLogo />
<OccupiLogo />
</motion.div>
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { render, screen, fireEvent, cleanup } from "@testing-library/react";
import AddRoomModal from "./AddRoomModal";

// Mock the props for the AddRoomModal component
const mockOnSave = jest.fn();
const mockOnClose = jest.fn();

describe("AddRoomModal Component", () => {
beforeEach(() => {
// Reset mocks before each test
mockOnSave.mockClear();
mockOnClose.mockClear();
});

afterEach(() => {
// Cleanup after each test to ensure a fresh DOM
cleanup();
});

test("renders modal when isOpen is true", () => {
render(
<AddRoomModal isOpen={true} onClose={mockOnClose} onSave={mockOnSave} />
);

// Check if the modal is displayed
const modalHeader = screen.getByText(/Add New Room/i);
expect(modalHeader).toBeDefined();
});

test("can fill in the form inputs and save the room", () => {
render(
<AddRoomModal isOpen={true} onClose={mockOnClose} onSave={mockOnSave} />
);

// Find input fields and type values
fireEvent.change(screen.getByPlaceholderText("RM000"), {
target: { value: "RM101" },
});
fireEvent.change(screen.getByPlaceholderText("1"), {
target: { value: "101" },
});
fireEvent.change(screen.getByPlaceholderText("3"), {
target: { value: "2" },
});
fireEvent.change(screen.getByLabelText("Min Occupancy"), {
target: { value: "2" },
});
fireEvent.change(screen.getByLabelText("Max Occupancy"), {
target: { value: "5" },
});
fireEvent.change(screen.getByLabelText("Room Name"), {
target: { value: "Conference Room" },
});

// Simulate clicking the "Add Room" button
fireEvent.click(screen.getByText("Add Room"));

// Check if onSave was called with the correct room data
expect(mockOnSave).toHaveBeenCalled();
expect(mockOnSave.mock.calls[0][0]).toMatchObject({
roomId: "RM101",
roomNo: "101",
floorNo: "2",
minOccupancy: "2", // Now expect the string '2'
maxOccupancy: "5", // Now expect the string '5'
description: "",
resources: [],
roomName: "Conference Room",
isDisabled: false,
});
});

test('calls onClose when clicking the "Cancel" button', () => {
render(
<AddRoomModal isOpen={true} onClose={mockOnClose} onSave={mockOnSave} />
);

// Simulate clicking the "Cancel" button
fireEvent.click(screen.getByText("Cancel"));

// Check if onClose was called
expect(mockOnClose).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
@@ -1,59 +1,73 @@
// import { expect, test, mock } from "bun:test";
// import { render,cleanup } from "@testing-library/react";
// import {AiDashCard} from "@components/index";
// import { afterEach } from "bun:test";
// src/AiDashCard.test.tsx
import { render, screen, fireEvent, cleanup } from "@testing-library/react";
import AiDashCard from "./AiDashCard";
import { FaChartLine } from "react-icons/fa"; // Example icon

describe("AiDashCard", () => {
const mockOnRemove = jest.fn();

// afterEach(() => {
// cleanup();
// });
beforeEach(() => {
// Reset mocks before each test
mockOnRemove.mockClear();
});

// test("AiDashCard renders correctly", () => {
// const mockProps = {
// title: "Test Card",
// icon: <div>Icon</div>,
// stat: "100",
// trend: 5,
// onRemove: mock(() => {}),
// };
afterEach(() => {
// Cleanup after each test to ensure a fresh DOM
cleanup();
});

// const { getByText } = render(<AiDashCard {...mockProps} />);
test("renders AiDashCard with correct props", () => {
render(
<AiDashCard
title="Revenue"
icon={<FaChartLine />}
stat="10,000"
trend={5}
onRemove={mockOnRemove}
/>
);

// expect(getByText("Test Card")).toBeDefined();
// expect(getByText("100")).toBeDefined();
// expect(getByText("5% Since last month")).toBeDefined();
// });
// Check if title is rendered using getByText
expect(screen.getByText("Revenue")).toBeDefined();

// Check if the stat is rendered using getByText
expect(screen.getByText("10,000")).toBeDefined();

// Check if the trend is rendered correctly with Uptrend using getByText
expect(screen.getByText("5% Since last month")).toBeDefined();
});

// test("AiDashCard calls onRemove when close button is clicked", () => {
// const mockOnRemove = mock(() => {});
// const mockProps = {
// title: "Test Card",
// icon: <div>Icon</div>,
// stat: "100",
// trend: 5,
// onRemove: mockOnRemove,
// };
test("renders DownTrend when trend is negative", () => {
render(
<AiDashCard
title="Sales"
icon={<FaChartLine />}
stat="5,000"
trend={-3}
onRemove={mockOnRemove}
/>
);

// const { getByText } = render(<AiDashCard {...mockProps} />);
// const closeButton = getByText("×");
// closeButton.click();
// Check if the stat and trend are rendered correctly using getByText
expect(screen.getByText("5,000")).toBeDefined();
expect(screen.getByText("3% Since last month")).toBeDefined();
});

// expect(mockOnRemove).toHaveBeenCalled();
// });
test("calls onRemove when remove button is clicked", () => {
render(
<AiDashCard
title="Profit"
icon={<FaChartLine />}
stat="15,000"
trend={10}
onRemove={mockOnRemove}
/>
);

// test("AiDashCard displays negative trend correctly", () => {
// const mockProps = {
// title: "Test Card",
// icon: <div>Icon</div>,
// stat: "100",
// trend: -5,
// onRemove: mock(() => {}),
// };

// const { getByText } = render(<AiDashCard {...mockProps} />);

// expect(getByText("5% Since last month")).toBeDefined();
// });
// Simulate clicking the remove button using getByText
fireEvent.click(screen.getByText("×"));

// Ensure that the mockOnRemove function was called
expect(mockOnRemove).toHaveBeenCalled();
});
});
Loading

0 comments on commit e7499db

Please sign in to comment.