Skip to content

Commit

Permalink
test: increasing coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj committed Nov 13, 2024
1 parent 4c2508b commit f4b07b6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// src/__test__/components/SilvicultureSearch/Openings/OpeningsSearchBar.test.tsx

import React from "react";
import { render, screen } from "@testing-library/react";
import { render, screen, act } from "@testing-library/react";
import "@testing-library/jest-dom";
import OpeningsSearchBar from "../../../../components/SilvicultureSearch/Openings/OpeningsSearchBar";
import { vi } from "vitest";
Expand Down Expand Up @@ -36,7 +36,7 @@ describe("OpeningsSearchBar", () => {
expect(searchInput).toBeInTheDocument();
});

it("should call the onSearchClick function when the search button is clicked", () => {
it("should call the onSearchClick function when the search button is clicked", async () => {
// Create a mock function to pass as a prop
const onSearchClick = vi.fn();

Expand All @@ -48,7 +48,7 @@ describe("OpeningsSearchBar", () => {

// Click the search button
const searchButton = screen.getAllByRole("button", { name: "Search" })[1];
searchButton.click();
await act(async () => searchButton.click());

// Check if the onSearchClick function was called
expect(onSearchClick).toHaveBeenCalled();
Expand Down Expand Up @@ -119,4 +119,25 @@ describe("OpeningsSearchBar", () => {
const dNoneElement = screen.getByText('+2');
expect(dNoneElement).toBeInTheDocument();
});

it("should show inline notification when no filter provided", async () => {
// Create a mock function to pass as a prop
const onSearchClick = vi.fn();

const {container, getByText} = render(
<QueryClientProvider client={queryClient}>
<OpeningsSearchBar onSearchClick={onSearchClick} showNoFilterNotification={true} />
</QueryClientProvider>
);

// Click the search button
const searchButton = screen.getAllByRole("button", { name: "Search" })[1];
await act(async () => searchButton.click());

// Check if the onSearchClick function was called
expect(onSearchClick).toHaveBeenCalled();

expect(getByText("Missing at least one criteria to search")).toBeInTheDocument();

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ describe('OpeningSearchTab', () => {
const searchInput = screen.getByPlaceholderText('Search by opening ID, opening number, timber mark or file ID') as HTMLInputElement;
await act(async () => userEvent.type(searchInput, 'test'));
await act(async () => (await screen.findByTestId('search-button')).click());
await act(async () => await screen.findByText('Actions'));
});

it('should display a message when no results are found', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState, useEffect, useContext } from "react";
import { InlineNotification } from "@carbon/react";
import "./styles.scss";
import EmptySection from "../../../EmptySection";
import OpeningsSearchBar from "../OpeningsSearchBar";
Expand Down

0 comments on commit f4b07b6

Please sign in to comment.