-
Notifications
You must be signed in to change notification settings - Fork 0
fix: prevent graph chart infinite loading loop on fullscreen expand (#313) #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
5734e15
fix: prevent graph chart infinite loading loop on fullscreen expand (…
alfredorubin96 4744a43
fix: make connector error click E2E test less brittle on CI
alfredorubin96 99b190a
test: add coverage for graph chart fullscreen fix to meet SonarCloud …
alfredorubin96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| /** | ||
| * CardContainer tests — focused on the widgetIdSuffix prop that prevents | ||
| * graph store conflicts when two CardContainers render the same widget | ||
| * (e.g. normal view + fullscreen dialog). | ||
| */ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
| import type { DashboardWidget } from "@/lib/db/schema"; | ||
|
|
||
| // ── Capture ChartRenderer props to verify effectiveWidgetId ─────────── | ||
| let capturedChartProps: Record<string, unknown> = {}; | ||
|
|
||
| vi.mock("@/components/chart-renderer", () => ({ | ||
| ChartRenderer: (props: Record<string, unknown>) => { | ||
| capturedChartProps = props; | ||
| return <div data-testid="chart-renderer" />; | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock("@/hooks/use-widget-query", () => ({ | ||
| useWidgetQuery: () => ({ | ||
| isPending: false, | ||
| isError: false, | ||
| data: null, | ||
| fetchStatus: "idle", | ||
| missingParams: [], | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock("@/hooks/use-click-action", () => ({ | ||
| useClickAction: () => ({ | ||
| handleChartClick: undefined, | ||
| hasClickAction: false, | ||
| clickableColumns: [], | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock("@/stores/parameter-store", () => ({ | ||
| useParameterValues: () => ({}), | ||
| })); | ||
|
|
||
| vi.mock("@/lib/chart-registry", () => ({ | ||
| getChartConfig: (type: string) => { | ||
| if (type === "bar" || type === "markdown") { | ||
| return { | ||
| type, | ||
| label: type, | ||
| transform: (d: unknown) => d, | ||
| transformWithMapping: (d: unknown) => d, | ||
| supportsColumnMapping: false, | ||
| validate: () => null, | ||
| }; | ||
| } | ||
| return null; | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock("@/lib/resolve-cache-options", () => ({ | ||
| resolveCacheOptions: () => ({ staleTime: 0, gcTime: 0 }), | ||
| })); | ||
|
|
||
| vi.mock("@/lib/scroll-to-widget", () => ({ | ||
| scrollAndHighlight: () => false, | ||
| })); | ||
|
|
||
| vi.mock("@neoboard/components", () => ({ | ||
| Skeleton: () => <div data-testid="skeleton" />, | ||
| Alert: ({ children }: { children: React.ReactNode }) => <div>{children}</div>, | ||
| AlertDescription: ({ children }: { children: React.ReactNode }) => ( | ||
| <div>{children}</div> | ||
| ), | ||
| AlertTitle: ({ children }: { children: React.ReactNode }) => ( | ||
| <div>{children}</div> | ||
| ), | ||
| Button: ({ | ||
| children, | ||
| onClick, | ||
| }: { | ||
| children: React.ReactNode; | ||
| onClick?: () => void; | ||
| }) => <button onClick={onClick}>{children}</button>, | ||
| EmptyState: ({ | ||
| title, | ||
| description, | ||
| }: { | ||
| title: string; | ||
| description?: string; | ||
| }) => ( | ||
| <div data-testid="empty-state"> | ||
| <span>{title}</span> | ||
| {description && <span>{description}</span>} | ||
| </div> | ||
| ), | ||
| ColumnMappingOverlay: () => null, | ||
| substituteParams: (s: string) => s, | ||
| Popover: ({ children }: { children: React.ReactNode }) => ( | ||
| <div>{children}</div> | ||
| ), | ||
| PopoverTrigger: ({ children }: { children: React.ReactNode }) => ( | ||
| <div>{children}</div> | ||
| ), | ||
| PopoverContent: ({ children }: { children: React.ReactNode }) => ( | ||
| <div>{children}</div> | ||
| ), | ||
| })); | ||
|
|
||
| vi.mock("@/lib/data-transforms", () => ({ | ||
| applyTransforms: (data: unknown) => data, | ||
| })); | ||
|
|
||
| vi.mock("@/lib/card-utils", () => ({ | ||
| extractColumnNames: () => [], | ||
| resolveStylingConfig: () => undefined, | ||
| })); | ||
|
|
||
| // Import after mocks | ||
| import { CardContainer } from "../card-container"; | ||
|
|
||
| function createWidget(overrides?: Partial<DashboardWidget>): DashboardWidget { | ||
| return { | ||
| id: "widget-123", | ||
| chartType: "markdown", | ||
| connectionId: "conn-1", | ||
| query: "", | ||
| settings: { | ||
| chartOptions: { content: "hello" }, | ||
| }, | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| function renderWithProviders(ui: React.ReactElement) { | ||
| const queryClient = new QueryClient({ | ||
| defaultOptions: { queries: { retry: false } }, | ||
| }); | ||
| return render( | ||
| <QueryClientProvider client={queryClient}>{ui}</QueryClientProvider>, | ||
| ); | ||
| } | ||
|
|
||
| describe("CardContainer", () => { | ||
| beforeEach(() => { | ||
| capturedChartProps = {}; | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe("widgetIdSuffix prop", () => { | ||
| it("passes widget.id as widgetId in meta when widgetIdSuffix is not provided", () => { | ||
| const widget = createWidget(); | ||
| renderWithProviders(<CardContainer widget={widget} />); | ||
|
|
||
| const meta = capturedChartProps.meta as { widgetId?: string }; | ||
| expect(meta?.widgetId).toBe("widget-123"); | ||
| }); | ||
|
|
||
| it("appends suffix to widgetId when widgetIdSuffix is provided", () => { | ||
| const widget = createWidget(); | ||
| renderWithProviders( | ||
| <CardContainer widget={widget} widgetIdSuffix="fullscreen" />, | ||
| ); | ||
|
|
||
| const meta = capturedChartProps.meta as { widgetId?: string }; | ||
| expect(meta?.widgetId).toBe("widget-123--fullscreen"); | ||
| }); | ||
|
|
||
| it("uses double-dash separator between widget id and suffix", () => { | ||
| const widget = createWidget({ id: "w-99" }); | ||
| renderWithProviders( | ||
| <CardContainer widget={widget} widgetIdSuffix="preview" />, | ||
| ); | ||
|
|
||
| const meta = capturedChartProps.meta as { widgetId?: string }; | ||
| expect(meta?.widgetId).toBe("w-99--preview"); | ||
| }); | ||
|
|
||
| it("passes original widget.id when widgetIdSuffix is empty string", () => { | ||
| // Empty string is falsy, so effectiveWidgetId should be widget.id | ||
| const widget = createWidget(); | ||
| renderWithProviders(<CardContainer widget={widget} widgetIdSuffix="" />); | ||
|
|
||
| const meta = capturedChartProps.meta as { widgetId?: string }; | ||
| expect(meta?.widgetId).toBe("widget-123"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("preview data path with widgetIdSuffix", () => { | ||
| it("passes effectiveWidgetId through meta when rendering with previewData", () => { | ||
| const widget = createWidget({ chartType: "bar" }); | ||
| const previewData = [{ name: "A", value: 1 }]; | ||
| renderWithProviders( | ||
| <CardContainer | ||
| widget={widget} | ||
| previewData={previewData} | ||
| widgetIdSuffix="fullscreen" | ||
| />, | ||
| ); | ||
|
|
||
| const meta = capturedChartProps.meta as { widgetId?: string }; | ||
| expect(meta?.widgetId).toBe("widget-123--fullscreen"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("unknown chart type", () => { | ||
| it("shows empty state for unknown chart types", () => { | ||
| const widget = createWidget({ chartType: "nonexistent" }); | ||
| renderWithProviders(<CardContainer widget={widget} />); | ||
|
|
||
| expect(screen.getByText("Unknown chart type")).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
In Playwright, doeslocator.last()resolve dynamically on each assertion/action, and can it point to a different element after DOM updates?💡 Result:
Yes, in Playwright, locator.last resolves dynamically on each assertion or action. It re-evaluates the locator query against the current DOM state every time it is used, so it can point to a different element if the DOM updates (such as elements being added, removed, or reordered) between uses. This behavior is core to how all Playwright locators work: they store a query rather than a fixed element reference, ensuring resilience to DOM changes. Official documentation states: "Every time a locator is used for an action, an up-to-date DOM element is located in the page." For example: const locator = page.locator('ul li'); await locator.last.click; // Finds current last
Citations:
🏁 Script executed:
Repository: alfredo1996/neoboard
Length of output: 699
🏁 Script executed:
Repository: alfredo1996/neoboard
Length of output: 2072
Scope the alert locator to the clicked card; global
.last()is brittle in e2e tests.On Line 190,
page.locator('[role="alert"]').last()re-evaluates dynamically. In e2e tests where multiple cards exist, this can target the wrong alert after DOM changes or when other test cases add alerts to the page. Sincecardis already scoped on line 180, use it to isolate the alert:Suggested fix
🤖 Prompt for AI Agents