From ca3731764b4ba9aaa1f17de3105f89b08b707f4f Mon Sep 17 00:00:00 2001 From: suzhou Date: Wed, 10 May 2023 18:38:22 +0800 Subject: [PATCH] feat: make unit test pass Signed-off-by: suzhou --- .../UnsavedChangesBottomBar.test.tsx.snap | 6 --- .../IndicesActions/IndicesActions.test.tsx | 38 +------------------ .../containers/IndicesActions/index.tsx | 1 - public/utils/helpers.ts | 21 +--------- 4 files changed, 2 insertions(+), 64 deletions(-) diff --git a/public/components/UnsavedChangesBottomBar/__snapshots__/UnsavedChangesBottomBar.test.tsx.snap b/public/components/UnsavedChangesBottomBar/__snapshots__/UnsavedChangesBottomBar.test.tsx.snap index 443d5f92a..30d2488b3 100644 --- a/public/components/UnsavedChangesBottomBar/__snapshots__/UnsavedChangesBottomBar.test.tsx.snap +++ b/public/components/UnsavedChangesBottomBar/__snapshots__/UnsavedChangesBottomBar.test.tsx.snap @@ -17,12 +17,6 @@ HTMLCollection [
-
- 0 - unsaved changes. -
diff --git a/public/pages/Indices/containers/IndicesActions/IndicesActions.test.tsx b/public/pages/Indices/containers/IndicesActions/IndicesActions.test.tsx index 9c78141ef..42ce19501 100644 --- a/public/pages/Indices/containers/IndicesActions/IndicesActions.test.tsx +++ b/public/pages/Indices/containers/IndicesActions/IndicesActions.test.tsx @@ -48,9 +48,6 @@ describe(" spec", () => { onShrink: function (): void { throw new Error("Function not implemented."); }, - getIndices: function (): Promise { - throw new Error("Function not implemented."); - }, }); await waitFor(() => { @@ -98,9 +95,6 @@ describe(" spec", () => { onShrink: function (): void { throw new Error("Function not implemented."); }, - getIndices: function (): Promise { - throw new Error("Function not implemented."); - }, }); await waitFor(() => { @@ -112,7 +106,7 @@ describe(" spec", () => { userEvent.click(getByTestId("Open Confirm button")); await waitFor(() => { - expect(browserServicesMock.commonService.apiCaller).toHaveBeenCalledTimes(1); + expect(browserServicesMock.commonService.apiCaller).toHaveBeenCalledTimes(2); expect(browserServicesMock.commonService.apiCaller).toHaveBeenCalledWith({ endpoint: "transport.request", data: { @@ -155,9 +149,6 @@ describe(" spec", () => { onShrink: function (): void { throw new Error("Function not implemented."); }, - getIndices: function (): Promise { - throw new Error("Function not implemented."); - }, }); await waitFor(() => { @@ -230,9 +221,6 @@ describe(" spec", () => { onShrink: function (): void { throw new Error("Function not implemented."); }, - getIndices: function (): Promise { - throw new Error("Function not implemented."); - }, }); await waitFor(() => { @@ -271,9 +259,6 @@ describe(" spec", () => { const history = createMemoryHistory(); const { container, getByTestId } = renderWithRouter({ - getIndices(): Promise { - return Promise.resolve(undefined); - }, history: history, location: history.location, onClose(): void {}, @@ -314,9 +299,6 @@ describe(" spec", () => { const history = createMemoryHistory(); const { container, getByTestId } = renderWithRouter({ - getIndices(): Promise { - return Promise.resolve(undefined); - }, history: history, location: history.location, onClose(): void {}, @@ -370,9 +352,6 @@ describe(" spec", () => { const history = createMemoryHistory(); const { container, getByTestId } = renderWithRouter({ - getIndices(): Promise { - return Promise.resolve(undefined); - }, history: history, location: history.location, onClose(): void {}, @@ -411,9 +390,6 @@ describe(" spec", () => { const history = createMemoryHistory(); const { getByTestId } = renderWithRouter({ - getIndices(): Promise { - return Promise.resolve(undefined); - }, history: history, location: history.location, onClose(): void {}, @@ -450,9 +426,6 @@ describe(" spec", () => { const history = createMemoryHistory(); const { getByTestId } = renderWithRouter({ - getIndices(): Promise { - return Promise.resolve(undefined); - }, history: history, location: history.location, onClose(): void {}, @@ -499,9 +472,6 @@ describe(" spec", () => { onShrink: function (): void { throw new Error("Function not implemented."); }, - getIndices: function (): Promise { - throw new Error("Function not implemented."); - }, }); await waitFor(() => { @@ -556,9 +526,6 @@ describe(" spec", () => { onShrink: function (): void { throw new Error("Function not implemented."); }, - getIndices: function (): Promise { - throw new Error("Function not implemented."); - }, }); await waitFor(() => { @@ -597,9 +564,6 @@ describe(" spec", () => { onShrink: function (): void { throw new Error("Function not implemented."); }, - getIndices: function (): Promise { - throw new Error("Function not implemented."); - }, }); await waitFor(() => { diff --git a/public/pages/Indices/containers/IndicesActions/index.tsx b/public/pages/Indices/containers/IndicesActions/index.tsx index e874de82f..1660aba82 100644 --- a/public/pages/Indices/containers/IndicesActions/index.tsx +++ b/public/pages/Indices/containers/IndicesActions/index.tsx @@ -26,7 +26,6 @@ export interface IndicesActionsProps extends Pick void; onClose: () => void; onShrink: () => void; - getIndices: () => Promise; } export default function IndicesActions(props: IndicesActionsProps) { diff --git a/public/utils/helpers.ts b/public/utils/helpers.ts index 39433de49..211fcee73 100644 --- a/public/utils/helpers.ts +++ b/public/utils/helpers.ts @@ -12,8 +12,6 @@ import { BrowserServices } from "../models/interfaces"; import { IndexOpBlocksType } from "./constants"; import { CatIndex, DataStream } from "../../server/models/interfaces"; import { IAlias } from "../pages/Aliases/interface"; -import { ClusterInfo } from "../models/interfaces"; -import { CommonService } from "../services"; export function getErrorMessage(err: any, defaultMessage: string) { if (err && err.message) return err.message; @@ -64,7 +62,7 @@ export const getClusterInfo = (props: { commonService: CommonService }): Promise .then((res) => { if (res && res.ok) { return { - cluster_name: res.response.cluster_name, + cluster_name: res?.response?.cluster_name, }; } @@ -169,20 +167,3 @@ export async function filterBlockedItems( }); return result; } -export const getClusterInfo = (props: { commonService: CommonService }): Promise => { - return props.commonService - .apiCaller<{ - cluster_name: string; - }>({ - endpoint: "cluster.health", - }) - .then((res) => { - if (res && res.ok) { - return { - cluster_name: res.response.cluster_name, - }; - } - - return {}; - }); -};