Compare commits

..

3 Commits

Author SHA1 Message Date
Joe Li
8230b7efa5 test(dashboard): cover combined edit+standalone URL params
Adds the React-side analogue of the legacy `?edit=true&standalone=true`
Cypress mount, asserting the two URL params remain orthogonal:
standalone=2 hides DashboardHeader while editMode still drives the
`dashboard--editing` wrapper class. Satisfies sc-107447 task 3.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-09 16:42:28 -07:00
Joe Li
63e60bc331 test(dashboard): save/restore full URL in standalone mode test
Save window.location.href instead of just window.location.search so the
finally block restores the original pathname and hash too, not just the
query string. Prevents state leakage if the Jest base URL ever moves
off the root path.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-09 16:29:26 -07:00
Joe Li
e6d770d1dd test(dashboard): migrate standalone mode Cypress spec to RTL
Replaces the standalone-mode assertion from the deleted Cypress spec
`cypress-base/cypress/e2e/dashboard/_skip.load.test.ts` (removed in
#40384) with a component-level RTL test in DashboardBuilder.test.tsx.
The React-side contract is `?standalone=2` (HideNavAndTitle) suppressing
`<DashboardHeader />`; the original Flask-template `#app-menu` selector
is out of RTL's reach. Other assertions in the deleted spec are already
covered by existing unit tests (extractUrlParams, Header, logger).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-09 12:05:09 -07:00
2 changed files with 36 additions and 113 deletions

View File

@@ -1,113 +0,0 @@
/**
* 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 fetchMock from 'fetch-mock';
import { JsonObject, QueryFormData, VizType } from '@superset-ui/core';
import { getChartDataRequest } from 'src/components/Chart/chartAction';
/**
* Integration (mocked-network) port of the deprecated Cypress spec
* `cypress/e2e/dashboard/_skip.url_params.test.ts` (sc-107448).
*
* The original test loaded a dashboard with query-string params, intercepted
* `/api/v1/chart/data`, and asserted each query in the request body carried
* `url_params`. That assertion is request-construction logic — the form_data
* → query-context pipeline — which is exercised here without a backend.
*
* Intentional narrowing: the URL-string → `form_data.url_params` hop (handled
* in `src/dashboard/actions/hydrate.ts` via `extractUrlParams`) is not covered
* here. This file verifies the chart-data side of the contract only; the
* dashboard hydration side is covered by its own unit tests.
*/
const CHART_DATA_GLOB = 'glob:*/api/v1/chart/data*';
const CHART_DATA_ROUTE = 'urlParamsForwarding-chartData';
const URL_PARAMS = { param1: '123', param2: 'abc' };
type ChartDataRequestBody = {
queries: JsonObject[];
form_data: JsonObject;
};
const buildFormData = (
overrides: Partial<QueryFormData> = {},
): QueryFormData => ({
datasource: '1__table',
granularity_sqla: 'ds',
viz_type: VizType.Table,
url_params: URL_PARAMS,
...overrides,
});
const lastChartDataBody = (): ChartDataRequestBody => {
const calls = fetchMock.callHistory.calls(CHART_DATA_ROUTE);
expect(calls.length).toBeGreaterThan(0);
return JSON.parse(
calls[calls.length - 1].options.body as string,
) as ChartDataRequestBody;
};
beforeEach(() => {
fetchMock.post(
CHART_DATA_GLOB,
{ result: [{ data: [] }] },
{
name: CHART_DATA_ROUTE,
},
);
});
// Remove only this file's route so global routes registered in
// setupSupersetClient (e.g. CSRF) survive into the next test.
afterEach(() => {
fetchMock.clearHistory();
fetchMock.removeRoutes({ names: [CHART_DATA_ROUTE] });
});
test('forwards url_params from form_data onto each query in the chart-data request body', async () => {
await getChartDataRequest({ formData: buildFormData() });
const body = lastChartDataBody();
expect(Array.isArray(body.queries)).toBe(true);
expect(body.queries.length).toBeGreaterThan(0);
body.queries.forEach(query => {
expect(query.url_params).toEqual(URL_PARAMS);
});
});
test('preserves url_params on form_data echoed back in the chart-data request body', async () => {
await getChartDataRequest({ formData: buildFormData() });
const body = lastChartDataBody();
expect(body.form_data.url_params).toEqual(URL_PARAMS);
});
// buildQueryObject defaults missing url_params to `{}` (see
// packages/superset-ui-core/src/query/buildQueryObject.ts), so the chart-data
// request body carries an empty object — not `undefined`. This test documents
// that contract; a future change that flips the default should update both.
test('emits an empty url_params object on each query when form_data has none', async () => {
await getChartDataRequest({
formData: buildFormData({ url_params: undefined }),
});
const body = lastChartDataBody();
expect(body.queries.length).toBeGreaterThan(0);
body.queries.forEach(query => {
expect(query.url_params).toEqual({});
});
});

View File

@@ -165,6 +165,42 @@ describe('DashboardBuilder', () => {
expect(header).toBeInTheDocument();
});
test('should hide DashboardHeader when standalone mode hides nav and title (?standalone=2)', () => {
// React-level equivalent of the legacy `cy.get('#app-menu').should('not.exist')`
// Cypress assertion. The `#app-menu` node lives in Flask's spa.html template,
// gated by `{% if standalone_mode %}`, so RTL cannot reach it directly.
// `?standalone=2` maps to DashboardStandaloneMode.HideNavAndTitle, which the
// DashboardBuilder honours by suppressing the React-side DashboardHeader.
const originalHref = window.location.href;
window.history.replaceState({}, '', '/?standalone=2');
try {
const { queryByTestId } = setup();
expect(queryByTestId('dashboard-header-container')).not.toBeInTheDocument();
} finally {
window.history.replaceState({}, '', originalHref);
}
});
test('should apply editing class and hide header when both edit and standalone params are set', () => {
// Combined-params analogue of the legacy `?edit=true&standalone=true` Cypress
// mount. The two URL params are orthogonal on the React side: standalone=2
// suppresses DashboardHeader regardless of editMode, while editMode still
// drives the `dashboard--editing` class on the wrapper.
const originalHref = window.location.href;
window.history.replaceState({}, '', '/?edit=true&standalone=2');
try {
const { getByTestId, queryByTestId } = setup({
dashboardState: { ...mockState.dashboardState, editMode: true },
});
expect(getByTestId('dashboard-content-wrapper')).toHaveClass(
'dashboard dashboard--editing',
);
expect(queryByTestId('dashboard-header-container')).not.toBeInTheDocument();
} finally {
window.history.replaceState({}, '', originalHref);
}
});
test('should render a Sticky top-level Tabs if the dashboard has tabs', async () => {
const { findAllByTestId } = setup({
dashboardLayout: undoableDashboardLayoutWithTabs,