sadpandajoe commented on code in PR #44850:
URL: https://github.com/apache/superset/pull/44850#discussion_r4167656495


##########
superset-frontend/src/explore/components/controls/ViewQueryModalFooter.test.tsx:
##########
@@ -0,0 +1,107 @@
+/**
+ * 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 { SupersetClient } from '@superset-ui/core';
+import {
+  fireEvent,
+  render,
+  screen,
+  userEvent,
+} from 'spec/helpers/testing-library';
+import ViewQueryModalFooter from './ViewQueryModalFooter';
+
+const datasource = { id: '7', type: 'table', sql: 'SELECT 1' };
+
+const setup = () => {
+  const closeModal = jest.fn();
+  const changeDatasource = jest.fn();
+  render(
+    <ViewQueryModalFooter
+      closeModal={closeModal}
+      changeDatasource={changeDatasource}
+      datasource={datasource}
+    />,
+    { useRouter: true },
+  );
+  return { closeModal, changeDatasource };
+};
+
+beforeEach(() => {
+  window.history.replaceState(null, '', '/explore/');
+});
+
+afterEach(() => {
+  jest.restoreAllMocks();
+});
+
+test('renders the footer actions', () => {
+  setup();
+  expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument();
+  expect(
+    screen.getByRole('button', { name: 'Save as Dataset' }),
+  ).toBeInTheDocument();
+  expect(
+    screen.getByRole('button', { name: 'Open in SQL Lab' }),
+  ).toBeInTheDocument();
+});
+
+test('Open in SQL Lab navigates in-app with the requested query', async () => {
+  const postForm = jest
+    .spyOn(SupersetClient, 'postForm')
+    .mockResolvedValue(undefined);
+  setup();
+  await userEvent.click(
+    screen.getByRole('button', { name: 'Open in SQL Lab' }),
+  );
+  expect(window.location.pathname).toBe('/sqllab');
+  expect(window.history.state.state).toEqual({
+    requestedQuery: { datasourceKey: '7__table', sql: 'SELECT 1' },
+  });
+  expect(postForm).not.toHaveBeenCalled();
+});
+
+test('meta-click on Open in SQL Lab posts a form to open a new tab', async () 
=> {
+  const postForm = jest
+    .spyOn(SupersetClient, 'postForm')
+    .mockResolvedValue(undefined);
+  setup();
+  fireEvent.click(screen.getByRole('button', { name: 'Open in SQL Lab' }), {
+    metaKey: true,
+  });

Review Comment:
   The component only treats `metaKey` as "open in new tab"; Ctrl-click 
currently navigates in-app. A test for it would fail against current behavior, 
and asserting the current behavior would pin the gap, so I haven't added one 
here. Honoring `ctrlKey` alongside `metaKey` is a component follow-up.



##########
superset-frontend/src/explore/components/controls/ZoomConfigControl/ZoomConfigControl.test.tsx:
##########
@@ -0,0 +1,119 @@
+/**
+ * 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 { fireEvent, render, screen } from 'spec/helpers/testing-library';
+import ZoomConfigControl from './ZoomConfigControl';
+import { ZoomConfigs } from './types';
+import { computeConfigValues } from './zoomUtil';
+
+// echarts needs a real canvas/layout engine; replace only chart creation and
+// keep the rest of the module (e.g. util) intact.
+jest.mock('echarts', () => ({
+  ...jest.requireActual('echarts'),
+  init: jest.fn(() => ({
+    setOption: jest.fn(),
+    convertToPixel: jest.fn(() => [0, 0]),
+    convertFromPixel: jest.fn(() => [0, 0]),
+  })),
+}));
+
+const makeValue = (type: ZoomConfigs['type'] = 'FIXED'): ZoomConfigs => {
+  const configs = {
+    zoom: 5,
+    width: 40,
+    height: 20,
+    slope: 2,
+    exponent: 1.4,
+  };
+  const base = { type, configs: { ...configs }, values: {} } as ZoomConfigs;
+  return { ...base, values: computeConfigValues(base) } as ZoomConfigs;
+};
+
+const setup = (value?: ZoomConfigs) => {
+  const onChange = jest.fn();
+  render(
+    <ZoomConfigControl
+      name="zoom_configs"
+      label="Zoom sizes"
+      value={value}
+      onChange={onChange}
+    />,
+  );
+  return { onChange };
+};
+
+test('renders the label, shape options, sliders and current zoom', () => {
+  setup(makeValue());
+  expect(screen.getByText('Zoom sizes')).toBeInTheDocument();
+  ['FIXED', 'LINEAR', 'EXP'].forEach(shape =>
+    expect(screen.getByText(shape)).toBeInTheDocument(),
+  );
+  expect(screen.getAllByRole('slider')).toHaveLength(4);
+  expect(screen.getByText(/Current Zoom/)).toHaveTextContent('Current Zoom: 
5');
+});
+
+test('initialises the sliders from the configured sizes', () => {
+  setup(makeValue());
+  const [width, height, slope, exponent] = screen.getAllByRole('slider');
+  expect(width).toHaveAttribute('aria-valuenow', '40');
+  expect(height).toHaveAttribute('aria-valuenow', '20');
+  expect(slope).toHaveAttribute('aria-valuenow', '2');
+  expect(exponent).toHaveAttribute('aria-valuenow', '1.4');
+});
+
+test('switching the shape emits a config of that type built from the base 
values', () => {
+  const { onChange } = setup(makeValue('FIXED'));
+  fireEvent.click(screen.getByRole('radio', { name: 'LINEAR' }));
+  const emitted = onChange.mock.lastCall?.[0];
+  expect(emitted.type).toBe('LINEAR');
+  expect(emitted.configs).toMatchObject({
+    width: 40,
+    height: 20,
+    slope: 2,
+    zoom: 5,
+  });
+  // Linear sizes grow by `slope` per zoom level, keeping the aspect ratio.
+  expect(emitted.values[5]).toEqual({ width: 40, height: 20 });
+  expect(emitted.values[6]).toEqual({ width: 42, height: 21 });
+  expect(emitted.values[4]).toEqual({ width: 38, height: 19 });
+});
+
+test('does not emit when the shape changes without a value', () => {
+  const { onChange } = setup(undefined);
+  fireEvent.click(screen.getByRole('radio', { name: 'EXP' }));
+  expect(onChange).not.toHaveBeenCalled();
+});
+
+test('changing the base width recomputes the values for every zoom level', () 
=> {
+  const { onChange } = setup(makeValue('FIXED'));
+  const [width] = screen.getAllByRole('slider');
+  fireEvent.keyDown(width, { key: 'ArrowRight', keyCode: 39 });
+  fireEvent.keyUp(width, { key: 'ArrowRight', keyCode: 39 });
+  expect(onChange).toHaveBeenCalledTimes(1);
+  const emitted = onChange.mock.calls[0][0];
+  expect(emitted.configs.width).toBe(41);
+  expect(emitted.values[0].width).toBe(41);
+  expect(emitted.values[28].width).toBe(41);

Review Comment:
   The component currently mutates `value.configs` (shallow spread, then nested 
assignment), so a no-mutation assertion would fail today. That's a known 
component bug tracked separately, so it isn't pinned or asserted in this 
test-only change.



##########
superset-frontend/src/explore/components/controls/MapViewControl/MapViewControl.test.tsx:
##########
@@ -0,0 +1,134 @@
+/**
+ * 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 {
+  fireEvent,
+  render,
+  screen,
+  userEvent,
+} from 'spec/helpers/testing-library';
+import MapViewControl from './MapViewControl';
+import { MapViewConfigs } from './types';
+
+const makeValue = (
+  overrides: Partial<MapViewConfigs> = {},
+): MapViewConfigs => ({
+  mode: 'CUSTOM',
+  zoom: 7,
+  latitude: 48.5,
+  longitude: 9.25,
+  fixedZoom: 4,
+  fixedLatitude: 10,
+  fixedLongitude: 20,
+  ...overrides,
+});
+
+const setup = (value?: MapViewConfigs) => {
+  const onChange = jest.fn();
+  render(
+    <MapViewControl
+      name="map_view"
+      label="Extent"
+      value={value}
+      onChange={onChange}
+    />,
+  );
+  return { onChange };
+};
+
+test('renders the label and the two extent modes', () => {
+  setup(makeValue({ mode: 'FIT_DATA' }));
+  expect(screen.getByText('Extent')).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: 'Fit data' })).toBeChecked();
+  expect(screen.getByRole('radio', { name: 'Custom' })).not.toBeChecked();
+});
+
+test('hides the extent tag and button in fit data mode', () => {
+  setup(makeValue({ mode: 'FIT_DATA' }));
+  expect(screen.queryByText(/Lat:/)).not.toBeInTheDocument();
+  expect(
+    screen.queryByRole('button', { name: 'Use current extent' }),
+  ).not.toBeInTheDocument();
+});
+
+test('shows the fixed extent in custom mode', () => {
+  setup(makeValue());
+  expect(screen.getByText(/Zoom: 4/)).toHaveTextContent(
+    'Zoom: 4 | Lat: 10.000000 | Lon: 20.000000',
+  );
+  expect(
+    screen.getByRole('button', { name: 'Use current extent' }),
+  ).toBeInTheDocument();
+});
+
+test('shows unset for missing extent values', () => {
+  // Saved configs may omit the fixed extent entirely, which the type forbids.
+  setup({
+    ...makeValue(),
+    fixedZoom: undefined,
+    fixedLatitude: undefined,
+    fixedLongitude: undefined,
+  } as unknown as MapViewConfigs);
+  expect(screen.getByText(/Zoom:/)).toHaveTextContent(
+    'Zoom: unset | Lat: unset | Lon: unset',
+  );

Review Comment:
   `ExtentTag` uses truthiness checks, so a legitimate `0` (equator or prime 
meridian) renders as "unset". Asserting either behavior here would either fail 
or pin the bug, so it's deferred to the component fix.



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