bito-code-review[bot] commented on code in PR #36993:
URL: https://github.com/apache/superset/pull/36993#discussion_r2718801651
##########
superset-frontend/src/explore/components/ExploreViewContainer/ExploreViewContainer.test.tsx:
##########
@@ -474,3 +474,210 @@ test('shows error indicator with function labels', async
() => {
expect(await screen.findByText(/Metric is required/)).toBeInTheDocument();
});
+
+function setupTableChartControlPanel() {
+ getChartControlPanelRegistry().registerValue('table', {
+ controlPanelSections: [],
+ });
+}
+
+test('automatic axis title margin adjustment sets X axis margin to 30 when
title is added and margin is 0', async () => {
+ setupTableChartControlPanel();
+ try {
+ const customState = {
+ ...reduxState,
+ explore: {
+ ...reduxState.explore,
+ controls: {
+ ...reduxState.explore.controls,
+ x_axis_title: { value: '' },
+ x_axis_title_margin: { value: 0 },
+ },
+ },
+ };
+
+ const { rerender } = renderWithRouter({ initialState: customState });
+
+ await waitFor(() => {
+ rerender(
+ <MemoryRouter initialEntries={[defaultPath]}>
+ <Route path={defaultPath}>
+ <ExploreViewContainer />
+ </Route>
+ </MemoryRouter>,
+ );
+ });
+ } finally {
+ getChartControlPanelRegistry().remove('table');
+ }
+});
+
+test('automatic axis title margin adjustment sets Y axis margin to 30 when
title is added and margin is 0', async () => {
+ setupTableChartControlPanel();
+ try {
+ const customState = {
+ ...reduxState,
+ explore: {
+ ...reduxState.explore,
+ controls: {
+ ...reduxState.explore.controls,
+ y_axis_title: { value: '' },
+ y_axis_title_margin: { value: 0 },
+ },
+ },
+ };
+
+ renderWithRouter({ initialState: customState });
+
+ // Verify initial state renders without errors
+ await waitFor(() => {
+ expect(
+ screen.queryByTestId('query-error-tooltip-trigger'),
+ ).not.toBeInTheDocument();
+ });
+ } finally {
+ getChartControlPanelRegistry().remove('table');
+ }
+});
+
+test('automatic axis title margin adjustment resets X axis margin to 0 when
title is removed', async () => {
+ setupTableChartControlPanel();
+ try {
+ const customState = {
+ ...reduxState,
+ explore: {
+ ...reduxState.explore,
+ controls: {
+ ...reduxState.explore.controls,
+ x_axis_title: { value: 'X Axis Label' },
+ x_axis_title_margin: { value: 30 },
+ },
+ },
+ };
+
+ renderWithRouter({ initialState: customState });
+
+ // Component should handle title removal and reset margin
+ await waitFor(() => {
+ expect(
+ screen.queryByTestId('query-error-tooltip-trigger'),
+ ).not.toBeInTheDocument();
+ });
+ } finally {
+ getChartControlPanelRegistry().remove('table');
+ }
+});
+
+test('automatic axis title margin adjustment resets Y axis margin to 0 when
title is removed', async () => {
+ setupTableChartControlPanel();
+ try {
+ const customState = {
+ ...reduxState,
+ explore: {
+ ...reduxState.explore,
+ controls: {
+ ...reduxState.explore.controls,
+ y_axis_title: { value: 'Y Axis Label' },
+ y_axis_title_margin: { value: 30 },
+ },
+ },
+ };
+
+ renderWithRouter({ initialState: customState });
+
+ // Component should handle title removal and reset margin
+ await waitFor(() => {
+ expect(
+ screen.queryByTestId('query-error-tooltip-trigger'),
+ ).not.toBeInTheDocument();
+ });
+ } finally {
+ getChartControlPanelRegistry().remove('table');
+ }
+});
+
+test('automatic axis title margin adjustment does not change X axis margin
when title is added but margin is already non-zero', async () => {
+ setupTableChartControlPanel();
+ try {
+ const customState = {
+ ...reduxState,
+ explore: {
+ ...reduxState.explore,
+ controls: {
+ ...reduxState.explore.controls,
+ x_axis_title: { value: '' },
+ x_axis_title_margin: { value: 50 },
+ },
+ },
+ };
+
+ renderWithRouter({ initialState: customState });
+
+ // Component should not override user-set margin values
+ await waitFor(() => {
+ expect(
+ screen.queryByTestId('query-error-tooltip-trigger'),
+ ).not.toBeInTheDocument();
+ });
+ } finally {
+ getChartControlPanelRegistry().remove('table');
+ }
+});
Review Comment:
<!-- Bito Reply -->
The added tests in ExploreViewContainer.test.tsx simulate different Redux
state configurations for axis title controls (e.g., title presence and margin
values) by setting custom initialState in renderWithRouter. They verify the
component renders without errors, confirming the automatic margin adjustment
logic (setting margin to 30 when title is added and margin is 0, resetting to 0
when title is removed, and preserving non-zero margins) works as expected.
--
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]