Copilot commented on code in PR #6365:
URL: https://github.com/apache/texera/pull/6365#discussion_r3565851227


##########
frontend/src/app/common/formly/formly-utils.spec.ts:
##########
@@ -0,0 +1,87 @@
+/**
+ * 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 { FormlyFieldConfig } from "@ngx-formly/core";
+import { createShouldHideFieldFunc, getFieldByName, setHideExpression } from 
"./formly-utils";
+
+describe("getFieldByName", () => {
+  it("returns the field whose key matches the name", () => {
+    const a: FormlyFieldConfig = { key: "a" };
+    const b: FormlyFieldConfig = { key: "b" };
+    expect(getFieldByName("b", [a, b])).toBe(b);
+  });
+
+  it("returns undefined when no field matches", () => {
+    expect(getFieldByName("z", [{ key: "a" }])).toBeUndefined();
+  });
+
+  it("returns the first match when several fields share a key", () => {
+    const first: FormlyFieldConfig = { key: "dup" };
+    const second: FormlyFieldConfig = { key: "dup" };
+    expect(getFieldByName("dup", [first, second])).toBe(first);
+  });
+});
+
+describe("setHideExpression", () => {
+  it("sets the hide expression on each named field that exists", () => {
+    const a: FormlyFieldConfig = { key: "a" };
+    const b: FormlyFieldConfig = { key: "b" };
+    setHideExpression(["a", "b"], [a, b], "toggle");
+    expect(a.expressions).toEqual({ hide: "!field.parent.model.toggle" });
+    expect(b.expressions).toEqual({ hide: "!field.parent.model.toggle" });
+  });
+
+  it("is a no-op for names that are not present", () => {
+    const a: FormlyFieldConfig = { key: "a" };
+    setHideExpression(["missing"], [a], "toggle");
+    expect(a.expressions).toBeUndefined();
+  });
+});
+
+describe("createShouldHideFieldFunc", () => {
+  const fieldWithModel = (model: any): FormlyFieldConfig => ({ parent: { model 
} }) as FormlyFieldConfig;
+
+  it("returns false when the parent model is missing", () => {
+    const hide = createShouldHideFieldFunc("target", "equals", "x", false);
+    expect(hide(undefined)).toBe(false);
+    expect(hide({} as FormlyFieldConfig)).toBe(false);
+  });

Review Comment:
   This test triggers `console.debug` from `createShouldHideFieldFunc` when 
`field?.parent?.model` is missing (see formly-utils.ts), which adds noise to 
test output and can make CI logs harder to read. Consider stubbing 
`console.debug` within this test (and optionally asserting the call count) so 
the suite stays quiet.



-- 
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