bito-code-review[bot] commented on code in PR #40512: URL: https://github.com/apache/superset/pull/40512#discussion_r3322539968
########## superset-frontend/src/dashboard/components/Header/useHeaderAutoRefresh.test.tsx: ########## @@ -0,0 +1,137 @@ +/** + * 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 { renderHook, act } from '@testing-library/react'; +import { Provider } from 'react-redux'; +import { createStore } from 'redux'; +import { ReactNode } from 'react'; +import { LOG_ACTIONS_FORCE_REFRESH_DASHBOARD } from 'src/logger/LogUtils'; +import { useHeaderAutoRefresh } from './useHeaderAutoRefresh'; + +jest.mock('src/dashboard/contexts/AutoRefreshContext', () => ({ + useAutoRefreshContext: () => ({ + startAutoRefresh: jest.fn(), + endAutoRefresh: jest.fn(), + setRefreshInFlight: jest.fn(), + }), +})); + +jest.mock('src/dashboard/hooks/useRealTimeDashboard', () => ({ + useRealTimeDashboard: () => ({ + isPaused: false, + setStatus: jest.fn(), + setPaused: jest.fn(), + setPausedByTab: jest.fn(), + recordSuccess: jest.fn(), + recordError: jest.fn(), + setFetchStartTime: jest.fn(), + autoRefreshPauseOnInactiveTab: false, + setPauseOnInactiveTab: jest.fn(), + }), +})); + +jest.mock('src/dashboard/hooks/useAutoRefreshTabPause', () => ({ + useAutoRefreshTabPause: jest.fn(), +})); + +const createWrapper = (conf: Record<string, unknown> = {}) => { + const store = createStore(() => ({ + charts: { + 1: { latestQueryFormData: { datasource: '1__table' } }, + 2: { latestQueryFormData: { datasource: '2__table' } }, + }, + dashboardInfo: { + common: { conf }, + }, + })); + return ({ children }: { children: ReactNode }) => ( + <Provider store={store}>{children}</Provider> + ); +}; + +const renderHeaderAutoRefresh = ( + conf: Record<string, unknown> = {}, + overrides = {}, +) => { + const props = { + chartIds: [1, 2], + dashboardId: 100, + refreshFrequency: 0, + timedRefreshImmuneSlices: [], + isLoading: false, + onRefresh: jest.fn().mockResolvedValue(undefined), + setRefreshFrequency: jest.fn(), + logEvent: jest.fn(), + ...overrides, + }; + const { result } = renderHook(() => useHeaderAutoRefresh(props), { + wrapper: createWrapper(conf), + }); + return { result, props }; +}; + +test('forceRefresh passes a non-zero interval by default so fetchCharts staggers the requests', async () => { + const { result, props } = renderHeaderAutoRefresh(); + + await act(async () => { + await result.current.forceRefresh(); + }); + + expect(props.onRefresh).toHaveBeenCalledTimes(1); + // onRefresh signature: (chartIds, force, interval, dashboardId, skipFiltersRefresh?) + const [chartIds, force, interval, dashboardId] = + props.onRefresh.mock.calls[0]; + expect(chartIds).toEqual([1, 2]); + expect(force).toBe(true); + expect(interval).toBeGreaterThan(0); + expect(dashboardId).toBe(100); +}); Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Missing exact default value assertion</b></div> <div id="fix"> The test at line 88 verifies `interval > 0` but does not assert the specific default value of 5000ms defined in the implementation (`DEFAULT_MANUAL_REFRESH_STAGGER_MS`). Per BITO.md rule [6262], tests should verify actual behavior, not approximate conditions. Without an exact assertion, a future regression could set the default to any non-zero value (e.g., 1ms or 10000ms) and still pass. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ``` --- superset-frontend/src/dashboard/components/Header/useHeaderAutoRefresh.test.tsx +++ superset-frontend/src/dashboard/components/Header/useHeaderAutoRefresh.test.tsx @@ -85,7 +85,7 @@ const renderHeaderAutoRefresh = ( }; -test('forceRefresh passes a non-zero interval by default so fetchCharts staggers the requests', async () => { +test('forceRefresh passes the default stagger interval (5000ms) when no config is provided', async () => { const { result, props } = renderHeaderAutoRefresh(); await act(async () => { @@ -98,7 +98,7 @@ test('forceRefresh passes a non-zero interval by default so fetchCharts staggers n expect(chartIds).toEqual([1, 2]); expect(force).toBe(true); - expect(interval).toBeGreaterThan(0); + expect(interval).toBe(5000); expect(dashboardId).toBe(100); }); ``` </div> </details> </div> <small><i>Code Review Run #8c2b98</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them -- 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]
