codeant-ai-for-open-source[bot] commented on code in PR #44850: URL: https://github.com/apache/superset/pull/44850#discussion_r4150670479
########## 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: **Suggestion:** This test covers only Meta-click, so Ctrl-click regressions can make SQL Lab open in the current tab without failing the suite. **Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `Code quality` [](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a8fae3f566bf41b2ac17270429ab625f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a8fae3f566bf41b2ac17270429ab625f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) <details> <summary><b>Prompt for AI Agent ๐ค </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-frontend/src/explore/components/controls/ViewQueryModalFooter.test.tsx **Line:** 83:85 **Comment:** *Code Quality: This test covers only Meta-click, so Ctrl-click regressions can make SQL Lab open in the current tab without failing the suite. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44850&comment_hash=1db68fe393ee132075094c56a7a739463ffbf25bbc67e1d9e36234f7c060e980&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44850&comment_hash=1db68fe393ee132075094c56a7a739463ffbf25bbc67e1d9e36234f7c060e980&reaction=dislike'>๐</a> ########## 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: **Suggestion:** This test checks only emitted values, so mutating the input value's nested configs would pass and could leak changes into parent state. **Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `Code quality` [](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9c3e68ac1d5746de88c0287696b5417c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=9c3e68ac1d5746de88c0287696b5417c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) <details> <summary><b>Prompt for AI Agent ๐ค </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-frontend/src/explore/components/controls/ZoomConfigControl/ZoomConfigControl.test.tsx **Line:** 102:111 **Comment:** *Code Quality: This test checks only emitted values, so mutating the input value's nested configs would pass and could leak changes into parent state. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44850&comment_hash=0c9c22ebfa46b312078f337b71357a9f6d64dbed5ea333c5076012ad4428bfe3&reaction=like'>๐</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44850&comment_hash=0c9c22ebfa46b312078f337b71357a9f6d64dbed5ea333c5076012ad4428bfe3&reaction=dislike'>๐</a> -- 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]
