FrancescoCastaldi commented on code in PR #45039:
URL: https://github.com/apache/superset/pull/45039#discussion_r4243558309


##########
superset-frontend/src/dashboard/components/RefreshFrequency/RefreshFrequencySelect.test.tsx:
##########
@@ -38,3 +45,210 @@ test('getRefreshWarningMessage normalizes refreshLimit', () 
=> {
   expect(getRefreshWarningMessage(5, 10, 'warn')).toBe('warn');
   expect(getRefreshWarningMessage(15, 10000, 'warn')).toBeNull();
 });
+
+const mockConfiguredIntervals: [number, string][] = [
+  [0, "Don't refresh"],
+  [15, '15 seconds'],
+  [45, '45 seconds'],
+  [90, '90 seconds'],
+];
+
+const createInitialState = (
+  intervals?: [number, string][],
+  extraConf?: Record<string, unknown>,
+) => ({
+  dashboardInfo: {
+    common: {
+      conf: {
+        ...(intervals !== undefined
+          ? { DASHBOARD_AUTO_REFRESH_INTERVALS: intervals }
+          : {}),
+        ...extraConf,
+      },
+    },
+  },
+});
+
+const defaultTestProps = {
+  value: 0,
+  onChange: jest.fn(),
+};
+
+const setup = (
+  props: Partial<typeof defaultTestProps> = {},
+  initialState?: object,
+) =>
+  render(<RefreshFrequencySelect {...defaultTestProps} {...props} />, {
+    useRedux: true,
+    ...(initialState ? { initialState } : {}),
+  });
+
+test('renders configured auto refresh intervals from redux store', () => {
+  setup({}, createInitialState(mockConfiguredIntervals));
+
+  expect(screen.getByRole('radio', { name: '15 seconds' 
})).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: '45 seconds' 
})).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: '90 seconds' 
})).toBeInTheDocument();
+  expect(
+    screen.queryByRole('radio', { name: '10 seconds' }),
+  ).not.toBeInTheDocument();
+});
+
+test('renders default options when config is not present', () => {
+  setup({}, createInitialState(undefined));
+
+  expect(
+    screen.getByRole('radio', { name: "Don't refresh" }),
+  ).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: '10 seconds' 
})).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: '30 seconds' 
})).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: '1 minute' })).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: '24 hours' })).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: /Custom/i })).toBeInTheDocument();
+});
+
+test('renders default options when configured intervals is empty array', () => 
{
+  setup({}, createInitialState([]));
+
+  expect(screen.getByRole('radio', { name: '10 seconds' 
})).toBeInTheDocument();
+  expect(screen.getByRole('radio', { name: '30 seconds' 
})).toBeInTheDocument();
+});
+
+test('options prop takes precedence over redux store configured intervals', () 
=> {
+  const propOptions: [number, string][] = [
+    [5, '5 seconds'],
+    [25, '25 seconds'],
+  ];
+
+  setup({ options: propOptions }, createInitialState(mockConfiguredIntervals));

Review Comment:
   In `RefreshFrequencySelect.tsx`, `RefreshFrequencySelectProps` explicitly 
defines `options?: [number, string][]`, and the test helper `setup` accepts 
`Partial<RefreshFrequencySelectProps>`. Passing `options` is fully supported by 
the component interface and passes TypeScript checking.



##########
superset-frontend/src/dashboard/components/RefreshFrequency/RefreshFrequencySelect.tsx:
##########
@@ -141,7 +224,7 @@ export const RefreshFrequencySelect = ({
 
   return (
     <StyledRadioGroup value={radioSelection} onChange={handleRadioChange}>
-      {REFRESH_FREQUENCY_OPTIONS.slice(0, -1).map(option => (
+      {activeOptions.map((option) => (

Review Comment:
   Formatted in commit `1541e6586c` using `oxfmt --write` with `arrowParens: 
"avoid"` to align with `.oxfmtrc.json` and keep single-parameter arrow syntax 
across source and test files.



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