From 9390eb07ea13779847ff95a344bca76dcccb362f Mon Sep 17 00:00:00 2001 From: Neilk1021 Date: Mon, 8 Jun 2026 17:14:34 -0700 Subject: [PATCH 1/3] test: add unit tests for SortButtonComponent (#5463) --- .../sort-button/sort-button.component.spec.ts | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 frontend/src/app/dashboard/component/user/sort-button/sort-button.component.spec.ts diff --git a/frontend/src/app/dashboard/component/user/sort-button/sort-button.component.spec.ts b/frontend/src/app/dashboard/component/user/sort-button/sort-button.component.spec.ts new file mode 100644 index 00000000000..2c4487aa0c4 --- /dev/null +++ b/frontend/src/app/dashboard/component/user/sort-button/sort-button.component.spec.ts @@ -0,0 +1,73 @@ +/** + * 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 {SortButtonComponent} from "./sort-button.component"; +import {SortMethod} from "../../../type/sort-method"; +import {describe, beforeEach, it, expect, vi} from "vitest"; + +describe("SortButtonComponent", () => { + let component: SortButtonComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [SortButtonComponent] + }).compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(SortButtonComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it("should create the component with correct default sorting method", () => { + expect(component).toBeTruthy(); + expect(component.sortMethod).toBe(SortMethod.EditTimeDesc); + }); + + it("should handle lastSort() correctly", () => { + const emitSpy = vi.spyOn(component.sortMethodChange, "emit"); + component.lastSort(); + expect(component.sortMethod).toBe(SortMethod.EditTimeDesc); + expect(emitSpy).toHaveBeenCalledWith(SortMethod.EditTimeDesc); + }); + + it("should handle dateSort() correctly", () => { + const emitSpy = vi.spyOn(component.sortMethodChange, "emit"); + component.dateSort(); + expect(component.sortMethod).toBe(SortMethod.CreateTimeDesc); + expect(emitSpy).toHaveBeenCalledWith(SortMethod.CreateTimeDesc); + }); + + it("should handle ascSort() correctly", () => { + const emitSpy = vi.spyOn(component.sortMethodChange, "emit"); + component.ascSort(); + expect(component.sortMethod).toBe(SortMethod.NameAsc); + expect(emitSpy).toHaveBeenCalledWith(SortMethod.NameAsc); + }); + + it("should handle dscSort() correctly", () => { + const emitSpy = vi.spyOn(component.sortMethodChange, "emit"); + component.dscSort(); + expect(component.sortMethod).toBe(SortMethod.NameDesc); + expect(emitSpy).toHaveBeenCalledWith(SortMethod.NameDesc); + }); +}); From 603e2ec9dade2f1cafba717776ba6872b0c886be Mon Sep 17 00:00:00 2001 From: Neilk1021 Date: Mon, 8 Jun 2026 22:53:23 -0700 Subject: [PATCH 2/3] style: fix linting and prettier formatting --- .../user/sort-button/sort-button.component.spec.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/dashboard/component/user/sort-button/sort-button.component.spec.ts b/frontend/src/app/dashboard/component/user/sort-button/sort-button.component.spec.ts index 2c4487aa0c4..8e183269e3a 100644 --- a/frontend/src/app/dashboard/component/user/sort-button/sort-button.component.spec.ts +++ b/frontend/src/app/dashboard/component/user/sort-button/sort-button.component.spec.ts @@ -17,10 +17,10 @@ * under the License. */ -import {ComponentFixture, TestBed} from "@angular/core/testing"; -import {SortButtonComponent} from "./sort-button.component"; -import {SortMethod} from "../../../type/sort-method"; -import {describe, beforeEach, it, expect, vi} from "vitest"; +import { ComponentFixture, TestBed } from "@angular/core/testing"; +import { SortButtonComponent } from "./sort-button.component"; +import { SortMethod } from "../../../type/sort-method"; +import { describe, beforeEach, it, expect, vi } from "vitest"; describe("SortButtonComponent", () => { let component: SortButtonComponent; @@ -28,7 +28,7 @@ describe("SortButtonComponent", () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [SortButtonComponent] + imports: [SortButtonComponent], }).compileComponents(); }); From 2f2cfb27f146ebe5aa8ac6a9dcab2abadc800e92 Mon Sep 17 00:00:00 2001 From: Neilk1021 Date: Mon, 8 Jun 2026 23:28:56 -0700 Subject: [PATCH 3/3] style: remove UTF-8 BOM and redundant vitest imports --- .../component/user/sort-button/sort-button.component.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/src/app/dashboard/component/user/sort-button/sort-button.component.spec.ts b/frontend/src/app/dashboard/component/user/sort-button/sort-button.component.spec.ts index 8e183269e3a..f007982cfd2 100644 --- a/frontend/src/app/dashboard/component/user/sort-button/sort-button.component.spec.ts +++ b/frontend/src/app/dashboard/component/user/sort-button/sort-button.component.spec.ts @@ -1,4 +1,4 @@ -/** +/** * 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 @@ -20,7 +20,6 @@ import { ComponentFixture, TestBed } from "@angular/core/testing"; import { SortButtonComponent } from "./sort-button.component"; import { SortMethod } from "../../../type/sort-method"; -import { describe, beforeEach, it, expect, vi } from "vitest"; describe("SortButtonComponent", () => { let component: SortButtonComponent;