codeant-ai-for-open-source[bot] commented on code in PR #41434: URL: https://github.com/apache/superset/pull/41434#discussion_r3866936093
########## superset-frontend/playwright/tests/dashboard/dashboard-tabs.spec.ts: ########## @@ -0,0 +1,195 @@ +/** + * 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. + */ + +import getEmptyLayout from '../../../src/dashboard/util/getEmptyLayout'; +import { + BACKGROUND_TRANSPARENT, + DASHBOARD_GRID_ID, + DASHBOARD_ROOT_ID, +} from '../../../src/dashboard/util/constants'; +import { + CHART_TYPE, + ROW_TYPE, + TABS_TYPE, + TAB_TYPE, +} from '../../../src/dashboard/util/componentTypes'; +import { testWithAssets, expect } from '../../helpers/fixtures'; +import type { + DashboardLayoutChart, + DashboardPositionJson, +} from '../../helpers/api/dashboard'; +import { TIMEOUT } from '../../utils/constants'; +import { DashboardPage } from '../../pages/DashboardPage'; +import { createDashboardWithCharts } from './dashboard-test-helpers'; + +const DATASET_NAME = 'birth_names'; +const WIDE_VIEWPORT = { width: 1400, height: 900 }; +const NARROW_VIEWPORT = { width: 700, height: 900 }; +const TABS_ID = 'TABS-TOP'; +const FIRST_TAB_ID = 'TAB-A'; +const SECOND_TAB_ID = 'TAB-B'; +const ROW_ID = 'ROW-A'; + +function buildTabbedDashboardLayout( + charts: readonly DashboardLayoutChart[], +): DashboardPositionJson { + const [treemap] = charts; + if (!treemap) { + throw new Error('Tabbed dashboard layout requires a chart'); + } + + const emptyLayout = getEmptyLayout(); + const chartKey = `CHART-${treemap.id}`; + + return { + ...emptyLayout, + [DASHBOARD_GRID_ID]: { + ...emptyLayout[DASHBOARD_GRID_ID], + children: [TABS_ID], + }, + [TABS_ID]: { + type: TABS_TYPE, + id: TABS_ID, + children: [FIRST_TAB_ID, SECOND_TAB_ID], + parents: [DASHBOARD_ROOT_ID, DASHBOARD_GRID_ID], + meta: {}, + }, + [FIRST_TAB_ID]: { + type: TAB_TYPE, + id: FIRST_TAB_ID, + children: [ROW_ID], + parents: [DASHBOARD_ROOT_ID, DASHBOARD_GRID_ID, TABS_ID], + meta: { + text: 'Tab A', + defaultText: 'Tab title', + placeholder: 'Tab title', + }, + }, + [SECOND_TAB_ID]: { + type: TAB_TYPE, + id: SECOND_TAB_ID, + children: [], + parents: [DASHBOARD_ROOT_ID, DASHBOARD_GRID_ID, TABS_ID], + meta: { + text: 'Tab B', + defaultText: 'Tab title', + placeholder: 'Tab title', + }, + }, + [ROW_ID]: { + type: ROW_TYPE, + id: ROW_ID, + children: [chartKey], + parents: [DASHBOARD_ROOT_ID, DASHBOARD_GRID_ID, TABS_ID, FIRST_TAB_ID], + meta: { background: BACKGROUND_TRANSPARENT }, + }, + [chartKey]: { + type: CHART_TYPE, + id: chartKey, + children: [], + parents: [ + DASHBOARD_ROOT_ID, + DASHBOARD_GRID_ID, + TABS_ID, + FIRST_TAB_ID, + ROW_ID, + ], + meta: { + chartId: treemap.id, + width: 12, + height: 50, + sliceName: treemap.sliceName, + }, + }, + }; +} + +testWithAssets( + 'chart in a hidden tab refits its container after the tab is revealed at a new width', + async ({ page, testAssets }, testInfo) => { + testWithAssets.setTimeout(TIMEOUT.SLOW_TEST); + + const { dashboardId, charts } = await createDashboardWithCharts( + page, + testAssets, + testInfo, + { + datasetName: DATASET_NAME, + chartNamePrefix: 'tabs', + dashboardTitlePrefix: 'tabs_resize', + chartSpecs: [ + { + viz_type: 'treemap_v2', + params: { + metric: 'count', + groupby: ['gender'], + row_limit: 100, + }, + }, + ], + buildLayout: buildTabbedDashboardLayout, + }, + ); + const [treemap] = charts; + if (!treemap) { + throw new Error('Dashboard setup did not create the treemap'); + } + + await page.setViewportSize(WIDE_VIEWPORT); + + const dashboard = new DashboardPage(page); + await dashboard.gotoById(dashboardId); + await dashboard.waitForLoad(); + + const treemapContainer = dashboard + .getChart(treemap.id) + .locator('[data-test="chart-container"]'); + await treemapContainer.waitFor({ + state: 'visible', + timeout: TIMEOUT.API_RESPONSE, + }); + await dashboard.waitForChartsToLoad(); + + const echartsHost = treemapContainer.locator('.echarts-host'); + const widthAtWide = await echartsHost.evaluate( + (element: HTMLElement) => element.offsetWidth, + ); + + await dashboard.switchDashboardTab('Tab B'); + await page.setViewportSize(NARROW_VIEWPORT); + await dashboard.switchDashboardTab('Tab A'); + + await treemapContainer.waitFor({ + state: 'visible', + timeout: TIMEOUT.API_RESPONSE, + }); + await dashboard.waitForChartsToLoad(); + + await expect + .poll( + () => + echartsHost.evaluate((element: HTMLElement) => element.offsetWidth), + { + timeout: TIMEOUT.API_RESPONSE, + message: 'treemap should resize after the hidden tab is revealed', + }, + ) + .toBeLessThan(widthAtWide); Review Comment: **Suggestion:** The test only checks that the ECharts host's `offsetWidth` decreased. That width can change from normal CSS layout when the viewport shrinks even if ECharts did not resize its rendered content, so the intended resize-on-reveal regression can pass while the chart still overflows horizontally. Add an assertion that the chart content's `scrollWidth` equals its `offsetWidth` after the tab is revealed. [logic error] <details> <summary><b>Severity Level:</b> Major ⚠️</summary> ```mdx - ❌ Resize regression can produce a false-green E2E test. - ⚠️ Hidden-tab treemap overflow may go undetected. - ⚠️ Dashboard chart layout coverage remains incomplete. ``` </details> [](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=3713333c7927478e82882188847fd703&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=3713333c7927478e82882188847fd703&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/dashboard-tabs.spec.ts **Line:** 184:193 **Comment:** *Logic Error: The test only checks that the ECharts host's `offsetWidth` decreased. That width can change from normal CSS layout when the viewport shrinks even if ECharts did not resize its rendered content, so the intended resize-on-reveal regression can pass while the chart still overflows horizontally. Add an assertion that the chart content's `scrollWidth` equals its `offsetWidth` after the tab is revealed. 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%2F41434&comment_hash=76b261ac3379fe4d0316fb6d99e21bf2410dabe9d6d0c14309962fb0baf81a9e&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41434&comment_hash=76b261ac3379fe4d0316fb6d99e21bf2410dabe9d6d0c14309962fb0baf81a9e&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]
