aminghadersohi commented on code in PR #40617: URL: https://github.com/apache/superset/pull/40617#discussion_r3342897310
########## superset-frontend/plugins/plugin-chart-echarts/test/Histogram/buildQuery.test.ts: ########## @@ -0,0 +1,81 @@ +/** + * 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 buildQuery from '../../src/Histogram/buildQuery'; +import { HistogramFormData } from '../../src/Histogram/types'; + +const baseFormData: HistogramFormData = { + datasource: '5__table', + granularity_sqla: 'ds', + column: 'price', + groupby: [], + bins: 10, + viz_type: 'histogram', + cumulative: false, + normalize: false, + sliceId: 1, + showLegend: false, + showValue: false, + xAxisFormat: '', + xAxisTitle: '', + yAxisFormat: '', + yAxisTitle: '', +}; + +test('should build query with column and no metrics', () => { + const queryContext = buildQuery(baseFormData); + const [query] = queryContext.queries; + expect(query.columns).toContain('price'); + expect(query.metrics).toBeUndefined(); +}); + +test('should include groupby columns in query columns', () => { + const queryContext = buildQuery({ ...baseFormData, groupby: ['category'] }); + const [query] = queryContext.queries; + expect(query.columns).toEqual(['category', 'price']); +}); + +test('Regression for #30330: HAVING-clause metric filters require aggregation in the query', () => { Review Comment: **NIT — test name doesn't follow the `'should ...'` convention used by the other two tests** Tests 1 and 2 use `'should ...'` names. Consider: ```ts test('should include COUNT(*) metric when HAVING filter is present', () => { ``` Keep the `#30330` reference and the bug explanation in the block comment, where they add context without cluttering the Jest output. ########## superset-frontend/plugins/plugin-chart-echarts/test/Histogram/buildQuery.test.ts: ########## @@ -0,0 +1,81 @@ +/** + * 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 buildQuery from '../../src/Histogram/buildQuery'; +import { HistogramFormData } from '../../src/Histogram/types'; + +const baseFormData: HistogramFormData = { + datasource: '5__table', + granularity_sqla: 'ds', + column: 'price', + groupby: [], + bins: 10, + viz_type: 'histogram', + cumulative: false, + normalize: false, + sliceId: 1, + showLegend: false, + showValue: false, + xAxisFormat: '', + xAxisTitle: '', + yAxisFormat: '', + yAxisTitle: '', +}; + +test('should build query with column and no metrics', () => { + const queryContext = buildQuery(baseFormData); + const [query] = queryContext.queries; + expect(query.columns).toContain('price'); + expect(query.metrics).toBeUndefined(); +}); + +test('should include groupby columns in query columns', () => { + const queryContext = buildQuery({ ...baseFormData, groupby: ['category'] }); + const [query] = queryContext.queries; + expect(query.columns).toEqual(['category', 'price']); +}); Review Comment: **NIT — missing complementary WHERE-only filter test** There's no test confirming that a WHERE-only filter leaves `metrics` as `undefined`. This is the direct complement to the regression test and guards against a future refactor accidentally triggering on WHERE filters: ```ts test('should not inject metrics for WHERE-only filters', () => { const formData = { ...baseFormData, adhoc_filters: [ { clause: 'WHERE', expressionType: 'SQL', sqlExpression: 'price > 10' }, ], }; const [query] = buildQuery(formData as HistogramFormData).queries; expect(query.metrics).toBeUndefined(); }); ``` -- 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]
