From e164568aefae15bcfef021555d422f8c0426a170 Mon Sep 17 00:00:00 2001 From: Archie Agarwal Date: Mon, 7 Jul 2025 11:22:30 +0530 Subject: [PATCH] Update Indexadvisor.test.tsx with latest test changes --- .../Tabs/QueryTab/Indexadvisor.test.tsx | 62 +++---------------- 1 file changed, 9 insertions(+), 53 deletions(-) diff --git a/src/Explorer/Tabs/QueryTab/Indexadvisor.test.tsx b/src/Explorer/Tabs/QueryTab/Indexadvisor.test.tsx index efbd4e7aa..90f421453 100644 --- a/src/Explorer/Tabs/QueryTab/Indexadvisor.test.tsx +++ b/src/Explorer/Tabs/QueryTab/Indexadvisor.test.tsx @@ -87,8 +87,6 @@ test("logs progress message when fetching index metrics", async () => { await waitFor(() => expect(mockLogConsoleProgress).toHaveBeenCalledWith(expect.stringContaining("IndexMetrics")) ); - console.log("Calls:", mockLogConsoleProgress.mock.calls); - }); test("renders both Included and Not Included sections after loading", async () => { render(); @@ -101,9 +99,11 @@ test("shows update button only when an index is selected", async () => { render(); await waitFor(() => expect(screen.getByText("/bar/?")).toBeInTheDocument()); const checkboxes = screen.getAllByRole("checkbox"); - fireEvent.click(checkboxes[1]); // Select /bar/? + expect(checkboxes.length).toBeGreaterThan(1); + fireEvent.click(checkboxes[1]); expect(screen.getByText(/Update Indexing Policy/)).toBeInTheDocument(); - fireEvent.click(checkboxes[1]); // Deselect /bar/? + + fireEvent.click(checkboxes[1]); expect(screen.queryByText(/Update Indexing Policy/)).not.toBeInTheDocument(); }); test("calls replace when update policy is confirmed", async () => { @@ -114,7 +114,6 @@ test("calls replace when update policy is confirmed", async () => { const updateButton = screen.getByText(/Update Indexing Policy/); fireEvent.click(updateButton); await waitFor(() => expect(mockReplace).toHaveBeenCalled()); - console.log("mockReplace calls:", mockReplace.mock.calls); }); test("calls replace when update button is clicked", async () => { @@ -126,34 +125,19 @@ test("calls replace when update button is clicked", async () => { fireEvent.click(checkboxes[1]); // Select /bar/? fireEvent.click(screen.getByText(/Update Indexing Policy/)); await waitFor(() => expect(mockReplace).toHaveBeenCalled()); - console.log("mockReplace calls:", mockReplace.mock.calls); }); test("fetches indexing policy via read", async () => { render(); await waitFor(() => { - console.log("mockRead calls:", mockRead.mock.calls); expect(mockRead).toHaveBeenCalled(); }); }); -test("shows update button only when an index is selected", async () => { - render(); - await waitFor(() => expect(screen.getByText("/bar/?")).toBeInTheDocument()); - const checkboxes = screen.getAllByRole("checkbox"); - expect(checkboxes.length).toBeGreaterThan(1); - fireEvent.click(checkboxes[1]); - expect(screen.getByText(/Update Indexing Policy/)).toBeInTheDocument(); - - fireEvent.click(checkboxes[1]); - expect(screen.queryByText(/Update Indexing Policy/)).not.toBeInTheDocument(); -}); - test("selects all indexes when select-all is clicked", async () => { render(); await waitFor(() => expect(screen.getByText("/bar/?")).toBeInTheDocument()); const checkboxes = screen.getAllByRole("checkbox"); - console.log("Checkbox count:", checkboxes.length); fireEvent.click(checkboxes[0]); checkboxes.forEach((cb, i) => { @@ -165,16 +149,17 @@ test("shows spinner while loading and hides after fetchIndexMetrics resolves", a render(); expect(screen.getByRole("progressbar")).toBeInTheDocument(); await waitFor(() => expect(screen.queryByRole("progressbar")).not.toBeInTheDocument()); - console.log("Spinner visibility test passed"); }); test("calls fetchAll with correct query and options", async () => { render(); await waitFor(() => expect(mockFetchAll).toHaveBeenCalled()); - console.log("fetchAll called times:", mockFetchAll.mock.calls.length); - console.log("fetchAll called with args:", mockFetchAll.mock.calls[0]); }); - +test("renders IndexAdvisorTab when clicked from ResultsView", async () => { + render(); + await waitFor(() => expect(screen.getByText("Included in Current Policy")).toBeInTheDocument()); + expect(screen.getByText("/foo/?")).toBeInTheDocument(); +}); test("renders index metrics from SDK response", async () => { render(); await waitFor(() => expect(screen.getByText("/foo/?")).toBeInTheDocument()); @@ -185,8 +170,6 @@ test("renders index metrics from SDK response", async () => { test("calls handleError if fetchIndexMetrics throws", async () => { mockFetchAll.mockRejectedValueOnce(new Error("fail")); render(); - - console.log("Error handler called:", mockHandleError.mock.calls.length); await waitFor(() => expect(mockHandleError).toHaveBeenCalled()); }); @@ -196,34 +179,9 @@ test("calls handleError if fetchIndexMetrics throws2nd", async () => { render(); await waitFor(() => expect(mockHandleError).toHaveBeenCalled()); - console.log("Error handler called:", mockHandleError.mock.calls.length); expect(screen.queryByRole("status")).not.toBeInTheDocument(); }); -test("updates indexing policy after replace is triggered", async () => { - render(); - const barIndexText = await screen.findByText((content) => - content.includes("/bar/?") - ); - expect(barIndexText).toBeInTheDocument(); - const checkboxes = screen.getAllByRole("checkbox"); - fireEvent.click(checkboxes[1]); // Select /bar/? - const updateButton = screen.getByText(/Update Indexing Policy/); - fireEvent.click(updateButton); - await waitFor(() => expect(mockReplace).toHaveBeenCalled()); - const updatedPolicy = mockReplace.mock.calls[0][0]; - expect(updatedPolicy).toBeDefined(); - expect(updatedPolicy.indexingPolicy.includedPaths).toEqual( - expect.arrayContaining([{ path: "/*" }, { path: "/bar/?" }]) - ); -}); - -test("renders IndexAdvisorTab when clicked from ResultsView", async () => { - render(); - await waitFor(() => expect(screen.getByText("Included in Current Policy")).toBeInTheDocument()); - expect(screen.getByText("/foo/?")).toBeInTheDocument(); -}); - test("IndexingPolicyStore stores updated policy on componentDidMount", async () => { render(); await waitFor(() => expect(mockRead).toHaveBeenCalled()); @@ -235,7 +193,6 @@ test("IndexingPolicyStore stores updated policy on componentDidMount", async () expect(policy.automatic).toBe(true); expect(policy.indexingMode).toBe("consistent"); expect(policy.includedPaths).toEqual(expect.arrayContaining([{ path: "/*" }, { path: "/foo/?" }])); - console.log("Indexing policy stored:", policy); }); test("refreshCollectionData updates observable and re-renders", async () => { @@ -248,5 +205,4 @@ test("refreshCollectionData updates observable and re-renders", async () => { await waitFor(() => expect(mockReplace).toHaveBeenCalled()); expect(screen.getByText("/bar/?")).toBeInTheDocument(); - console.log("Collection data refreshed and re-rendered", mockReplace.mock.calls); });