codeant-ai-for-open-source[bot] commented on code in PR #44844: URL: https://github.com/apache/superset/pull/44844#discussion_r4150644753
########## superset-frontend/playwright/tests/dashboard/featured-charts-render.spec.ts: ########## @@ -0,0 +1,209 @@ +/** + * 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. + */ + +/** + * Render smoke for the "Featured Charts" example dashboard. + * + * Replaces the per-visualization Cypress specs (big number, box plot, bubble, + * gauge, graph, pie, sunburst, ...) that were skipped once example data moved + * to YAML and later deleted. Those specs mostly asserted that a canvas or svg + * existed; chart correctness lives in each plugin's transformProps/buildQuery + * unit tests. This spec keeps the one thing only a real browser against a real + * backend can prove: every registered visualization on the example dashboard + * queries successfully and paints its output without an error. + * + * CI green => every chart on the dashboard issued an accepted chart-data query + * and rendered its terminal output with no error alert. + * CI red => a visualization failed to query or render, or the example + * dashboard lost one of the visualization types it covers. + */ +import type { Locator } from '@playwright/test'; +import { test, expect } from '@playwright/test'; +import { + getDashboardByName, + getDashboardCharts, +} from '../../helpers/api/dashboard'; +import { DashboardPage } from '../../pages/DashboardPage'; +import { TIMEOUT } from '../../utils/constants'; +import { sliceIdFromChartDataUrl } from './dashboard-test-helpers'; + +const DASHBOARD_TITLE = 'Featured Charts'; + +// Visualization types the dashboard is expected to cover. A subset check, so +// adding charts to the example does not break the spec, but dropping one does. +const EXPECTED_VIZ_TYPES = [ + 'big_number', + 'big_number_total', + 'box_plot', + 'bubble_v2', + 'echarts_area', + 'echarts_timeseries_bar', + 'echarts_timeseries_line', + 'echarts_timeseries_scatter', + 'funnel', + 'gantt_chart', + 'gauge_chart', + 'graph_chart', + 'heatmap_v2', + 'histogram_v2', + 'mixed_timeseries', + 'pie', + 'pivot_table_v2', + 'radar', + 'sankey_v2', + 'sunburst_v2', + 'table', + 'tree_chart', + 'treemap_v2', + 'waterfall', + 'word_cloud', +]; + +// Saturated-pixel floor for a chart's canvases. Painted charts on this +// dashboard score from several hundred to tens of thousands; a blank or +// axes-only canvas scores ~0. Series correctness is left to plugin unit tests. +const MIN_COLORED_PIXELS = 100; + +/** + * The terminal output each visualization paints once its data has arrived. + * ECharts-based visualizations (the default) paint a canvas. + */ +function chartOutput(chart: Locator, vizType: string): Locator { + switch (vizType) { + case 'big_number': + case 'big_number_total': + return chart.locator('.header-line'); + case 'table': + case 'pivot_table_v2': + return chart.locator('table tbody tr:not(:has(.dt-no-results))').first(); + case 'word_cloud': + return chart.locator('svg text').first(); + default: + return chart.locator('canvas').first(); + } +} + +/** + * Counts opaque, saturated pixels across every canvas in a chart (ECharts may + * split a chart over several layers). Axes, gridlines and labels are drawn in + * neutral grays, so only colored marks such as series and legend swatches + * count. + */ +async function saturatedPixelCount(chart: Locator): Promise<number> { + return chart.locator('canvas').evaluateAll((elements: HTMLCanvasElement[]) => + elements.reduce((total, element) => { + const context = element.getContext('2d'); + if (!context || element.width === 0 || element.height === 0) { + return total; + } + const { data } = context.getImageData( + 0, + 0, + element.width, + element.height, + ); + let count = 0; + for (let index = 0; index < data.length; index += 4) { + const red = data[index]; + const green = data[index + 1]; + const blue = data[index + 2]; + if ( + data[index + 3] >= 200 && + Math.max(red, green, blue) - Math.min(red, green, blue) > 40 + ) { + count += 1; + } + } + return total + count; + }, 0), + ); +} + +test('every chart on the Featured Charts dashboard renders', async ({ + page, +}) => { + // Twenty-five uncached queries, rendered one scroll position at a time. + test.setTimeout(TIMEOUT.SLOW_TEST * 3); Review Comment: **Suggestion:** Twenty-five sequential chart assertions can each consume the 30-second render timeout, exceeding the 180-second test timeout even when every chart eventually renders. **Assessment:** ๐ `Major` ยท ๐ `Occurrence: Rarely` ยท ๐ท๏ธ `Performance` [](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=135d8d24e2db4396955a99039cded7cd&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=135d8d24e2db4396955a99039cded7cd&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) <details> <summary><b>Prompt for AI Agent ๐ค </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-frontend/playwright/tests/dashboard/featured-charts-render.spec.ts **Line:** 142:142 **Comment:** *Performance: Twenty-five sequential chart assertions can each consume the 30-second render timeout, exceeding the 180-second test timeout even when every chart eventually renders. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44844&comment_hash=ef8c757d30c322569f55a038541dd32d547f1be5c6c0074ac159b2e96b0d49b5&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44844&comment_hash=ef8c757d30c322569f55a038541dd32d547f1be5c6c0074ac159b2e96b0d49b5&reaction=dislike'>๐</a> -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
