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


##########
frontend/src/app/common/service/user/registration-request-modal/registration-request-modal.component.spec.ts:
##########
@@ -0,0 +1,116 @@
+/**
+ * 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 { TemplateRef } from "@angular/core";
+import { ComponentFixture, TestBed } from "@angular/core/testing";
+import { NoopAnimationsModule } from "@angular/platform-browser/animations";
+import { NZ_MODAL_DATA } from "ng-zorro-antd/modal";
+
+import { RegistrationRequestModalComponent } from 
"./registration-request-modal.component";
+
+type ModalData = { uid: number; email: string; name: string };
+
+function createFixture(data: ModalData): 
ComponentFixture<RegistrationRequestModalComponent> {
+  TestBed.configureTestingModule({
+    imports: [RegistrationRequestModalComponent, NoopAnimationsModule],

Review Comment:
   `ModalData` is typed with required `name`/`email`, but the spec 
intentionally exercises missing/nullable fields. This forces unsafe casts later 
and makes it harder to add a `NZ_MODAL_DATA = null` case (which the component 
explicitly supports via optional chaining). Consider widening the helper’s 
input type to allow optional fields and `null`.



##########
frontend/src/app/common/service/user/registration-request-modal/registration-request-modal.component.spec.ts:
##########
@@ -0,0 +1,116 @@
+/**
+ * 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 { TemplateRef } from "@angular/core";
+import { ComponentFixture, TestBed } from "@angular/core/testing";
+import { NoopAnimationsModule } from "@angular/platform-browser/animations";
+import { NZ_MODAL_DATA } from "ng-zorro-antd/modal";
+
+import { RegistrationRequestModalComponent } from 
"./registration-request-modal.component";
+
+type ModalData = { uid: number; email: string; name: string };
+
+function createFixture(data: ModalData): 
ComponentFixture<RegistrationRequestModalComponent> {
+  TestBed.configureTestingModule({
+    imports: [RegistrationRequestModalComponent, NoopAnimationsModule],
+    providers: [{ provide: NZ_MODAL_DATA, useValue: data }],
+  });
+  const fixture = TestBed.createComponent(RegistrationRequestModalComponent);
+  fixture.detectChanges();
+  return fixture;
+}
+
+describe("RegistrationRequestModalComponent", () => {
+  afterEach(() => {
+    TestBed.resetTestingModule();
+  });
+
+  describe("constructor", () => {
+    it("hydrates name and email from injected NZ_MODAL_DATA", () => {
+      const fixture = createFixture({ uid: 7, name: "Ada Lovelace", email: 
"[email protected]" });
+      const component = fixture.componentInstance;
+
+      expect(component.name).toBe("Ada Lovelace");
+      expect(component.email).toBe("[email protected]");
+    });
+
+    it("falls back to empty strings when data fields are missing", () => {
+      const fixture = createFixture({
+        uid: 7,
+        name: undefined as unknown as string,
+        email: undefined as unknown as string,
+      });
+      const component = fixture.componentInstance;
+
+      expect(component.name).toBe("");
+      expect(component.email).toBe("");
+    });
+

Review Comment:
   The constructor uses `data?.name` / `data?.email`, so `NZ_MODAL_DATA` being 
`null` is a supported runtime scenario. The current test simulates missing 
fields via `undefined as unknown as string`; you can avoid the unsafe casts by 
passing an object without those keys, and add an explicit `null`-data test to 
lock in the optional-chaining behavior.



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