You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@texera.apache.org by "aglinxinyuan (via GitHub)" <gi...@apache.org> on 2026/07/20 03:10:17 UTC

[PR] test(frontend): add unit tests for PublicProjectComponent [texera]

aglinxinyuan opened a new pull request, #6575:
URL: https://github.com/apache/texera/pull/6575

   ### What changes were proposed in this PR?
   
   Adds a Vitest unit spec for `PublicProjectComponent`, which previously had no test coverage. The 10 tests cover:
   - `ngOnInit` loading `publicProjectEntries` and rendering table rows.
   - reading `disabledList` from `NZ_MODAL_DATA`.
   - `updateCheckedSet` add/remove and `onItemChecked`.
   - `onAllChecked(true/false)` checking/unchecking every entry.
   - `refreshCheckedStatus` for all-, none-, and some-selected (`checked`/`indeterminate`).
   - `addPublicProjects` calling the service with `Array.from(checkedList)` and destroying the modal on success.
   
   The component injects `NzModalRef` and `NZ_MODAL_DATA`, both provided in the TestBed.
   
   ### Any related issues, documentation, discussions?
   
   Closes #6572.
   
   ### How was this PR tested?
   
   `npx ng test --watch=false --include='**/public-project.component.spec.ts'` -> 10/10 passing. `yarn format:ci` passes.
   
   ### Was this PR authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Opus 4.8 [1M context])


-- 
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: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(frontend): add unit tests for PublicProjectComponent [texera]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #6575:
URL: https://github.com/apache/texera/pull/6575#issuecomment-5018410303

   <!-- texera-reviewer-suggestion -->
   ### Automated Reviewer Suggestions
   
   Based on the `git blame` history of the changed files, we recommend the following reviewers:
   
   - No candidates found from `git blame` history.
   


-- 
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: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(frontend): add unit tests for PublicProjectComponent [texera]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #6575:
URL: https://github.com/apache/texera/pull/6575#discussion_r3611846220


##########
frontend/src/app/dashboard/component/user/user-project/public-project/public-project.component.spec.ts:
##########
@@ -0,0 +1,185 @@
+/**
+ * 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 { ComponentFixture, TestBed } from "@angular/core/testing";
+import { NoopAnimationsModule } from "@angular/platform-browser/animations";
+import { of } from "rxjs";
+import { NZ_MODAL_DATA, NzModalRef } from "ng-zorro-antd/modal";
+import { PublicProjectComponent } from "./public-project.component";
+import { PublicProjectService } from "../../../../service/user/public-project/public-project.service";
+import { PublicProject } from "../../../../type/dashboard-project.interface";
+import { commonTestProviders } from "../../../../../common/testing/test-utils";
+
+describe("PublicProjectComponent", () => {
+  let fixture: ComponentFixture<PublicProjectComponent>;
+  let component: PublicProjectComponent;
+
+  const sampleProjects: PublicProject[] = [
+    { pid: 1, name: "Alpha", owner: "alice", creationTime: 1_000 },
+    { pid: 2, name: "Bravo", owner: "bob", creationTime: 2_000 },
+    { pid: 3, name: "Charlie", owner: "carol", creationTime: 3_000 },
+  ];
+
+  let mockPublicProjectService: {
+    getPublicProjects: ReturnType<typeof vi.fn>;
+    addPublicProjects: ReturnType<typeof vi.fn>;
+  };
+  let modalRef: { destroy: ReturnType<typeof vi.fn> };
+  let disabledList: Set<number>;
+
+  beforeEach(async () => {
+    mockPublicProjectService = {
+      getPublicProjects: vi.fn().mockReturnValue(of(sampleProjects)),
+      addPublicProjects: vi.fn().mockReturnValue(of(undefined)),
+    };
+    modalRef = { destroy: vi.fn() };
+    // pid 2 is disabled to verify the component reads disabledList from NZ_MODAL_DATA.
+    disabledList = new Set<number>([2]);
+
+    await TestBed.configureTestingModule({
+      imports: [PublicProjectComponent, NoopAnimationsModule],
+      providers: [
+        ...commonTestProviders,
+        { provide: PublicProjectService, useValue: mockPublicProjectService },
+        { provide: NzModalRef, useValue: modalRef },
+        { provide: NZ_MODAL_DATA, useValue: { disabledList } },
+      ],
+    }).compileComponents();
+
+    fixture = TestBed.createComponent(PublicProjectComponent);
+    component = fixture.componentInstance;
+  });
+
+  afterEach(() => {
+    fixture?.destroy();
+    document.querySelectorAll(".cdk-overlay-container").forEach(c => (c.innerHTML = ""));
+  });
+
+  it("should create and read disabledList from NZ_MODAL_DATA", () => {
+    fixture.detectChanges();
+    expect(component).toBeTruthy();
+    expect(component.disabledList).toBe(disabledList);
+    expect(component.disabledList.has(2)).toBe(true);
+  });
+
+  it("ngOnInit loads publicProjectEntries from getPublicProjects and renders the rows", () => {
+    fixture.detectChanges();
+    expect(mockPublicProjectService.getPublicProjects).toHaveBeenCalledTimes(1);
+    expect(component.publicProjectEntries).toEqual(sampleProjects);
+
+    const rows = (fixture.nativeElement as HTMLElement).querySelectorAll("tbody tr");
+    expect(rows.length).toBe(sampleProjects.length);
+    const text = (fixture.nativeElement as HTMLElement).textContent ?? "";
+    expect(text).toContain("Alpha");
+    expect(text).toContain("alice");
+    expect(text).toContain("Selected 0 items");
+  });
+
+  it("updateCheckedSet adds an id when checked and removes it when unchecked", () => {
+    fixture.detectChanges();
+
+    component.updateCheckedSet(1, true);
+    expect(component.checkedList.has(1)).toBe(true);
+
+    component.updateCheckedSet(1, false);
+    expect(component.checkedList.has(1)).toBe(false);
+  });
+
+  it("onItemChecked updates the set and refreshes the checked status", () => {
+    fixture.detectChanges();
+    const refreshSpy = vi.spyOn(component, "refreshCheckedStatus");
+
+    component.onItemChecked(1, true);
+
+    expect(component.checkedList.has(1)).toBe(true);
+    expect(refreshSpy).toHaveBeenCalledTimes(1);
+    // Only 1 of 3 selected => indeterminate, not fully checked.
+    expect(component.checked).toBe(false);
+    expect(component.indeterminate).toBe(true);
+
+    component.onItemChecked(1, false);
+    expect(component.checkedList.has(1)).toBe(false);
+    expect(refreshSpy).toHaveBeenCalledTimes(2);
+    expect(component.indeterminate).toBe(false);
+  });
+
+  it("onAllChecked(true) selects every entry", () => {
+    fixture.detectChanges();
+
+    component.onAllChecked(true);
+
+    sampleProjects.forEach(p => expect(component.checkedList.has(p.pid)).toBe(true));
+    expect(component.checkedList.size).toBe(sampleProjects.length);
+    expect(component.checked).toBe(true);
+    expect(component.indeterminate).toBe(false);
+  });
+
+  it("onAllChecked(false) unchecks all entries", () => {
+    fixture.detectChanges();
+    component.onAllChecked(true);
+
+    component.onAllChecked(false);
+
+    expect(component.checkedList.size).toBe(0);
+    expect(component.checked).toBe(false);
+    expect(component.indeterminate).toBe(false);
+  });
+
+  describe("refreshCheckedStatus", () => {
+    beforeEach(() => fixture.detectChanges());
+
+    it("all selected => checked true, indeterminate false", () => {
+      sampleProjects.forEach(p => component.checkedList.add(p.pid));
+
+      component.refreshCheckedStatus();
+
+      expect(component.checked).toBe(true);
+      expect(component.indeterminate).toBe(false);
+    });
+
+    it("none selected => checked false, indeterminate false", () => {
+      component.checkedList.clear();
+
+      component.refreshCheckedStatus();
+
+      expect(component.checked).toBe(false);
+      expect(component.indeterminate).toBe(false);
+    });
+
+    it("some selected => checked false, indeterminate true", () => {
+      component.checkedList.add(sampleProjects[0].pid);
+
+      component.refreshCheckedStatus();
+
+      expect(component.checked).toBe(false);
+      expect(component.indeterminate).toBe(true);
+    });
+  });
+
+  it("addPublicProjects calls the service with the checked ids and destroys the modal on success", () => {
+    fixture.detectChanges();
+    component.checkedList = new Set<number>([1, 3]);
+
+    component.addPublicProjects();
+
+    expect(mockPublicProjectService.addPublicProjects).toHaveBeenCalledTimes(1);
+    expect(mockPublicProjectService.addPublicProjects).toHaveBeenCalledWith([1, 3]);

Review Comment:
   The service call assertion is order-sensitive (`[1, 3]`), but the component passes `Array.from(Set)` and the insertion order can vary based on how a user checks items. This makes the test unnecessarily brittle even though the behavior being tested is the set of ids, not their ordering.



-- 
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: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(frontend): add unit tests for PublicProjectComponent [texera]

Posted by "aglinxinyuan (via GitHub)" <gi...@apache.org>.
aglinxinyuan merged PR #6575:
URL: https://github.com/apache/texera/pull/6575


-- 
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: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(frontend): add unit tests for PublicProjectComponent [texera]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #6575:
URL: https://github.com/apache/texera/pull/6575#issuecomment-5018445789

   ## [Codecov](https://app.codecov.io/gh/apache/texera/pull/6575?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 73.05%. Comparing base ([`4f82883`](https://app.codecov.io/gh/apache/texera/commit/4f828836c35df5bfb70983f76aeee7bf18969c06?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`a7859ad`](https://app.codecov.io/gh/apache/texera/commit/a7859ad035877f1ed5c3d51bdebcc4f12fb3aca5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 4 commits behind head on main.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##               main    #6575      +/-   ##
   ============================================
   + Coverage     73.02%   73.05%   +0.02%     
     Complexity     3439     3439              
   ============================================
     Files          1145     1150       +5     
     Lines         45129    45336     +207     
     Branches       4975     4996      +21     
   ============================================
   + Hits          32956    33119     +163     
   - Misses        10476    10514      +38     
   - Partials       1697     1703       +6     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/texera/pull/6575/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | *Carryforward flag |
   |---|---|---|---|
   | [access-control-service](https://app.codecov.io/gh/apache/texera/pull/6575/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `70.00% <ø> (ø)` | | Carriedforward from [4f82883](https://app.codecov.io/gh/apache/texera/commit/4f828836c35df5bfb70983f76aeee7bf18969c06?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [agent-service](https://app.codecov.io/gh/apache/texera/pull/6575/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `76.76% <ø> (ø)` | | Carriedforward from [4f82883](https://app.codecov.io/gh/apache/texera/commit/4f828836c35df5bfb70983f76aeee7bf18969c06?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [amber](https://app.codecov.io/gh/apache/texera/pull/6575/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `66.82% <ø> (ø)` | | Carriedforward from [4f82883](https://app.codecov.io/gh/apache/texera/commit/4f828836c35df5bfb70983f76aeee7bf18969c06?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [computing-unit-managing-service](https://app.codecov.io/gh/apache/texera/pull/6575/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `17.72% <ø> (ø)` | | Carriedforward from [4f82883](https://app.codecov.io/gh/apache/texera/commit/4f828836c35df5bfb70983f76aeee7bf18969c06?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [config-service](https://app.codecov.io/gh/apache/texera/pull/6575/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `66.66% <ø> (ø)` | | Carriedforward from [4f82883](https://app.codecov.io/gh/apache/texera/commit/4f828836c35df5bfb70983f76aeee7bf18969c06?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [file-service](https://app.codecov.io/gh/apache/texera/pull/6575/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `66.80% <ø> (ø)` | | Carriedforward from [4f82883](https://app.codecov.io/gh/apache/texera/commit/4f828836c35df5bfb70983f76aeee7bf18969c06?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [frontend](https://app.codecov.io/gh/apache/texera/pull/6575/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `74.97% <ø> (+0.04%)` | :arrow_up: | |
   | [notebook-migration-service](https://app.codecov.io/gh/apache/texera/pull/6575/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `78.94% <ø> (ø)` | | Carriedforward from [4f82883](https://app.codecov.io/gh/apache/texera/commit/4f828836c35df5bfb70983f76aeee7bf18969c06?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [pyamber](https://app.codecov.io/gh/apache/texera/pull/6575/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `91.79% <ø> (ø)` | | Carriedforward from [4f82883](https://app.codecov.io/gh/apache/texera/commit/4f828836c35df5bfb70983f76aeee7bf18969c06?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [workflow-compiling-service](https://app.codecov.io/gh/apache/texera/pull/6575/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.14% <ø> (ø)` | | Carriedforward from [4f82883](https://app.codecov.io/gh/apache/texera/commit/4f828836c35df5bfb70983f76aeee7bf18969c06?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   *This pull request uses carry forward flags. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/texera/pull/6575?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org