1
1
import type { UseQueryResult } from '@tanstack/react-query' ;
2
2
import { BroadcastFixture } from 'sentry-fixture/broadcast' ;
3
+ import { LocationFixture } from 'sentry-fixture/locationFixture' ;
3
4
import { OrganizationFixture } from 'sentry-fixture/organization' ;
4
5
import { ServiceIncidentFixture } from 'sentry-fixture/serviceIncident' ;
5
6
import { UserFixture } from 'sentry-fixture/user' ;
6
7
7
- import { initializeOrg } from 'sentry-test/initializeOrg' ;
8
8
import { act , render , screen , userEvent , waitFor } from 'sentry-test/reactTestingLibrary' ;
9
9
10
10
import { OnboardingContextProvider } from 'sentry/components/onboarding/onboardingContext' ;
11
11
import SidebarContainer from 'sentry/components/sidebar' ;
12
12
import ConfigStore from 'sentry/stores/configStore' ;
13
13
import type { Organization , StatuspageIncident } from 'sentry/types' ;
14
+ import { useLocation } from 'sentry/utils/useLocation' ;
14
15
import * as incidentsHook from 'sentry/utils/useServiceIncidents' ;
15
16
16
17
jest . mock ( 'sentry/utils/useServiceIncidents' ) ;
18
+ jest . mock ( 'sentry/utils/useLocation' ) ;
19
+
20
+ const mockUseLocation = jest . mocked ( useLocation ) ;
17
21
18
22
const sidebarAccordionFeatures = [
19
23
'performance-view' ,
@@ -23,7 +27,7 @@ const sidebarAccordionFeatures = [
23
27
] ;
24
28
25
29
describe ( 'Sidebar' , function ( ) {
26
- const { organization, routerContext } = initializeOrg ( ) ;
30
+ const organization = OrganizationFixture ( ) ;
27
31
const broadcast = BroadcastFixture ( ) ;
28
32
const user = UserFixture ( ) ;
29
33
const apiMocks = {
@@ -39,9 +43,10 @@ describe('Sidebar', function () {
39
43
) ;
40
44
41
45
const renderSidebar = ( { organization : org } : { organization : Organization | null } ) =>
42
- render ( getElement ( ) , { context : routerContext , organization : org } ) ;
46
+ render ( getElement ( ) , { organization : org } ) ;
43
47
44
48
beforeEach ( function ( ) {
49
+ mockUseLocation . mockReset ( ) ;
45
50
jest . spyOn ( incidentsHook , 'useServiceIncidents' ) . mockImplementation (
46
51
( ) =>
47
52
( {
@@ -149,11 +154,9 @@ describe('Sidebar', function () {
149
154
expect ( await screen . findByRole ( 'dialog' ) ) . toBeInTheDocument ( ) ;
150
155
expect ( screen . getByText ( "What's new in Sentry" ) ) . toBeInTheDocument ( ) ;
151
156
152
- const oldPath = routerContext . context . location . pathname ;
153
- routerContext . context . location . pathname = '/other/path' ;
157
+ mockUseLocation . mockReturnValue ( { ...LocationFixture ( ) , pathname : '/other/path' } ) ;
154
158
rerender ( getElement ( ) ) ;
155
159
expect ( screen . queryByText ( "What's new in Sentry" ) ) . not . toBeInTheDocument ( ) ;
156
- routerContext . context . location . pathname = oldPath ;
157
160
} ) ;
158
161
159
162
it ( 'can have onboarding feature' , async function ( ) {
0 commit comments