Skip to content

Commit

Permalink
merge tests
Browse files Browse the repository at this point in the history
  • Loading branch information
charlielovett committed Nov 15, 2024
2 parents cea7fc5 + 57f639b commit 46f76e1
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 0 deletions.
121 changes: 121 additions & 0 deletions src/components/EditForm.isa-genai.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// EditForm.test.jsx
import { render, screen, fireEvent } from "@testing-library/react";
import EditForm from "./EditForm";
import { vi } from "vitest";
import "@testing-library/jest-dom";
import React from "react";

// Mock dependencies

// Mock CustomDropdown to render a simple select element
vi.mock("./CustomDropdown", () => {
return {
default: ({ fieldId, FieldName, options, defaultValue, onChange }) => (
<select
id={fieldId}
name={FieldName}
defaultValue={defaultValue}
onChange={(e) => onChange(e.target.value)}
>
{options.map((option) => (
<option key={option} value={option}>
{option}
</option>
))}
</select>
),
};
});

// Mock ImageUploader to avoid dealing with actual image uploads
vi.mock("./ImageUploader", () => {
return {
default: () => <div>ImageUploaderMock</div>,
};
});

// Mock WarmthLevelInfo component
vi.mock("./WarmthLevelInfo", () => {
return {
default: () => null,
};
});

// Mock PreferenceInfo component
vi.mock("./PreferenceInfo", () => {
return {
default: () => null,
};
});

// Mock Firebase auth
vi.mock("../utilities/firebase", () => {
return {
auth: {
currentUser: {
uid: "testUserId",
},
},
};
});

// Mock writeData function
vi.mock("../utilities/database", () => {
return {
writeData: vi.fn(),
};
});

test("warmth level field shows up for certain categories", () => {
const categories = ["T-Shirt", "Sneakers", "Rain Jacket"];
const categoriesDict = {
"T-Shirt": "Tops",
Sneakers: "Footwear",
"Rain Jacket": "Outerwear",
};

// Render the component
render(
<EditForm
showModal={true}
setShowModal={() => {}}
defaultData={{
category: "T-Shirt",
warmthLevel: 0,
color: "#000000",
preference: 5,
image: "",
}}
categories={categories}
categoriesDict={categoriesDict}
editing={false}
/>
);

// Check that the warmth level field is displayed initially
expect(screen.getByLabelText("Warmth Level")).toBeInTheDocument();

// Change the category to "Sneakers" (Footwear)
fireEvent.change(screen.getByLabelText("Category"), {
target: { value: "Sneakers" },
});

// The warmth level field should not be displayed
expect(screen.queryByLabelText("Warmth Level")).not.toBeInTheDocument();

// Change the category to "Rain Jacket"
fireEvent.change(screen.getByLabelText("Category"), {
target: { value: "Rain Jacket" },
});

// The warmth level field should not be displayed
expect(screen.queryByLabelText("Warmth Level")).not.toBeInTheDocument();

// Change the category back to "T-Shirt"
fireEvent.change(screen.getByLabelText("Category"), {
target: { value: "T-Shirt" },
});

// The warmth level field should be displayed again
expect(screen.getByLabelText("Warmth Level")).toBeInTheDocument();
});
47 changes: 47 additions & 0 deletions src/components/SuggestedOutfit.aining-genai.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { render, screen } from "@testing-library/react";
import { describe, it, vi, expect } from "vitest";
import SuggestedOutfit from "./SuggestedOutfit";
import { MemoryRouter } from "react-router-dom";

// Mock Firebase auth
vi.mock("../utilities/firebase", () => ({
auth: {
currentUser: { uid: "testUserId" },
},
}));

// Mock the getSuggestedOutfit function
vi.mock("../utilities/functions", () => ({
getSuggestedOutfit: vi.fn(() =>
Promise.resolve({
top: "",
bottom: "",
outerwear: "",
footwear: "",
})
),
}));

describe("SuggestedOutfit Component", () => {
it("displays a message asking the user to add clothes when no clothes are in the closet", async () => {
const mockWeatherData = { temp: 20 }; // Example weather data
const mockWeatherError = null;

render(
<MemoryRouter>
<SuggestedOutfit
weatherData={mockWeatherData}
weatherError={mockWeatherError}
/>
</MemoryRouter>
);

// Wait for the outfit loading to finish
const messageElement = await screen.findByText(
/Add more clothes to get an outfit suggestion!/i
);

// Check if the message is displayed
expect(messageElement).toBeInTheDocument();
});
});

0 comments on commit 46f76e1

Please sign in to comment.