@@ -11,10 +11,10 @@ import {resetMockDate, setMockDate} from 'sentry-test/utils';
1111import { PageFiltersStore } from 'sentry/components/pageFilters/store' ;
1212import { MemberListStore } from 'sentry/stores/memberListStore' ;
1313import { MEPSettingProvider } from 'sentry/utils/performance/contexts/metricsEnhancedSetting' ;
14- import { useChartInterval } from 'sentry/utils/useChartInterval' ;
1514import { useLocation } from 'sentry/utils/useLocation' ;
1615import { Dashboard } from 'sentry/views/dashboards/dashboard' ;
1716import { FiltersBar } from 'sentry/views/dashboards/filtersBar' ;
17+ import { useDashboardChartInterval } from 'sentry/views/dashboards/hooks/useDashboardChartInterval' ;
1818import type {
1919 DashboardDetails ,
2020 DashboardFilters ,
@@ -499,7 +499,7 @@ describe('Dashboards > Dashboard', () => {
499499 dashboard ?: DashboardDetails ;
500500 } = { } ) {
501501 const location = useLocation ( ) ;
502- const [ widgetInterval ] = useChartInterval ( ) ;
502+ const [ widgetInterval ] = useDashboardChartInterval ( ) ;
503503 return (
504504 < MEPSettingProvider forceTransactions = { false } >
505505 < FiltersBar
@@ -541,12 +541,12 @@ describe('Dashboards > Dashboard', () => {
541541 } ) ;
542542
543543 describe ( 'no interval set in URL' , ( ) => {
544- it ( 'defaults to the smallest valid interval for the dashboard period' , async ( ) => {
545- const fiveMinuteMock = MockApiClient . addMockResponse ( {
544+ it ( 'defaults to the second-biggest valid interval for the dashboard period' , async ( ) => {
545+ const tenMinuteMock = MockApiClient . addMockResponse ( {
546546 url : '/organizations/org-slug/events-stats/' ,
547547 method : 'GET' ,
548548 body : [ ] ,
549- match : [ MockApiClient . matchQuery ( { interval : '5m ' } ) ] ,
549+ match : [ MockApiClient . matchQuery ( { interval : '10m ' } ) ] ,
550550 } ) ;
551551 const thirtyMinuteMock = MockApiClient . addMockResponse ( {
552552 url : '/organizations/org-slug/events-stats/' ,
@@ -555,21 +555,21 @@ describe('Dashboards > Dashboard', () => {
555555 match : [ MockApiClient . matchQuery ( { interval : '30m' } ) ] ,
556556 } ) ;
557557
558- // No interval in the URL — the 5m default is derived purely from the
559- // dashboard's saved 24h period via PageFiltersStore → useChartInterval .
558+ // No interval in the URL — the 10m default (second-biggest of [5m, 10m, 30m])
559+ // is derived from the dashboard's saved 24h period via useDashboardChartInterval .
560560 const { router} = render ( < DashboardWithIntervalSelector /> , {
561561 organization : orgWithFlag ,
562562 initialRouterConfig : { location : { pathname : '/' } } ,
563563 } ) ;
564564
565565 await screen . findByText ( 'Test Spans Widget' ) ;
566- await waitFor ( ( ) => expect ( fiveMinuteMock ) . toHaveBeenCalled ( ) ) ;
566+ await waitFor ( ( ) => expect ( tenMinuteMock ) . toHaveBeenCalled ( ) ) ;
567567 expect ( thirtyMinuteMock ) . not . toHaveBeenCalled ( ) ;
568568
569569 // Click the interval selector and choose '30 minutes'. FiltersBar writes
570570 // interval=30m to the URL, DashboardWithIntervalSelector re-renders with
571571 // the new widgetInterval, and the widget re-fetches with the new interval.
572- await userEvent . click ( screen . getByRole ( 'button' , { name : '5 minutes' } ) ) ;
572+ await userEvent . click ( screen . getByRole ( 'button' , { name : '10 minutes' } ) ) ;
573573 await userEvent . click ( screen . getByRole ( 'option' , { name : '30 minutes' } ) ) ;
574574
575575 await waitFor ( ( ) => expect ( thirtyMinuteMock ) . toHaveBeenCalled ( ) ) ;
@@ -632,11 +632,11 @@ describe('Dashboards > Dashboard', () => {
632632 } ) ;
633633
634634 it ( 'ignores the URL interval and falls back to the period default' , async ( ) => {
635- const threeHourMock = MockApiClient . addMockResponse ( {
635+ const sixHourMock = MockApiClient . addMockResponse ( {
636636 url : '/organizations/org-slug/events-stats/' ,
637637 method : 'GET' ,
638638 body : [ ] ,
639- match : [ MockApiClient . matchQuery ( { interval : '3h ' } ) ] ,
639+ match : [ MockApiClient . matchQuery ( { interval : '6h ' } ) ] ,
640640 } ) ;
641641 const fiveMinuteMock = MockApiClient . addMockResponse ( {
642642 url : '/organizations/org-slug/events-stats/' ,
@@ -653,11 +653,12 @@ describe('Dashboards > Dashboard', () => {
653653
654654 await screen . findByText ( 'Test Spans Widget' ) ;
655655
656- // The selector should show the period-derived default, not the invalid URL value.
657- expect ( screen . getByRole ( 'button' , { name : '3 hours' } ) ) . toBeInTheDocument ( ) ;
656+ // The selector should show the period-derived default (6h = second-biggest
657+ // of [3h, 6h, 12h]), not the invalid URL value (5m).
658+ expect ( screen . getByRole ( 'button' , { name : '6 hours' } ) ) . toBeInTheDocument ( ) ;
658659
659660 // The widget should query with the valid default interval, not the URL value.
660- await waitFor ( ( ) => expect ( threeHourMock ) . toHaveBeenCalled ( ) ) ;
661+ await waitFor ( ( ) => expect ( sixHourMock ) . toHaveBeenCalled ( ) ) ;
661662 expect ( fiveMinuteMock ) . not . toHaveBeenCalled ( ) ;
662663 } ) ;
663664 } ) ;
@@ -681,11 +682,11 @@ describe('Dashboards > Dashboard', () => {
681682 it ( 'ignores the URL interval and falls back to the period default' , async ( ) => {
682683 // Uses the /sessions/ endpoint (session.status in columns → useSessionAPI=true),
683684 // which surfaces the "intervals too granular" error in production.
684- const threeHourMock = MockApiClient . addMockResponse ( {
685+ const sixHourMock = MockApiClient . addMockResponse ( {
685686 url : '/organizations/org-slug/sessions/' ,
686687 method : 'GET' ,
687688 body : emptySessionsBody ,
688- match : [ MockApiClient . matchQuery ( { interval : '3h ' } ) ] ,
689+ match : [ MockApiClient . matchQuery ( { interval : '6h ' } ) ] ,
689690 } ) ;
690691 const fiveMinuteMock = MockApiClient . addMockResponse ( {
691692 url : '/organizations/org-slug/sessions/' ,
@@ -701,13 +702,13 @@ describe('Dashboards > Dashboard', () => {
701702
702703 await screen . findByText ( 'Test Releases Widget' ) ;
703704
704- // The selector should show the period-derived default (3h), not the
705- // invalid URL value (5m).
706- expect ( screen . getByRole ( 'button' , { name : '3 hours' } ) ) . toBeInTheDocument ( ) ;
705+ // The selector should show the period-derived default (6h = second-biggest
706+ // of [3h, 6h, 12h]), not the invalid URL value (5m).
707+ expect ( screen . getByRole ( 'button' , { name : '6 hours' } ) ) . toBeInTheDocument ( ) ;
707708
708709 // The widget should query the sessions endpoint with the valid default
709710 // interval, not the 5m value from the URL.
710- await waitFor ( ( ) => expect ( threeHourMock ) . toHaveBeenCalled ( ) ) ;
711+ await waitFor ( ( ) => expect ( sixHourMock ) . toHaveBeenCalled ( ) ) ;
711712 expect ( fiveMinuteMock ) . not . toHaveBeenCalled ( ) ;
712713 } ) ;
713714 } ) ;
0 commit comments