Skip to content

Commit 0e5dcdd

Browse files
Minor change for clear cache operation (#773) (#776)
* Minor change for clear cache operation Signed-off-by: gaobinlong <[email protected]> * Modify releate notes Signed-off-by: gaobinlong <[email protected]> --------- Signed-off-by: gaobinlong <[email protected]> (cherry picked from commit 5c882d7) Co-authored-by: gaobinlong <[email protected]>
1 parent e3e9d7f commit 0e5dcdd

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

public/containers/ClearCacheModal/ClearCacheModal.test.tsx

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,57 @@
55

66
import React from "react";
77
import "@testing-library/jest-dom/extend-expect";
8-
import { render, fireEvent } from "@testing-library/react";
9-
import ClearCacheModal from "./ClearCacheModal";
8+
import { browserServicesMock, coreServicesMock } from "../../../test/mocks";
9+
import { CoreServicesContext } from "../../components/core_services";
10+
import { ServicesContext } from "../../services";
11+
import { BrowserServices } from "../../models/interfaces";
12+
import { ModalProvider } from "../../components/Modal";
13+
import { CoreStart } from "opensearch-dashboards/public";
14+
import { render, fireEvent, waitFor } from "@testing-library/react";
15+
import ClearCacheModal, { ClearCacheModalProps } from "./ClearCacheModal";
16+
import { INDEX_OP_TARGET_TYPE } from "../../utils/constants";
17+
import { act } from "react-dom/test-utils";
1018

19+
function renderWithRouter(
20+
coreServicesContext: CoreStart | null,
21+
browserServicesContext: BrowserServices | null,
22+
props: ClearCacheModalProps
23+
) {
24+
return {
25+
...render(
26+
<CoreServicesContext.Provider value={coreServicesContext}>
27+
<ServicesContext.Provider value={browserServicesContext}>
28+
<ModalProvider>
29+
<ClearCacheModal {...props} />
30+
</ModalProvider>
31+
</ServicesContext.Provider>
32+
</CoreServicesContext.Provider>
33+
),
34+
};
35+
}
1136
describe("<ClearCacheModal /> spec", () => {
1237
it("renders the component", async () => {
13-
render(<ClearCacheModal selectedItems={[]} visible onClose={() => {}} type="indexes" />);
14-
38+
renderWithRouter(coreServicesMock, browserServicesMock, {
39+
selectedItems: [],
40+
visible: true,
41+
type: INDEX_OP_TARGET_TYPE.INDEX,
42+
onClose: () => {},
43+
});
44+
await act(async () => {});
1545
expect(document.body.children).toMatchSnapshot();
1646
});
1747

18-
it("calls close when cancel button clicked", () => {
48+
it("calls close when cancel button clicked", async () => {
1949
const onClose = jest.fn();
20-
const { getByTestId } = render(<ClearCacheModal selectedItems={[]} visible onClose={onClose} type="indexes" />);
50+
const { getByTestId, getByText } = renderWithRouter(coreServicesMock, browserServicesMock, {
51+
selectedItems: [],
52+
visible: true,
53+
type: INDEX_OP_TARGET_TYPE.INDEX,
54+
onClose: onClose,
55+
});
56+
await waitFor(() => {
57+
expect(getByText("Cache will be cleared for all open indexes.")).toBeInTheDocument();
58+
});
2159
fireEvent.click(getByTestId("ClearCacheCancelButton"));
2260
expect(onClose).toHaveBeenCalled();
2361
});

public/containers/ClearCacheModal/ClearCacheModal.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
EuiSpacer,
2424
} from "@elastic/eui";
2525

26-
interface ClearCacheModalProps {
26+
export interface ClearCacheModalProps {
2727
selectedItems: CatIndex[] | DataStream[] | IAlias[];
2828
visible: boolean;
2929
onClose: () => void;
@@ -36,7 +36,7 @@ export default function ClearCacheModal(props: ClearCacheModalProps) {
3636
const [blockHint, setBlockHint] = useState("");
3737
const [unBlockedItems, setUnBlockedItems] = useState([] as string[]);
3838
const [blockedItems, setBlockedItems] = useState([] as string[]);
39-
const [loading, setLoading] = useState(false);
39+
const [loading, setLoading] = useState(true);
4040

4141
const services = useContext(ServicesContext);
4242
const coreServices = useContext(CoreServicesContext) as CoreStart;
@@ -49,7 +49,6 @@ export default function ClearCacheModal(props: ClearCacheModalProps) {
4949
INDEX_OP_BLOCKS_TYPE.READ_ONLY_ALLOW_DELETE,
5050
];
5151
if (!!services && visible) {
52-
setLoading(true);
5352
switch (type) {
5453
case INDEX_OP_TARGET_TYPE.DATA_STREAM:
5554
setHint("Cache will be cleared for the following data streams.");
@@ -106,7 +105,7 @@ export default function ClearCacheModal(props: ClearCacheModalProps) {
106105
setBlockedItems([] as string[]);
107106
setLoading(true);
108107
}
109-
}, [services, visible, type, selectedItems, setLoading]);
108+
}, [services, visible, type, selectedItems]);
110109

111110
const onConfirm = useCallback(async () => {
112111
if (!!services) {

release-notes/opensearch-index-management-dashboards-plugin.release-notes-2.8.0.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Compatible with OpenSearch 2.8.0
44

55
### Features
66
* Feature: Add refresh index operation to UI ([#761](https://github.com/opensearch-project/index-management-dashboards-plugin/pull/761))
7-
* Feature: Add clear cache operation to UI ([#728](https://github.com/opensearch-project/index-management-dashboards-plugin/pull/728))
7+
* Feature: Add clear cache operation to UI ([#728](https://github.com/opensearch-project/index-management-dashboards-plugin/pull/728),[#773](https://github.com/opensearch-project/index-management-dashboards-plugin/pull/773))
88
* Feature: Add flush index operation to UI ([#713](https://github.com/opensearch-project/index-management-dashboards-plugin/pull/713),[#718](https://github.com/opensearch-project/index-management-dashboards-plugin/pull/718),[#751](https://github.com/opensearch-project/index-management-dashboards-plugin/pull/751),[#753](https://github.com/opensearch-project/index-management-dashboards-plugin/pull/753))
99
* Feature: Add notification settings page and runtime notification option for long running index operations ([#731](https://github.com/opensearch-project/index-management-dashboards-plugin/pull/731),[#732](https://github.com/opensearch-project/index-management-dashboards-plugin/pull/732))
1010
* Feature: Composable templates enhancement ([#730](https://github.com/opensearch-project/index-management-dashboards-plugin/pull/730))

0 commit comments

Comments
 (0)