Skip to content

Commit

Permalink
added test for the OpeningsTab
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzgrewal committed Nov 6, 2024
1 parent c6cb9ca commit e7d29b4
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions frontend/src/__test__/components/OpeningsTab.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// src/__test__/components/SilvicultureSearch/Openings/OpeningsSearchBar.test.tsx

import React from "react";
import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";
import { vi } from "vitest";
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import OpeningsTab from "../../../src/components/OpeningsTab";
import { Provider } from "react-redux";
import store from "../../store";

describe("OpeningsTab", () => {
// Create a new QueryClient instance for each test
const queryClient = new QueryClient();
const showSpatial = false
const setShowSpatial = vi.fn()

it("renders the component successfully", () => {
render(
<QueryClientProvider client={queryClient}>
<Provider store={store}>
<OpeningsTab
showSpatial={showSpatial}
setShowSpatial={setShowSpatial}
/>
</Provider>
</QueryClientProvider>
);
// Check if the component is present with the correct text
const searchInput = screen.getByText(/Track the history of openings you have looked at and check spatial information by selecting the openings in the table below/i);
expect(searchInput).toBeInTheDocument();
});

it("shows the spatial area with Hide Spatial Button", () => {
render(
<QueryClientProvider client={queryClient}>
<Provider store={store}>
<OpeningsTab
showSpatial={true}
setShowSpatial={setShowSpatial}
/>
</Provider>
</QueryClientProvider>
);
console.log(screen.debug())
// Check if the component is present with the correct text
const searchInput = screen.getByRole('button', { name: /Hide Spatial/i });
expect(searchInput).toBeInTheDocument();
});
});

0 comments on commit e7d29b4

Please sign in to comment.