-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from 392-f24/charlie-testing
charlie gen-ai test
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { describe, it, vi, beforeEach, afterEach } from 'vitest'; | ||
import { render, screen } 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'); | ||
|
||
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 | ||
getCategories.mockResolvedValue(mockCategories); | ||
getClothesData.mockImplementation((uid, callback) => { | ||
callback(mockClothesData); | ||
return () => {}; // Mock unsubscribe function | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
describe('Closet component', () => { | ||
it('displays "Add your first t-shirt!" message when no t-shirts are uploaded', async () => { | ||
// Render the Closet component | ||
render(<Closet />); | ||
|
||
// Wait for the categories to load and ensure "T-Shirts" category is selectable | ||
await screen.findByText('T-Shirts'); | ||
|
||
// Click the "T-Shirts" category button | ||
const tShirtButton = screen.getByRole('button', { name: /T-Shirts/i }); | ||
tShirtButton.click(); | ||
|
||
// Verify the placeholder message | ||
const message = await screen.findByText(/add your first t-shirt/i); | ||
expect(message).toBeInTheDocument(); | ||
}); | ||
}); |