Skip to content

Commit

Permalink
Wrap indexView in router in test
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelemeny committed Dec 26, 2023
1 parent a2da0c7 commit ace2045
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions quickwit/quickwit-ui/src/views/IndexView.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { render, unmountComponentAtNode } from "react-dom";
import { waitFor } from "@testing-library/react";
import { screen } from '@testing-library/dom';
import { unmountComponentAtNode } from "react-dom";
import { render, waitFor, screen } from "@testing-library/react";
import { act } from "react-dom/test-utils";
import { Client } from "../services/client";
import IndexView from "./IndexView";
import { BrowserRouter } from "react-router-dom";

jest.mock('../services/client');
const mockedUsedNavigate = jest.fn();
Expand All @@ -33,20 +33,6 @@ jest.mock('react-router-dom', () => ({
})
}));

let container = null;
beforeEach(() => {
// setup a DOM element as a render target
container = document.createElement("div");
document.body.appendChild(container);
});

afterEach(() => {
// cleanup on exiting
unmountComponentAtNode(container);
container.remove();
container = null;
});

test('renders IndexView', async () => {
const index = {
metadata: {
Expand All @@ -59,7 +45,7 @@ test('renders IndexView', async () => {
Client.prototype.getIndex.mockImplementation(() => Promise.resolve(index));

await act(async () => {
render(<IndexView />, container);
render( <IndexView /> , {wrapper: BrowserRouter});
});

await waitFor(() => expect(screen.getByText(/my-new-fresh-index-uri/)).toBeInTheDocument());
Expand Down

0 comments on commit ace2045

Please sign in to comment.