akashchamp commented on code in PR #712:
URL: https://github.com/apache/shenyu-dashboard/pull/712#discussion_r4233891653


##########
src/routes/Plugin/Common/dictState.test.js:
##########
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import React from "react";
+import { act, fireEvent, render, screen } from "@testing-library/react";
+import { Form } from "antd";
+import ConnectedSelector from "./Selector";
+import ConnectedRule from "./Rule";
+
+let importModalProps;
+
+jest.mock("../../../utils/IntlUtils", () => ({
+  getIntlContent: (key) => key,
+}));
+jest.mock("./SelectorCopy", () => () => null);
+jest.mock("./RuleCopy", () => () => null);
+jest.mock("../Discovery/DiscoveryUpstreamTable.js", () => () => null);
+jest.mock("../Discovery/DiscoveryImportModal", () => (props) => {
+  importModalProps = props;
+  return null;
+});
+
+// Form.create() hoists the class unwrapped by dva connect(), so the modal can 
be
+// mounted with a real form but without a store.
+const unwrap = (component) => Form.create()(component.WrappedComponent);
+const Selector = unwrap(ConnectedSelector);
+const Rule = unwrap(ConnectedRule);
+
+const matchModeDics = [
+  { dictValue: "0", dictName: "and" },
+  { dictValue: "1", dictName: "or" },
+];
+
+// Hold dictionary requests until the test resolves them, like a slow backend.
+const createDispatch = () => {
+  const pending = {};
+  const dispatch = jest.fn(({ type, payload }) => {
+    if (type === "shenyuDict/fetchByType") {
+      pending[payload.type] = payload.callBack;
+    }
+  });
+  const resolve = (type, dics) => act(() => pending[type](dics));
+  return { dispatch, resolve };
+};
+
+const matchModeSelection = () =>
+  document.querySelector("#matchMode .ant-select-selection-selected-value")
+    .textContent;

Review Comment:
   The Select in this antd v3 form does not expose a role or label to query, 
and the component has no data-testid, so the test reads the rendered selection 
text. I would rather not add test-only attributes to production code for this; 
the selector is pinned to the antd version in package-lock.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to