bito-code-review[bot] commented on code in PR #37141:
URL: https://github.com/apache/superset/pull/37141#discussion_r3717522119


##########
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx:
##########
@@ -963,3 +979,62 @@ test('withholds the empty-state edit action while 
previewing a version', async (
     queryByRole('button', { name: 'Edit the dashboard' }),
   ).not.toBeInTheDocument();
 });
+
+// Mobile support tests
+// Note: The main mobile tests require mocking useBreakpoint to return mobile 
breakpoints
+// which is done at the module level. These tests verify mobile-related 
component behavior.
+
+test('should not render filter bar panel on desktop when nativeFiltersEnabled 
is false', () => {
+  (useStoredSidebarWidth as jest.Mock).mockImplementation(() => [
+    100,
+    jest.fn(),
+  ]);
+  (fetchFaveStar as jest.Mock).mockReturnValue({ type: 'mock-action' });
+  (setActiveTab as jest.Mock).mockReturnValue({ type: 'mock-action' });
+
+  jest.spyOn(useNativeFiltersModule, 'useNativeFilters').mockReturnValue({
+    showDashboard: true,
+    missingInitialFilters: [],
+    dashboardFiltersOpen: true,
+    toggleDashboardFiltersOpen: jest.fn(),
+    nativeFiltersEnabled: false,
+    hasFilters: false,
+  });
+
+  const { queryByTestId } = render(<DashboardBuilder />, {
+    useRedux: true,
+    store: storeWithState({
+      ...mockState,
+      dashboardLayout: undoableDashboardLayout,
+    }),
+    useDnd: true,
+    useTheme: true,
+    useRouter: true,
+  });
+
+  // Filter panel should not be present when native filters are disabled
+  expect(queryByTestId('dashboard-filters-panel')).not.toBeInTheDocument();
+});
+
+test('should render header container', () => {
+  (useStoredSidebarWidth as jest.Mock).mockImplementation(() => [
+    100,
+    jest.fn(),
+  ]);
+  (fetchFaveStar as jest.Mock).mockReturnValue({ type: 'mock-action' });
+  (setActiveTab as jest.Mock).mockReturnValue({ type: 'mock-action' });
+
+  const { queryByTestId } = render(<DashboardBuilder />, {
+    useRedux: true,
+    store: storeWithState({
+      ...mockState,
+      dashboardLayout: undoableDashboardLayout,
+    }),
+    useDnd: true,
+    useTheme: true,
+    useRouter: true,
+  });
+
+  // Header container should be present
+  expect(queryByTestId('dashboard-header-container')).toBeInTheDocument();
+});

Review Comment:
   <!-- Bito Reply -->
   The suggestion to remove the test is appropriate because the test at line 
1015 (in the provided diff hunk) indeed duplicates an existing assertion for 
`dashboard-header-container` that is already covered elsewhere in the test 
suite. Removing redundant tests helps maintain a cleaner and more efficient 
test suite.



##########
superset-frontend/playwright/tests/mobile/mobile-dashboard.spec.ts:
##########
@@ -0,0 +1,284 @@
+/**
+ * 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 { test, expect, devices, Page } from '@playwright/test';
+
+// NOTE: These tests exercise the mobile consumption experience and require
+// the MOBILE_CONSUMPTION_MODE feature flag to be enabled in the target
+// environment (FEATURE_FLAGS = {"MOBILE_CONSUMPTION_MODE": True}).
+import { TIMEOUT } from '../../utils/constants';
+import { URL } from '../../utils/urls';
+
+/**
+ * Mobile dashboard viewing tests verify that dashboards can be viewed
+ * and interacted with on mobile devices.
+ *
+ * These tests assume the World Bank's Health sample dashboard exists.
+ */
+
+// Use iPhone 12 viewport for mobile tests
+const mobileViewport = devices['iPhone 12'];
+
+/**
+ * Navigates to the dashboard list, clicks the first available dashboard
+ * card, and waits for navigation into that dashboard. Skips the current
+ * test when no dashboards are available to open.
+ */
+async function openFirstDashboard(page: Page): Promise<void> {
+  await page.goto(URL.DASHBOARD_LIST);
+  await page.waitForLoadState('networkidle');
+
+  const cards = page.locator('[data-test="styled-card"]');

Review Comment:
   <!-- Bito Reply -->
   Understood. Since the data-test attribute is present on the component being 
targeted in the UI, the selector is appropriate for this test. No changes are 
required to the selector.



##########
superset-frontend/playwright/tests/mobile/mobile-dashboard.spec.ts:
##########
@@ -0,0 +1,284 @@
+/**
+ * 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 { test, expect, devices, Page } from '@playwright/test';
+
+// NOTE: These tests exercise the mobile consumption experience and require
+// the MOBILE_CONSUMPTION_MODE feature flag to be enabled in the target
+// environment (FEATURE_FLAGS = {"MOBILE_CONSUMPTION_MODE": True}).
+import { TIMEOUT } from '../../utils/constants';
+import { URL } from '../../utils/urls';
+
+/**
+ * Mobile dashboard viewing tests verify that dashboards can be viewed
+ * and interacted with on mobile devices.
+ *
+ * These tests assume the World Bank's Health sample dashboard exists.
+ */
+
+// Use iPhone 12 viewport for mobile tests
+const mobileViewport = devices['iPhone 12'];
+
+/**
+ * Navigates to the dashboard list, clicks the first available dashboard
+ * card, and waits for navigation into that dashboard. Skips the current
+ * test when no dashboards are available to open.
+ */
+async function openFirstDashboard(page: Page): Promise<void> {
+  await page.goto(URL.DASHBOARD_LIST);
+  await page.waitForLoadState('networkidle');
+
+  const cards = page.locator('[data-test="styled-card"]');
+  const cardCount = await cards.count();
+
+  test.skip(cardCount === 0, 'No dashboards available to open on mobile');
+
+  await cards.first().click();
+
+  await page.waitForURL(url => /\/dashboard\/(?!list)/.test(url.pathname), {
+    timeout: TIMEOUT.PAGE_LOAD,
+  });
+}
+
+/**
+ * Navigates to the World Bank's Health dashboard and returns a locator
+ * for its mobile filter button. Skips the current test when the fixture
+ * has no native filters configured.
+ */
+async function getMobileFilterButton(page: Page) {
+  // Navigate directly to the World Bank's Health dashboard, which this
+  // spec's fixtures require, rather than an arbitrary first card from
+  // the list. Whether it has native filters configured depends on the
+  // fixture, so callers skip themselves when none are present.
+  await page.goto('dashboard/world_health/');
+  await page.waitForLoadState('networkidle');
+
+  // Give filters time to load
+  await page.waitForTimeout(2000);
+
+  const filterButton = page
+    .locator('[data-test="mobile-filters-trigger"]')
+    .or(page.locator('[aria-label="Open filters"]'));
+
+  const filterCount = await filterButton.count();
+
+  test.skip(
+    filterCount === 0,
+    'world_health dashboard fixture has no native filters configured; ' +
+      'cannot verify mobile filter behavior.',
+  );
+
+  return filterButton;
+}
+
+test.describe('Mobile Dashboard Viewing', () => {
+  test.use({
+    viewport: mobileViewport.viewport,
+    userAgent: mobileViewport.userAgent,
+  });
+
+  test.beforeEach(async ({ page }) => {
+    // Navigate to dashboard list to find a dashboard
+    await page.goto(URL.DASHBOARD_LIST);
+    await page.waitForLoadState('networkidle');
+  });
+
+  test('dashboard list renders in card view on mobile', async ({ page }) => {
+    // On mobile, dashboard list should show cards, not table
+    // Look for card elements
+    const cards = page.locator('[data-test="styled-card"]');
+
+    // Should have at least one card if dashboards exist
+    // (This test may need adjustment based on test data availability)
+    const cardCount = await cards.count();
+
+    // Either cards are visible, or the empty state is shown; the table
+    // view must never render on mobile
+    if (cardCount > 0) {
+      await expect(cards.first()).toBeVisible({ timeout: TIMEOUT.PAGE_LOAD });
+    } else {
+      await expect(page.locator('[data-test="empty-state"]')).toBeVisible({
+        timeout: TIMEOUT.PAGE_LOAD,
+      });
+    }
+    await expect(page.locator('[data-test="listview-table"]')).toHaveCount(0);
+  });
+
+  test('mobile search button appears in dashboard list', async ({ page }) => {
+    // On mobile, the search/filter button should appear in the header
+    const searchButton = page
+      .locator('[aria-label="Search"]')
+      .or(page.locator('[data-test="mobile-search-button"]'));
+
+    // Search button should be visible on mobile
+    await expect(searchButton.first()).toBeVisible({
+      timeout: TIMEOUT.PAGE_LOAD,
+    });
+  });
+
+  test('tapping dashboard card opens the dashboard', async ({ page }) => {
+    // Find a dashboard card
+    const cards = page.locator('[data-test="styled-card"]');
+    const cardCount = await cards.count();
+
+    if (cardCount > 0) {
+      // Click the first card
+      await cards.first().click();
+
+      // Should navigate to dashboard view
+      await page.waitForURL(url => /\/dashboard\/(?!list)/.test(url.pathname), 
{
+        timeout: TIMEOUT.PAGE_LOAD,
+      });
+
+      // Dashboard should load (look for dashboard content)
+      await expect(
+        page
+          .locator('[data-test="dashboard-content-wrapper"]')
+          .or(page.locator('.dashboard')),
+      ).toBeVisible({ timeout: TIMEOUT.PAGE_LOAD });
+    } else {
+      test.skip();
+    }
+  });
+});
+
+test.describe('Mobile Dashboard Interaction', () => {
+  test.use({
+    viewport: mobileViewport.viewport,
+    userAgent: mobileViewport.userAgent,
+  });
+
+  // Skip this test suite if no dashboards exist
+  test.beforeAll(async ({ browser }) => {
+    // browser.newPage() does not inherit the project's `storageState`, so
+    // it must be passed explicitly to reuse the authenticated session -
+    // otherwise this check hits the login page and always finds 0 cards.
+    const page = await browser.newPage({
+      viewport: mobileViewport.viewport,
+      userAgent: mobileViewport.userAgent,
+      storageState: 'playwright/.auth/user.json',
+    });
+
+    await page.goto(URL.DASHBOARD_LIST);
+    await page.waitForLoadState('networkidle');
+
+    const cards = page.locator('[data-test="styled-card"]');
+    const cardCount = await cards.count();
+
+    await page.close();
+
+    if (cardCount === 0) {
+      test.skip();
+    }
+  });
+
+  test('dashboard loads and shows charts on mobile', async ({ page }) => {
+    await openFirstDashboard(page);
+
+    // Dashboard content should be visible
+    await expect(
+      page
+        .locator('[data-test="dashboard-content-wrapper"]')
+        .or(page.locator('.dashboard')),
+    ).toBeVisible({ timeout: TIMEOUT.PAGE_LOAD });
+
+    // Charts should start loading (look for chart containers)
+    const chartContainers = page
+      .locator('[data-test="chart-container"]')
+      .or(page.locator('.dashboard-chart'));
+
+    // Wait for at least one chart to be visible (with timeout)
+    await expect(chartContainers.first()).toBeVisible({
+      timeout: TIMEOUT.PAGE_LOAD * 2,
+    });
+  });
+
+  test('dashboard header shows hamburger menu on mobile', async ({ page }) => {
+    await openFirstDashboard(page);
+
+    // Look for the hamburger menu / more actions button
+    const menuButton = page
+      .locator('[data-test="actions-trigger"]')
+      .or(page.locator('[aria-label="Menu actions trigger"]'));

Review Comment:
   <!-- Bito Reply -->
   The reviewer's concern regarding the selector 
`[data-test="actions-trigger"]` is noted. If this selector is indeed absent 
from the production codebase, the test will fail as expected. Please verify the 
correct data-test attribute or role-based selector used for the header actions 
menu in the target component and update the test accordingly.
   
   **superset-frontend/playwright/tests/mobile/mobile-dashboard.spec.ts**
   ```
   // Look for the hamburger menu / more actions button
       const menuButton = page
         .locator('[data-test="actions-trigger"]')
         .or(page.locator('[aria-label="Menu actions trigger"]'));
   ```



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

Reply via email to