rusackas commented on code in PR #44878:
URL: https://github.com/apache/superset/pull/44878#discussion_r4332217910
##########
superset-frontend/src/explore/components/ExploreViewContainer/ExploreViewContainer.test.tsx:
##########
@@ -1462,3 +1454,117 @@ test('automatic axis title margin adjustment handles
both X and Y axis titles be
jest.restoreAllMocks();
}
});
+
+test('automatic axis title margin adjustment ignores a transient empty value
from a quick clear-and-retype', async () => {
+ setupTableChartControlPanel();
+ try {
+ const setControlValueSpy = jest.spyOn(exploreActions, 'setControlValue');
+
+ const initialState = {
+ ...reduxState,
+ explore: {
+ ...reduxState.explore,
+ form_data: {
+ datasource: '1__table',
+ viz_type: VizType.Table,
+ metrics: [],
+ },
+ controls: {
+ ...reduxState.explore.controls,
+ x_axis_title: { value: 'X Axis Label' },
+ x_axis_title_margin: { value: 75 }, // a custom margin above the
default 30
+ },
+ },
+ };
+
+ const store = createStore(initialState, reducerIndex);
+ renderWithRouter({ initialState, store: store as Store });
+
+ // Clear any calls from initial render
+ setControlValueSpy.mockClear();
+
+ // TextControl now reports edits via useDeferredValue instead of a fixed
+ // debounce, so a quick clear-and-retype (deleting a title and
+ // immediately typing a replacement) can briefly pass an empty value
+ // through here before the retyped value settles. The margin effect
+ // must react to the settled value only, not this transient one, or it
+ // would zero out a custom margin and then bump it back to 30, losing
+ // the original 75.
+ // Commit the clear on its own so the margin effect actually sees the
+ // empty value, then retype inside the debounce window.
+ act(() => {
+ store.dispatch(exploreActions.setControlValue('x_axis_title', ''));
+ });
+ act(() => {
+ store.dispatch(
+ exploreActions.setControlValue('x_axis_title', 'X Axis Label Redone'),
+ );
+ });
+
+ // Give the debounced margin effect more than its window to settle.
+ await new Promise(resolve => setTimeout(resolve, 300));
+
+ expect(setControlValueSpy).not.toHaveBeenCalledWith(
+ 'x_axis_title_margin',
+ expect.anything(),
+ undefined,
+ { programmatic: true },
+ );
+ } finally {
+ getChartControlPanelRegistry().remove('table');
+ jest.restoreAllMocks();
+ }
+});
+
+test('automatic axis title margin adjustment yields to a margin picked inside
the debounce window', async () => {
Review Comment:
Thanks @sadpandajoe. Added the viz-switch and rescheduling tests, and all
the race tests now run for both axes. The viz switch keeps the title and margin
so only the viz type snapshot can bail, since a changed margin is already
caught by the margin snapshot. Each new test goes red with its guard deleted
(the snapshot check, its viz type half alone, and the `clearTimeout`).
--
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]