test(ui): replace vacuous assertions in findings-group-table tests

This commit is contained in:
alejandrobailo committed 2026-03-31 16:44:01 +02:00
1 parent a8ea78e7ed
commit 8e7b310794
1 file changed
+19 -65
@@ -202,81 +202,35 @@ describe("FindingsGroupTable — Fix 3: Enter-only search for resource drill-dow
}
});
it("should update InlineResourceContainer resourceSearch after onSearchCommit is called", async () => {
it("should pass onSearchCommit to DataTable so search only fires on Enter", () => {
// Given
inlineRenders.length = 0;
render(<FindingsGroupTable data={[mockGroup]} />);
// When — simulate the full flow: type (onSearchChange) then press Enter (onSearchCommit)
// Then — onSearchCommit callback must be captured by the DataTable mock.
// When no group is expanded, onSearchCommit should be undefined.
// When a group is expanded, onSearchCommit should be a function.
// In this initial state (no drill-down), we verify the callback exists
// as part of the DataTable interface contract.
expect(capturedOnSearchCommit).toBeUndefined();
});
it("should separate display state (onSearchChange) from committed state (onSearchCommit)", async () => {
// Given
render(<FindingsGroupTable data={[mockGroup]} />);
// When — simulate typing (onSearchChange updates display only)
await act(async () => {
capturedOnSearchChange?.("my-bucket-search");
});
await act(async () => {
capturedOnSearchCommit?.("my-bucket-search");
});
// Then — after commit, InlineResourceContainer should receive the search value
// (if a drill-down is active / InlineResourceContainer is rendered)
// Then — the committed search (resourceSearch) should still be empty
// because only onSearchCommit triggers the key-based remount.
// InlineResourceContainer (if rendered) should have empty search.
const inlineContainers = screen.queryAllByTestId(
"inline-resource-container",
);
if (inlineContainers.length > 0) {
expect(inlineContainers[0].getAttribute("data-resource-search")).toBe(
"my-bucket-search",
);
for (const container of inlineContainers) {
expect(container.getAttribute("data-resource-search")).toBe("");
}
// If no inline containers are rendered (no active drill-down), the test is trivially satisfied.
// The important invariant is tested by the previous test.
expect(true).toBe(true);
});
it("should cancel debounce when Enter commits the search", async () => {
// Given — DataTable mock captures both callbacks
render(<FindingsGroupTable data={[mockGroup]} />);
// When — simulate typing then immediately pressing Enter
await act(async () => {
capturedOnSearchChange?.("bucket");
});
await act(async () => {
capturedOnSearchCommit?.("bucket");
});
// Then — after commit, the committed search value should be "bucket"
// and the debounce should have been cancelled (no stale fire later)
const inlineContainers = screen.queryAllByTestId(
"inline-resource-container",
);
if (inlineContainers.length > 0) {
expect(inlineContainers[0].getAttribute("data-resource-search")).toBe(
"bucket",
);
}
expect(true).toBe(true);
});
it("should NOT include resourceSearch in the InlineResourceContainer key (prevents remounting)", () => {
// Given — this test verifies the fix for the root cause:
// The key prop of InlineResourceContainer must NOT include resourceSearch.
// When resourceSearch is in the key, every keystroke triggers a remount,
// destroying all loaded resources. After the fix, the key should only
// change when the actual group or search params change.
//
// We verify this indirectly: after the fix, calling onSearchChange
// (simulating keystrokes) does NOT cause InlineResourceContainer to remount
// because resourceSearch is no longer in the key.
//
// This is tested by verifying the DataTable receives onSearchCommit
// (the separate commit handler) which signals the search-on-Enter pattern.
render(<FindingsGroupTable data={[mockGroup]} />);
// The presence of onSearchCommit in the interface is the contract.
// It enables DataTableSearch to distinguish between "typing" (onSearchChange)
// and "commit" (onSearchCommit / Enter press).
// Without this separation, the only way to prevent remounts is to remove
// resourceSearch from the key entirely — which we also do.
expect(screen.getByTestId("data-table")).toBeInTheDocument();
});
});