Skip to content

Commit

Permalink
feat: test for correct data on first render
Browse files Browse the repository at this point in the history
  • Loading branch information
JMarques1196 committed Jan 29, 2025
1 parent 98fbdeb commit 5b26e60
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/components/Menu/activity-menu.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen } from "@testing-library/react";
import { render, screen, waitFor } from "@testing-library/react";
import { describe, it, expect, vi } from "vitest";
import React from "react";
import Menu from "./activity-menu";
Expand All @@ -14,17 +14,16 @@ global.ResizeObserver = vi.fn().mockImplementation(() => {
};
});
// Firebase
vi.mock('firebase/firestore', () => ({
vi.mock("firebase/firestore", () => ({
collection: vi.fn(),
getDocs: vi.fn(),
QuerySnapshot: vi.fn(),
}));

vi.mock('src/firebase.js', () => ({
vi.mock("src/firebase.js", () => ({
db: vi.fn(),
}));


describe("Menu", () => {
// Mock Data
interface MockData {
Expand Down Expand Up @@ -85,5 +84,15 @@ describe("Menu", () => {
screen.debug();
});
// Test Functions
// Add mocks for functions
it("Dsplays running data on initial render", async () => {
render(<Menu />);

await waitFor(() => {
const dateSelect = screen.getByLabelText("Choose a date");
expect(dateSelect).toHaveValue("2024-01-01"); // Displays the older activity on first run
});

expect(getDocs).toHaveBeenCalledTimes(1);
expect(collection).toHaveBeenCalledWith(expect.anything(), "run");
});
});

0 comments on commit 5b26e60

Please sign in to comment.