Copilot commented on code in PR #6538:
URL: https://github.com/apache/texera/pull/6538#discussion_r3609556857
##########
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:
The `removeProjectColor` test currently starts from the default state
(`component.color === "#ffffff"` and `entry.color === null`), so it would still
pass even if the method stopped resetting local state (as long as the service
call still happens). Setting a non-default initial `color`/`entry.color` (and
optionally `editingColor`) before calling `removeProjectColor()` makes this
test actually validate the reset behavior it claims to cover.
--
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]