aglinxinyuan commented on code in PR #7417:
URL: https://github.com/apache/texera/pull/7417#discussion_r3740199028


##########
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:
   Fixed in 28e0fa72c6 — replying here too so this thread carries its own 
answer rather than pointing at the neighbouring one.
   
   Both call sites now assert before dereferencing, with a message naming the 
control that could not be found:
   
   ```ts
   const list = host.querySelector<HTMLButtonElement>('button[title="List 
View"]');
   const card = host.querySelector<HTMLButtonElement>('button[title="Card 
View"]');
   expect(list, 'no button titled "List View"').not.toBeNull();
   expect(card, 'no button titled "Card View"').not.toBeNull();
   ```
   
   and the same for the create button. A renamed `title` or class now fails as 
"no button titled …" instead of a null dereference several lines later.
   
   That covers the second occurrence you flagged as well — it was the 
create-button lookup, which had the same `!` on it.



-- 
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]

Reply via email to