From 94c9ba1260c25316c9c97b147c5cb313df1f48bf Mon Sep 17 00:00:00 2001 From: Aining Li Date: Fri, 15 Nov 2024 15:31:32 -0600 Subject: [PATCH 1/3] genAI test --- .../SuggestedOutfit.aining-genai.test.jsx | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/components/SuggestedOutfit.aining-genai.test.jsx diff --git a/src/components/SuggestedOutfit.aining-genai.test.jsx b/src/components/SuggestedOutfit.aining-genai.test.jsx new file mode 100644 index 0000000..0304bd5 --- /dev/null +++ b/src/components/SuggestedOutfit.aining-genai.test.jsx @@ -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( + + + + ); + + // 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(); + }); +}); From cea7fc549cd616b37ef4ab33ce1a3e62dc426c41 Mon Sep 17 00:00:00 2001 From: charlielovett <115426211+charlielovett@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:42:51 -0600 Subject: [PATCH 2/3] charlie gen-ai test mock firebase --- src/pages/Closet.charlie.gen-ai.test.jsx | 29 +++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/pages/Closet.charlie.gen-ai.test.jsx b/src/pages/Closet.charlie.gen-ai.test.jsx index 8fbdd41..92fd6d0 100644 --- a/src/pages/Closet.charlie.gen-ai.test.jsx +++ b/src/pages/Closet.charlie.gen-ai.test.jsx @@ -1,29 +1,32 @@ import { describe, it, vi, beforeEach, afterEach } from 'vitest'; -import { render, screen } from '@testing-library/react'; +import { render, screen, fireEvent } from '@testing-library/react'; import Closet from './Closet'; -import { getClothesData, getCategories } from '../utilities/database'; -import { auth } from '../utilities/firebase'; -vi.mock('../utilities/database'); -vi.mock('../utilities/firebase'); +// Mock the utilities +vi.mock('../utilities/firebase', () => ({ + auth: { currentUser: { uid: '12345' } }, +})); + +vi.mock('../utilities/database', () => ({ + getCategories: vi.fn(), + getClothesData: vi.fn(), +})); + +// Import mocked utilities +import { getCategories, getClothesData } from '../utilities/database'; const mockCategories = { categoriesOrdered: ['T-Shirts', 'Pants', 'Shoes'], categoriesDict: { 'T-Shirts': {}, Pants: {}, Shoes: {} }, }; -const mockUser = { uid: '12345' }; - const mockClothesData = [ { category: 'Pants', imageURL: 'pants1.png' }, { category: 'Shoes', imageURL: 'shoes1.png' }, ]; beforeEach(() => { - // Mock Firebase Authentication - auth.currentUser = mockUser; - - // Mock database calls + // Set up mocks getCategories.mockResolvedValue(mockCategories); getClothesData.mockImplementation((uid, callback) => { callback(mockClothesData); @@ -40,12 +43,12 @@ describe('Closet component', () => { // Render the Closet component render(); - // Wait for the categories to load and ensure "T-Shirts" category is selectable + // Wait for categories to load await screen.findByText('T-Shirts'); // Click the "T-Shirts" category button const tShirtButton = screen.getByRole('button', { name: /T-Shirts/i }); - tShirtButton.click(); + fireEvent.click(tShirtButton); // Verify the placeholder message const message = await screen.findByText(/add your first t-shirt/i); From c3cfb6ad67d4b792401812d57c0c864307892b53 Mon Sep 17 00:00:00 2001 From: irena liu Date: Fri, 15 Nov 2024 16:54:46 -0600 Subject: [PATCH 3/3] Update AddClothesButton.irena.test.jsx --- .../AddClothesButton.irena.test.jsx | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/components/AddClothesButton.irena.test.jsx b/src/components/AddClothesButton.irena.test.jsx index c664348..a78bf73 100644 --- a/src/components/AddClothesButton.irena.test.jsx +++ b/src/components/AddClothesButton.irena.test.jsx @@ -3,32 +3,42 @@ import { vi, describe, it, expect } from 'vitest'; import AddClothesButton from './AddClothesButton'; import Closet from '../pages/Closet'; +// Mocking Firebase utilities vi.mock('../utilities/firebase', () => ({ - auth: { - currentUser: { uid: 'testUserId' }, - }, - })); + auth: { + currentUser: { uid: 'testUserId' }, + }, +})); - vi.mock('../utilities/database', () => ({ - getClothesData: vi.fn((uid, callback) => { - callback([]); // Simulate an empty clothes list - return () => {}; // Return unsubscribe function - }), - getCategories: vi.fn(() => Promise.resolve({ +// Mocking database utilities +vi.mock('../utilities/database', () => ({ + getClothesData: vi.fn((uid, callback) => { + // Simulate an empty clothes list + callback([]); + // Return an unsubscribe function + return () => {}; + }), + getCategories: vi.fn(() => + Promise.resolve({ categoriesOrdered: ['shirt'], - categoriesDict: {} - })) - })); - -describe('AddClothesButton', () => { - it('should open the Add Clothes form when the Add button is clicked', async () => { + categoriesDict: {}, + }) + ), +})); + +describe('AddClothesButton Component', () => { + it('displays the Add Clothes form when the Add button is clicked', async () => { + // Render the Closet component render(); - await screen.findByText("shirt"); + // Ensure the "shirt" category is displayed + await screen.findByText('shirt'); + + // Find and click the Add button const addButton = screen.getByRole('button', { name: /add/i }); fireEvent.click(addButton); + // Verify that the Add Clothes form appears expect(screen.getByText(/Add Clothes/i)).toBeInTheDocument(); - }); });