|
1 | 1 | import {AutofixSetupFixture} from 'sentry-fixture/autofixSetupFixture'; |
2 | 2 | import {OrganizationFixture} from 'sentry-fixture/organization'; |
3 | 3 |
|
4 | | -import {act, renderHookWithProviders} from 'sentry-test/reactTestingLibrary'; |
| 4 | +import {act, renderHookWithProviders, waitFor} from 'sentry-test/reactTestingLibrary'; |
5 | 5 | import {setWindowLocation} from 'sentry-test/utils'; |
6 | 6 |
|
7 | 7 | import {TabKey, useActiveReplayTab} from 'sentry/utils/replays/hooks/useActiveReplayTab'; |
@@ -40,17 +40,25 @@ describe('useActiveReplayTab', () => { |
40 | 40 | expect(result.current.getActiveTab()).toBe(TabKey.AI); |
41 | 41 | }); |
42 | 42 |
|
43 | | - it('should set the default tab if the name is invalid', () => { |
| 43 | + it('should set the default tab if the name is invalid', async () => { |
44 | 44 | const {result, router} = renderHookWithProviders(useActiveReplayTab, { |
45 | 45 | initialProps: {}, |
| 46 | + initialRouterConfig: { |
| 47 | + location: {pathname: '/mock-pathname/', query: {query: 'click.tag:button'}}, |
| 48 | + }, |
46 | 49 | organization: OrganizationFixture({ |
47 | 50 | features: ['gen-ai-features', 'replay-ai-summaries'], |
48 | 51 | }), |
49 | 52 | }); |
50 | 53 | expect(result.current.getActiveTab()).toBe(TabKey.AI); |
51 | 54 |
|
52 | 55 | act(() => result.current.setActiveTab('foo bar')); |
53 | | - expect(router.location.query).toEqual({query: 'click.tag:button', t_main: 'ai'}); |
| 56 | + await waitFor(() => { |
| 57 | + expect(router.location.query).toEqual({ |
| 58 | + query: 'click.tag:button', |
| 59 | + t_main: 'ai', |
| 60 | + }); |
| 61 | + }); |
54 | 62 | }); |
55 | 63 |
|
56 | 64 | it('should use AI as default for video replays when replay-ai-summaries-mobile is enabled', () => { |
@@ -103,34 +111,43 @@ describe('useActiveReplayTab', () => { |
103 | 111 | expect(result.current.getActiveTab()).toBe(TabKey.BREADCRUMBS); |
104 | 112 | }); |
105 | 113 |
|
106 | | - it('should set the default tab if the name is invalid', () => { |
| 114 | + it('should set the default tab if the name is invalid', async () => { |
107 | 115 | const {result, router} = renderHookWithProviders(useActiveReplayTab, { |
108 | 116 | initialProps: {}, |
| 117 | + initialRouterConfig: { |
| 118 | + location: {pathname: '/mock-pathname/', query: {query: 'click.tag:button'}}, |
| 119 | + }, |
109 | 120 | organization: OrganizationFixture({features: []}), |
110 | 121 | }); |
111 | 122 | expect(result.current.getActiveTab()).toBe(TabKey.BREADCRUMBS); |
112 | 123 |
|
113 | 124 | act(() => result.current.setActiveTab('foo bar')); |
114 | | - expect(router.location.query).toEqual({ |
115 | | - query: 'click.tag:button', |
116 | | - t_main: 'breadcrumbs', |
| 125 | + await waitFor(() => { |
| 126 | + expect(router.location.query).toEqual({ |
| 127 | + query: 'click.tag:button', |
| 128 | + t_main: 'breadcrumbs', |
| 129 | + }); |
117 | 130 | }); |
118 | 131 | }); |
119 | 132 | }); |
120 | 133 | }); |
121 | 134 |
|
122 | | - it('should allow case-insensitive tab names', () => { |
| 135 | + it('should allow case-insensitive tab names', async () => { |
123 | 136 | const {result, router} = renderHookWithProviders(useActiveReplayTab, { |
124 | 137 | initialProps: {}, |
| 138 | + initialRouterConfig: { |
| 139 | + location: {pathname: '/mock-pathname/', query: {query: 'click.tag:button'}}, |
| 140 | + }, |
125 | 141 | organization: OrganizationFixture({features: []}), |
126 | 142 | }); |
127 | 143 | expect(result.current.getActiveTab()).toBe(TabKey.BREADCRUMBS); |
128 | 144 |
|
129 | 145 | act(() => result.current.setActiveTab('nEtWoRk')); |
130 | | - |
131 | | - expect(router.location.query).toEqual({ |
132 | | - query: 'click.tag:button', |
133 | | - t_main: 'network', |
| 146 | + await waitFor(() => { |
| 147 | + expect(router.location.query).toEqual({ |
| 148 | + query: 'click.tag:button', |
| 149 | + t_main: 'network', |
| 150 | + }); |
134 | 151 | }); |
135 | 152 | }); |
136 | 153 | }); |
0 commit comments