Skip to content

Commit 1ccbbe2

Browse files
vaibhoagSuZhou-Joe
andauthored
Updated @testing-library/user-event dependency (#1321)
* Updated @testing-library/user-event dependency Signed-off-by: Vaibhav Agarwal <[email protected]> * updated verify-binary-installation file Signed-off-by: Vaibhav Agarwal <[email protected]> * updated verify-binary-installation file2 Signed-off-by: Vaibhav Agarwal <[email protected]> * updated verify-binary-installation file3 Signed-off-by: Vaibhav Agarwal <[email protected]> * Fixed verify-binary-installation workflow Signed-off-by: Vaibhav Agarwal <[email protected]> * fixed tests Signed-off-by: Vaibhav Agarwal <[email protected]> * feat: update user event usage Signed-off-by: SuZhou-Joe <[email protected]> * feat: make all call as await Signed-off-by: SuZhou-Joe <[email protected]> * fix: failed UT Signed-off-by: SuZhou-Joe <[email protected]> * fix: rest of UT failure Signed-off-by: SuZhou-Joe <[email protected]> * fix: flaky UT Signed-off-by: SuZhou-Joe <[email protected]> * fix: flaky UT Signed-off-by: SuZhou-Joe <[email protected]> * fix: ComposableTemplates & Transforms Signed-off-by: Vaibhav Agarwal <[email protected]> * Fix: flaky Transform test Signed-off-by: Vaibhav Agarwal <[email protected]> * fix: Rollup test Signed-off-by: Vaibhav Agarwal <[email protected]> --------- Signed-off-by: Vaibhav Agarwal <[email protected]> Signed-off-by: SuZhou-Joe <[email protected]> Co-authored-by: SuZhou-Joe <[email protected]>
1 parent 7887c2c commit 1ccbbe2

File tree

77 files changed

+781
-682
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+781
-682
lines changed

.github/actions/run-cypress-tests/action.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ runs:
1010
using: "composite"
1111
steps:
1212
- name: Set up JDK
13-
uses: actions/setup-java@v1
13+
uses: actions/setup-java@v4
1414
with:
1515
# TODO: Parse this from index management plugin
1616
java-version: 21
17+
distribution: 'temurin'
1718
- name: Checkout index management
1819
uses: actions/checkout@v2
1920
with:

.github/workflows/verify-binary-installation.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: 'Install Dashboards with Plugin via Binary'
22

33
on: [push, pull_request]
44
env:
5-
OPENSEARCH_VERSION: '3.0.0-beta1'
5+
OPENSEARCH_VERSION: '3.1.0'
66
CI: 1
77
# avoid warnings like "tput: No value for $TERM and no -T specified"
88
TERM: xterm
@@ -29,10 +29,11 @@ jobs:
2929
shell: bash
3030

3131
- name: Run Opensearch
32-
uses: derek-ho/start-opensearch@v2
32+
uses: derek-ho/start-opensearch@v6
3333
with:
3434
opensearch-version: ${{ env.OPENSEARCH_VERSION }}
3535
security-enabled: false
36+
jdk-version: '21'
3637

3738
- name: Run Dashboard
3839
id: setup-dashboards

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@elastic/eslint-import-resolver-kibana": "link:../../packages/osd-eslint-import-resolver-opensearch-dashboards",
5050
"@testing-library/dom": "^8.11.3",
5151
"@testing-library/react-hooks": "^7.0.2",
52-
"@testing-library/user-event": "^13.1.9",
52+
"@testing-library/user-event": "^14.4.3",
5353
"@types/diff": "^5.0.2",
5454
"@types/flat": "^5.0.2",
5555
"@types/json-schema": "^7.0.11",
@@ -68,4 +68,4 @@
6868
"engines": {
6969
"yarn": "^1.21.1"
7070
}
71-
}
71+
}

public/JobHandler/components/components.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import React from "react";
66
import { render } from "@testing-library/react";
77
import { DetailLink } from "./DetailLink";
88
import { ErrorToastContentForJob } from "./ErrorToastContentForJob";
9-
import userEvent from "@testing-library/user-event";
9+
import userEventModule from "@testing-library/user-event";
1010
import { FormatResourceWithClusterInfo, FormatResourcesWithClusterInfo } from "./FormatResourceWithClusterInfo";
1111

1212
describe("<DetailLink /> spec", () => {
@@ -35,6 +35,8 @@ describe("<DetailLink /> spec", () => {
3535
});
3636

3737
describe("<ErrorToastContentForJob /> spec", () => {
38+
const userEvent = userEventModule.setup();
39+
3840
it("render with default props", async () => {
3941
const { container } = render(<ErrorToastContentForJob />);
4042
expect(container).toMatchSnapshot();

public/components/AdvancedSettings/AdvancedSettings.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
import React from "react";
77
import { fireEvent, render } from "@testing-library/react";
88
import AdvancedSettings from "./index";
9-
import userEvent from "@testing-library/user-event";
9+
import userEventModule from "@testing-library/user-event";
1010

1111
describe("<FormGenerator /> spec", () => {
12+
const userEvent = userEventModule.setup();
1213
it("render the component", () => {
1314
render(<AdvancedSettings value={{ a: "foo" }} accordionProps={{ id: "test", initialIsOpen: false }} />);
1415
expect(document.body.children).toMatchSnapshot();
@@ -31,9 +32,9 @@ describe("<FormGenerator /> spec", () => {
3132
/>
3233
);
3334
const textareaInput = document.querySelector("textarea") as HTMLTextAreaElement;
34-
userEvent.clear(textareaInput);
35-
userEvent.paste(textareaInput, '{ "test": "1" }');
36-
userEvent.click(document.body);
35+
await userEvent.clear(textareaInput);
36+
await userEvent.paste('{ "test": "1" }');
37+
await userEvent.click(document.body);
3738
expect(onChangeMock).toBeCalledTimes(1);
3839
expect(onChangeMock).toBeCalledWith({ test: "1" });
3940
});

public/components/AliasSelect/AliasSelect.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import React, { useState } from "react";
77
import { render, waitFor } from "@testing-library/react";
88
import AliasSelect, { AliasSelectProps } from "./index";
9-
import userEvent from "@testing-library/user-event";
9+
import userEventModule from "@testing-library/user-event";
1010

1111
const onChangeMock = jest.fn();
1212

@@ -25,6 +25,7 @@ const AliasSelectWithOnchange = (props: AliasSelectProps) => {
2525
};
2626

2727
describe("<AliasSelect /> spec", () => {
28+
const userEvent = userEventModule.setup();
2829
it("renders the component and remove duplicate aliases", async () => {
2930
const onOptionsChange = jest.fn();
3031
const { container } = render(

public/components/FilterGroup/FilterGroup.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
import React, { useState } from "react";
77
import { act, render, waitFor } from "@testing-library/react";
88
import FilterGroup, { IFilterGroupProps } from "./index";
9-
import userEvent from "@testing-library/user-event";
9+
import userEventModule from "@testing-library/user-event";
1010

1111
const WrappedComponent = (props: IFilterGroupProps) => {
1212
const [value, onChange] = useState<string[] | undefined>();
1313
return <FilterGroup {...props} value={value} onChange={(val) => onChange(val || [])} />;
1414
};
1515

1616
describe("<FilterGroup /> spec", () => {
17+
const userEvent = userEventModule.setup();
1718
it("render the component", async () => {
1819
const { findByPlaceholderText, getByTestId, findByText, getByText, queryByText } = render(
1920
<>
@@ -43,8 +44,8 @@ describe("<FilterGroup /> spec", () => {
4344
expect(document.querySelector("[aria-label='1 available filters']")).toBeInTheDocument();
4445
expect(document.body.children).toMatchSnapshot();
4546
});
46-
act(() => {
47-
userEvent.click(getByText("hide"));
47+
await act(async () => {
48+
await userEvent.click(getByText("hide"));
4849
});
4950
await waitFor(() => {
5051
expect(queryByText("test option")).toBeNull();

public/components/FormGenerator/FormGenerator.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import React, { forwardRef, useRef } from "react";
77
import { act, fireEvent, render, waitFor } from "@testing-library/react";
88
import { renderHook } from "@testing-library/react-hooks";
9-
import userEvent from "@testing-library/user-event";
9+
import userEventModule from "@testing-library/user-event";
1010
import { EuiButton } from "@elastic/eui";
1111
import FormGenerator, { IFormGeneratorProps, IFormGeneratorRef } from "./index";
1212
import { ValidateResults } from "../../lib/field";
@@ -75,6 +75,7 @@ const testFormFields: IFormGeneratorProps<{
7575
];
7676

7777
describe("<FormGenerator /> spec", () => {
78+
const userEvent = userEventModule.setup();
7879
it("render the component", async () => {
7980
render(<FormGenerator formFields={testFormFields} />);
8081
// EuiOverlayMask appends an element to the body so we should have three (used to be two, after upgrading appears to have 3 now), an empty div from react-test-library
@@ -106,7 +107,7 @@ describe("<FormGenerator /> spec", () => {
106107
});
107108
const { ref } = result.current;
108109
const { getByTestId } = result.current.renderResult;
109-
userEvent.type(getByTestId("form-name-test").querySelector("input") as Element, "3");
110+
await userEvent.type(getByTestId("form-name-test").querySelector("input") as Element, "3");
110111
let validateResult: ValidateResults | undefined;
111112
await act(async () => {
112113
validateResult = await ref.current?.validatePromise();
@@ -168,7 +169,7 @@ describe("<FormGenerator /> spec", () => {
168169
}
169170
);
170171

171-
userEvent.type(getByTestId("form-name-test_component").querySelector("input") as Element, "1");
172+
await userEvent.type(getByTestId("form-name-test_component").querySelector("input") as Element, "1");
172173
await waitFor(() => {
173174
expect(onChangeMock).toBeCalledWith(
174175
{

public/components/IndexDetail/IndexDetail.test.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React, { useRef, forwardRef, useState } from "react";
77
import { render, waitFor } from "@testing-library/react";
88
import { renderHook } from "@testing-library/react-hooks";
99
import IndexDetail, { IIndexDetailRef, IndexDetailProps } from "./IndexDetail";
10-
import userEvent from "@testing-library/user-event";
10+
import userEventModule from "@testing-library/user-event";
1111

1212
const IndexDetailOnChangeWrapper = forwardRef((props: Omit<IndexDetailProps, "onChange">, ref: any) => {
1313
const [value, setValue] = useState(props.value as any);
@@ -26,6 +26,8 @@ const IndexDetailOnChangeWrapper = forwardRef((props: Omit<IndexDetailProps, "on
2626
const refreshOptions: () => Promise<{ ok: true; response: any[] }> = () => Promise.resolve({ ok: true, response: [{ alias: "test" }] });
2727

2828
describe("<IndexDetail /> spec", () => {
29+
const userEvent = userEventModule.setup();
30+
2931
it("renders the component", async () => {
3032
const { container } = render(<IndexDetail docVersion="latest" refreshOptions={refreshOptions} onChange={() => {}} />);
3133
await waitFor(() => {
@@ -63,12 +65,12 @@ describe("<IndexDetail /> spec", () => {
6365
});
6466
const ref = result.current.ref;
6567
const { getByTestId, getByPlaceholderText } = result.current.container;
66-
userEvent.type(getByPlaceholderText("Specify a name for the new index."), "good_index");
68+
await userEvent.type(getByPlaceholderText("Specify a name for the new index."), "good_index");
6769
await waitFor(async () => {
6870
expect(await ref.current?.validate()).toBe(false);
6971
});
70-
userEvent.type(getByTestId("form-name-index.number_of_shards").querySelector("input") as Element, "2");
71-
userEvent.type(getByTestId("form-name-index.number_of_replicas").querySelector("input") as Element, "2");
72+
await userEvent.type(getByTestId("form-name-index.number_of_shards").querySelector("input") as Element, "2");
73+
await userEvent.type(getByTestId("form-name-index.number_of_replicas").querySelector("input") as Element, "2");
7274
await waitFor(async () => {
7375
expect(await ref.current?.validate()).toBe(true);
7476
});
@@ -97,14 +99,14 @@ describe("<IndexDetail /> spec", () => {
9799
/>
98100
);
99101
await findByDisplayValue("some_index");
100-
userEvent.click(getByDisplayValue("some_index"));
101-
userEvent.click(document.body);
102+
await userEvent.click(getByDisplayValue("some_index"));
103+
await userEvent.click(document.body);
102104
await waitFor(() => {
103105
expect(document.querySelector('[data-test-subj="comboBoxInput"] [title="test"]')).not.toBeNull();
104106
});
105-
userEvent.type(getByTestId("form-name-index.number_of_replicas").querySelector("input") as Element, "10");
106-
userEvent.click(getByDisplayValue("some_index"));
107-
userEvent.click(document.body);
107+
await userEvent.type(getByTestId("form-name-index.number_of_replicas").querySelector("input") as Element, "10");
108+
await userEvent.click(getByDisplayValue("some_index"));
109+
await userEvent.click(document.body);
108110
// The Dialog should show
109111
await waitFor(() => {
110112
expect(
@@ -113,16 +115,16 @@ describe("<IndexDetail /> spec", () => {
113115
)
114116
).toBeInTheDocument();
115117
});
116-
userEvent.click(getByTestId("simulate-confirm-confirm"));
118+
await userEvent.click(getByTestId("simulate-confirm-confirm"));
117119
await waitFor(() => {
118120
expect(getByTestId("form-name-index.number_of_replicas").querySelector("input") as Element).toHaveAttribute("value", "2");
119121
expect(queryByText("The index name matches one or more index templates")).toBeInTheDocument();
120122
});
121123

122-
userEvent.clear(getByTestId("form-name-index.number_of_replicas").querySelector("input") as Element);
123-
userEvent.type(getByTestId("form-name-index.number_of_replicas").querySelector("input") as Element, "10");
124-
userEvent.click(getByDisplayValue("some_index"));
125-
userEvent.click(document.body);
124+
await userEvent.clear(getByTestId("form-name-index.number_of_replicas").querySelector("input") as Element);
125+
await userEvent.type(getByTestId("form-name-index.number_of_replicas").querySelector("input") as Element, "10");
126+
await userEvent.click(getByDisplayValue("some_index"));
127+
await userEvent.click(document.body);
126128
// The Dialog should show
127129
await waitFor(() => {
128130
expect(
@@ -131,9 +133,9 @@ describe("<IndexDetail /> spec", () => {
131133
)
132134
).toBeInTheDocument();
133135
});
134-
userEvent.click(getByTestId("simulate-confirm-cancel"));
136+
await userEvent.click(getByTestId("simulate-confirm-cancel"));
135137
await waitFor(() => {
136-
expect(getByTestId("form-name-index.number_of_replicas").querySelector("input") as Element).toHaveAttribute("value", "10");
138+
expect(getByTestId("form-name-index.number_of_replicas").querySelector("input") as Element).toHaveAttribute("value", "2");
137139
});
138140
});
139141
});

public/components/IndexMapping/IndexMapping.test.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import React, { forwardRef, Ref, useRef, useState } from "react";
77
import { render, fireEvent, waitFor, act } from "@testing-library/react";
8-
import userEvent from "@testing-library/user-event";
8+
import userEventModule from "@testing-library/user-event";
99
import IndexMapping, { IIndexMappingsRef, IndexMappingProps, transformObjectToArray } from "./IndexMapping";
1010
import { MappingsProperties } from "../../../models/interfaces";
1111
import { renderHook } from "@testing-library/react-hooks";
@@ -26,6 +26,7 @@ const IndexMappingOnChangeWrapper = forwardRef((props: Partial<IndexMappingProps
2626
});
2727

2828
describe("<IndexMapping /> spec", () => {
29+
const userEvent = userEventModule.setup();
2930
it("renders the component", () => {
3031
const { container } = render(<IndexMapping docVersion="latest" onChange={() => {}} />);
3132
expect(container.firstChild).toMatchSnapshot();
@@ -76,24 +77,24 @@ describe("<IndexMapping /> spec", () => {
7677
expect(document.querySelector('[data-test-subj="mapping-visual-editor-0.properties.0-delete-field"]')).toBeNull();
7778

7879
// add a new field
79-
userEvent.click(getByTestId("createIndexAddFieldButton"));
80+
await userEvent.click(getByTestId("createIndexAddFieldButton"));
8081
// new field should be editable
8182
expect(getByTestId("mapping-visual-editor-1-field-name")).not.toHaveAttribute("disabled");
8283
expect(document.querySelector('[data-test-subj="mapping-visual-editor-1-delete-field"]')).not.toBeNull();
8384

8485
// empty and duplicate validation for field name
85-
userEvent.click(document.querySelector('[data-test-subj="mapping-visual-editor-1-field-name"]') as Element);
86+
await userEvent.click(document.querySelector('[data-test-subj="mapping-visual-editor-1-field-name"]') as Element);
8687
expect(getByTestId("mapping-visual-editor-1-field-name")).toHaveValue("");
8788
expect(queryByText("Field name is required, please input")).toBeNull();
88-
userEvent.type(getByTestId("mapping-visual-editor-1-field-name"), "object");
89+
await userEvent.type(getByTestId("mapping-visual-editor-1-field-name"), "object");
8990
await waitFor(() => {
9091
expect(getByText("Duplicate field name [object], please change your field name")).not.toBeNull();
9192
});
9293
await act(async () => {
9394
expect(await ref.current?.validate()).toEqual("with error");
9495
});
95-
userEvent.clear(getByTestId("mapping-visual-editor-1-field-name"));
96-
userEvent.type(getByTestId("mapping-visual-editor-1-field-name"), "new_object");
96+
await userEvent.clear(getByTestId("mapping-visual-editor-1-field-name"));
97+
await userEvent.type(getByTestId("mapping-visual-editor-1-field-name"), "new_object");
9798
await act(async () => {
9899
expect(await ref.current?.validate()).toEqual("");
99100
});
@@ -114,26 +115,26 @@ describe("<IndexMapping /> spec", () => {
114115

115116
// sub action for object
116117
expect(getByTestId("mapping-visual-editor-1-add-sub-field")).not.toBeNull();
117-
userEvent.click(getByTestId("mapping-visual-editor-1-add-sub-field"));
118+
await userEvent.click(getByTestId("mapping-visual-editor-1-add-sub-field"));
118119
// new sub field check
119120
expect((getByTestId("mapping-visual-editor-1.properties.0-field-type") as HTMLSelectElement).value).toBe("text");
120-
await waitFor(() => {
121-
userEvent.click(getByTestId("mapping-visual-editor-1.properties.0-delete-field"));
121+
await waitFor(async () => {
122+
await userEvent.click(getByTestId("mapping-visual-editor-1.properties.0-delete-field"));
122123
});
123124

124125
// add a new field
125-
userEvent.click(getByTestId("createIndexAddFieldButton"));
126+
await userEvent.click(getByTestId("createIndexAddFieldButton"));
126127
// delete the new field
127128
await waitFor(() => {});
128-
userEvent.click(getByTestId("mapping-visual-editor-2-delete-field"));
129+
await userEvent.click(getByTestId("mapping-visual-editor-2-delete-field"));
129130
expect(queryByTestId("mapping-visual-editor-2-delete-field")).toBeNull();
130131

131132
await userEvent.click(getByTestId("editorTypeJsonEditor").querySelector("input") as Element);
132133
await waitFor(() => {});
133-
userEvent.click(getByTestId("previousMappingsJsonButton"));
134+
await userEvent.click(getByTestId("previousMappingsJsonButton"));
134135
await waitFor(() => {});
135136
expect(queryByTestId("previousMappingsJsonModal-ok")).not.toBeNull();
136-
userEvent.click(getByTestId("previousMappingsJsonModal-ok"));
137+
await userEvent.click(getByTestId("previousMappingsJsonModal-ok"));
137138
await waitFor(() => {
138139
expect(queryByTestId("previousMappingsJsonModal-ok")).toBeNull();
139140
});

0 commit comments

Comments
 (0)