Copilot commented on code in PR #7417:
URL: https://github.com/apache/texera/pull/7417#discussion_r3739735947
##########
frontend/src/app/dashboard/component/user/user-dataset/user-dataset.component.spec.ts:
##########
@@ -368,3 +382,131 @@ describe("UserDatasetComponent", () => {
});
});
});
+/**
+ * The existing suite constructs the component directly, so its template has
never been rendered.
+ * These tests mount it for real: the view toggle, the sort wiring and the
bindings handed to the
+ * results list all live only in the template.
+ */
+describe("UserDatasetComponent rendering", () => {
+ let fixture: ComponentFixture<UserDatasetComponent>;
+ let component: UserDatasetComponent;
+ let searchSpy: ReturnType<typeof vi.fn>;
+
+ beforeEach(async () => {
+ // viewType is seeded from localStorage at construction, so a view chosen
by an earlier test
+ // would leak into this one.
+ localStorage.clear();
+ searchSpy = vi.fn(() => of({ entries: [], more: false, hasMismatch: false
}));
+ await TestBed.configureTestingModule({
+ imports: [UserDatasetComponent, ...commonTestImports],
+ providers: [
+ { provide: NzModalService, useValue: { create: vi.fn() } },
+ { provide: UserService, useClass: StubUserService },
+ { provide: SearchService, useValue: { executeSearch: searchSpy } },
+ { provide: DatasetService, useValue: { deleteDatasets: vi.fn(() =>
of({} as Response)) } },
+ { provide: NzMessageService, useValue: { warning: vi.fn() } },
+ // ng-zorro defaults to zh-cn and throws NG0701 without locale data;
the app registers en_US.
+ { provide: NZ_I18N, useValue: en_US },
+ provideRouter([]),
+ ...commonTestProviders,
+ ],
+ }).compileComponents();
+
+ fixture = TestBed.createComponent(UserDatasetComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
+ /**
+ * The two view-mode buttons, found by title: the sort button renders its
own <button> into the
+ * same nz-space-compact, so a positional selector picks that up first.
+ */
+ function viewButtons(): { list: HTMLButtonElement; card: HTMLButtonElement }
{
+ const host = fixture.nativeElement as HTMLElement;
+ return {
+ list: host.querySelector<HTMLButtonElement>('button[title="List
View"]')!,
+ card: host.querySelector<HTMLButtonElement>('button[title="Card
View"]')!,
+ };
Review Comment:
The non-null assertions on querySelector() will throw a generic 'Cannot read
properties of null' if the template changes, which makes failures harder to
diagnose. Add an explicit assertion/guard so the failure clearly reports which
button is missing.
This issue also appears on line 497 of the same file.
##########
frontend/src/app/dashboard/component/user/user-dataset/user-dataset.component.spec.ts:
##########
@@ -368,3 +382,131 @@ describe("UserDatasetComponent", () => {
});
});
});
+/**
+ * The existing suite constructs the component directly, so its template has
never been rendered.
+ * These tests mount it for real: the view toggle, the sort wiring and the
bindings handed to the
+ * results list all live only in the template.
+ */
+describe("UserDatasetComponent rendering", () => {
+ let fixture: ComponentFixture<UserDatasetComponent>;
+ let component: UserDatasetComponent;
+ let searchSpy: ReturnType<typeof vi.fn>;
+
+ beforeEach(async () => {
+ // viewType is seeded from localStorage at construction, so a view chosen
by an earlier test
+ // would leak into this one.
+ localStorage.clear();
+ searchSpy = vi.fn(() => of({ entries: [], more: false, hasMismatch: false
}));
Review Comment:
Using localStorage.clear() is overly broad for test isolation and can
unintentionally wipe keys used by other helpers/specs in the same environment.
Prefer removing only the view-mode key this component uses.
--
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]