mengw15 commented on code in PR #6538:
URL: https://github.com/apache/texera/pull/6538#discussion_r3609570616
##########
frontend/src/app/dashboard/component/user/user-project/user-project-list-item/user-project-list-item.component.spec.ts:
##########
@@ -80,13 +85,133 @@ describe("UserProjectListItemComponent", () => {
beforeEach(() => {
hostFixture = TestBed.createComponent(TestHostComponent);
- hostFixture.componentInstance.entry = testProject;
+ // Clone so per-test mutations (saveProjectName/Description mutate entry
in place)
+ // don't leak into other tests through the shared testProject fixture.
+ hostFixture.componentInstance.entry = { ...testProject };
hostFixture.componentInstance.editable = true;
hostFixture.detectChanges();
component = hostFixture.componentInstance.inner;
+ userProjectService = TestBed.inject(UserProjectService);
+ modalService = TestBed.inject(NzModalService);
+ notificationService = TestBed.inject(NotificationService);
+ });
+
+ afterEach(() => {
+ vi.restoreAllMocks();
});
it("should create", () => {
expect(component).toBeTruthy();
});
+
+ describe("updateProjectColor", () => {
+ it("persists a valid color and updates local state", () => {
+ const spy = vi.spyOn(userProjectService,
"updateProjectColor").mockReturnValue(of({} as Response));
+ component.color = "#123456";
+
+ component.updateProjectColor();
+
+ expect(spy).toHaveBeenCalledWith(1, "123456");
+ expect(component.color).toBe("123456");
+ expect(component.entry.color).toBe("123456");
+ expect(component.editingColor).toBe(false);
+ });
+
+ it("rejects an invalid HEX color and does not call the service", () => {
+ const spy = vi.spyOn(userProjectService, "updateProjectColor");
+ const errorSpy = vi.spyOn(notificationService,
"error").mockImplementation(() => {});
+ component.color = "#zzz";
+
+ component.updateProjectColor();
+
+ expect(errorSpy).toHaveBeenCalled();
+ expect(spy).not.toHaveBeenCalled();
+ });
+
+ it("is a no-op when the item is not editable", () => {
+ const spy = vi.spyOn(userProjectService, "updateProjectColor");
+ component.editable = false;
+ component.color = "#123456";
+
+ component.updateProjectColor();
+
+ expect(spy).not.toHaveBeenCalled();
+ });
+ });
+
+ describe("removeProjectColor", () => {
+ it("deletes the color and resets local state", () => {
+ const spy = vi.spyOn(userProjectService,
"deleteProjectColor").mockReturnValue(of({} as Response));
+
+ component.removeProjectColor();
+
+ expect(spy).toHaveBeenCalledWith(1);
+ expect(component.color).toBe("#ffffff");
+ expect(component.entry.color).toBeNull();
+ expect(component.editingColor).toBe(false);
+ });
Review Comment:
Good catch — addressed by starting the test from a non-default state (`color
= "#123456"`, `entry.color = "123456"`, `editingColor = true`) so the reset
assertions now verify an actual state transition. Confirmed it fails if the
reset is removed.
--
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]