1
1
import { createLogFixtures , initializeLogsTest } from 'sentry-fixture/log' ;
2
+ import { ProjectKeysFixture } from 'sentry-fixture/projectKeys' ;
3
+ import { TeamFixture } from 'sentry-fixture/team' ;
2
4
3
5
import { render , screen , userEvent , waitFor } from 'sentry-test/reactTestingLibrary' ;
4
6
7
+ import * as useRecentCreatedProjectHook from 'sentry/components/onboarding/useRecentCreatedProject' ;
8
+ import ProjectsStore from 'sentry/stores/projectsStore' ;
9
+ import TeamStore from 'sentry/stores/teamStore' ;
10
+ import type { Organization } from 'sentry/types/organization' ;
11
+ import type { Project } from 'sentry/types/project' ;
5
12
import { LOGS_AUTO_REFRESH_KEY } from 'sentry/views/explore/contexts/logs/logsAutoRefreshContext' ;
13
+ import type { OurLogsResponseItem } from 'sentry/views/explore/logs/types' ;
6
14
7
15
import LogsPage from './content' ;
8
16
9
17
describe ( 'LogsPage' , function ( ) {
10
- const { organization, project , setupPageFilters , setupEventsMock } = initializeLogsTest ( ) ;
11
-
12
- setupPageFilters ( ) ;
18
+ let organization : Organization ;
19
+ let project : Project ;
20
+ let testDate : Date ;
13
21
14
22
let eventTableMock : jest . Mock ;
15
23
let eventStatsMock : jest . Mock ;
16
24
17
- // Standard log fixtures for consistent testing
18
- const testDate = new Date ( '2024-01-15T10:00:00.000Z' ) ;
19
- const { baseFixtures} = createLogFixtures ( organization , project , testDate ) ;
20
-
21
25
beforeEach ( function ( ) {
22
26
MockApiClient . clearMockResponses ( ) ;
27
+ const {
28
+ organization : _organization ,
29
+ project : _project ,
30
+ setupPageFilters,
31
+ setupEventsMock,
32
+ } = initializeLogsTest ( ) ;
33
+
34
+ organization = _organization ;
35
+ project = _project ;
36
+
37
+ setupPageFilters ( ) ;
38
+
39
+ // Standard log fixtures for consistent testing
40
+ testDate = new Date ( '2024-01-15T10:00:00.000Z' ) ;
41
+ const { baseFixtures} = createLogFixtures ( organization , project , testDate ) ;
23
42
24
43
eventTableMock = setupEventsMock ( baseFixtures . slice ( 0 , 2 ) ) ;
25
44
@@ -79,6 +98,56 @@ describe('LogsPage', function () {
79
98
expect ( table ) . toHaveTextContent ( / U s e r l o g i n s u c c e s s f u l / ) ;
80
99
} ) ;
81
100
101
+ it ( 'should show onboarding when project is not onboarded' , async function ( ) {
102
+ ProjectsStore . reset ( ) ;
103
+ const {
104
+ organization : onboardingOrganization ,
105
+ project : onboardingProject ,
106
+ setupPageFilters : onboardingSetupPageFilters ,
107
+ } = initializeLogsTest ( {
108
+ project : {
109
+ hasLogs : false ,
110
+ platform : 'javascript-react' ,
111
+ } ,
112
+ } ) ;
113
+ TeamStore . loadInitialData ( [ TeamFixture ( ) ] ) ;
114
+ const projectSlugMock = MockApiClient . addMockResponse ( {
115
+ url : `/projects/${ onboardingOrganization . slug } /${ onboardingProject . slug } /keys/` ,
116
+ method : 'GET' ,
117
+ body : [ ProjectKeysFixture ( ) [ 0 ] ] ,
118
+ } ) ;
119
+ const sdkMock = MockApiClient . addMockResponse ( {
120
+ url : `/organizations/${ onboardingOrganization . slug } /sdks/` ,
121
+ method : 'GET' ,
122
+ body : [ ] ,
123
+ } ) ;
124
+
125
+ jest
126
+ . spyOn ( useRecentCreatedProjectHook , 'useRecentCreatedProject' )
127
+ . mockImplementation ( ( ) => {
128
+ return {
129
+ project : onboardingProject ,
130
+ isProjectActive : true ,
131
+ } ;
132
+ } ) ;
133
+
134
+ onboardingSetupPageFilters ( ) ;
135
+
136
+ render ( < LogsPage /> , {
137
+ organization,
138
+ initialRouterConfig : {
139
+ location : `/organizations/${ organization . slug } /explore/logs/` ,
140
+ } ,
141
+ } ) ;
142
+
143
+ expect ( projectSlugMock ) . toHaveBeenCalled ( ) ;
144
+ expect ( sdkMock ) . toHaveBeenCalled ( ) ;
145
+
146
+ await waitFor ( ( ) => {
147
+ expect ( screen . getByText ( 'Your Source for Log-ical Data' ) ) . toBeInTheDocument ( ) ;
148
+ } ) ;
149
+ } ) ;
150
+
82
151
it ( 'should call aggregates APIs as expected' , async function ( ) {
83
152
render ( < LogsPage /> , {
84
153
organization,
@@ -137,34 +206,39 @@ describe('LogsPage', function () {
137
206
} ) ;
138
207
139
208
describe ( 'autorefresh flag enabled' , ( ) => {
140
- const {
141
- organization : autorefreshOrganization ,
142
- setupEventsMock : _setupEventsMock ,
143
- setupTraceItemsMock : _setupTraceItemsMock ,
144
- generateRouterConfig,
145
- routerConfig : initialRouterConfig ,
146
- } = initializeLogsTest ( {
147
- refreshInterval : '10000' , // 10 seconds, should not first events multiple times.
148
- liveRefresh : true ,
149
- } ) ;
150
-
151
- const { baseFixtures : autorefreshBaseFixtures } = createLogFixtures (
152
- autorefreshOrganization ,
153
- project ,
154
- testDate ,
155
- {
156
- intervalMs : 24 * 60 * 60 * 1000 , // 24 hours
157
- }
158
- ) ;
209
+ let initialRouterConfig : ReturnType < typeof initializeLogsTest > [ 'routerConfig' ] ;
210
+ let autorefreshBaseFixtures : OurLogsResponseItem [ ] ;
211
+ let setupTraceItemsMock : ReturnType < typeof initializeLogsTest > [ 'setupTraceItemsMock' ] ;
212
+ let setupEventsMock : ReturnType < typeof initializeLogsTest > [ 'setupEventsMock' ] ;
159
213
160
214
beforeEach ( ( ) => {
161
215
eventTableMock . mockClear ( ) ;
162
- eventTableMock = _setupEventsMock ( autorefreshBaseFixtures . slice ( 0 , 5 ) ) ;
216
+
217
+ const {
218
+ organization : autorefreshOrganization ,
219
+ setupEventsMock : _setupEventsMock ,
220
+ project : _project ,
221
+ setupTraceItemsMock : _setupTraceItemsMock ,
222
+ routerConfig,
223
+ } = initializeLogsTest ( {
224
+ refreshInterval : '10000' , // 10 seconds, should not first events multiple times.
225
+ liveRefresh : true ,
226
+ } ) ;
227
+ organization = autorefreshOrganization ;
228
+ project = _project ;
229
+ initialRouterConfig = routerConfig ;
230
+ setupTraceItemsMock = _setupTraceItemsMock ;
231
+ setupEventsMock = _setupEventsMock ;
232
+ const { baseFixtures} = createLogFixtures ( organization , project , testDate , {
233
+ intervalMs : 24 * 60 * 60 * 1000 , // 24 hours
234
+ } ) ;
235
+ eventTableMock = _setupEventsMock ( baseFixtures . slice ( 0 , 5 ) ) ;
236
+ autorefreshBaseFixtures = baseFixtures ;
163
237
} ) ;
164
238
165
239
it ( 'enables autorefresh when Switch is clicked' , async function ( ) {
166
240
render ( < LogsPage /> , {
167
- organization : autorefreshOrganization ,
241
+ organization,
168
242
initialRouterConfig,
169
243
} ) ;
170
244
@@ -185,10 +259,17 @@ describe('LogsPage', function () {
185
259
186
260
it ( 'pauses auto-refresh when enabled switch is clicked' , async function ( ) {
187
261
const { router} = render ( < LogsPage /> , {
188
- organization : autorefreshOrganization ,
189
- initialRouterConfig : generateRouterConfig ( {
190
- [ LOGS_AUTO_REFRESH_KEY ] : 'enabled' ,
191
- } ) ,
262
+ organization,
263
+ initialRouterConfig : {
264
+ ...initialRouterConfig ,
265
+ location : {
266
+ ...initialRouterConfig . location ,
267
+ query : {
268
+ ...initialRouterConfig . location . query ,
269
+ [ LOGS_AUTO_REFRESH_KEY ] : 'enabled' ,
270
+ } ,
271
+ } ,
272
+ } ,
192
273
} ) ;
193
274
expect ( router . location . query [ LOGS_AUTO_REFRESH_KEY ] ) . toBe ( 'enabled' ) ;
194
275
@@ -208,12 +289,19 @@ describe('LogsPage', function () {
208
289
} ) ;
209
290
210
291
it ( 'pauses auto-refresh when row is clicked' , async function ( ) {
211
- const rowDetailsMock = _setupTraceItemsMock ( autorefreshBaseFixtures . slice ( 0 , 1 ) ) [ 0 ] ;
292
+ const rowDetailsMock = setupTraceItemsMock ( autorefreshBaseFixtures . slice ( 0 , 1 ) ) [ 0 ] ;
212
293
const { router} = render ( < LogsPage /> , {
213
- organization : autorefreshOrganization ,
214
- initialRouterConfig : generateRouterConfig ( {
215
- [ LOGS_AUTO_REFRESH_KEY ] : 'enabled' ,
216
- } ) ,
294
+ organization,
295
+ initialRouterConfig : {
296
+ ...initialRouterConfig ,
297
+ location : {
298
+ ...initialRouterConfig . location ,
299
+ query : {
300
+ ...initialRouterConfig . location . query ,
301
+ [ LOGS_AUTO_REFRESH_KEY ] : 'enabled' ,
302
+ } ,
303
+ } ,
304
+ } ,
217
305
} ) ;
218
306
219
307
expect ( router . location . query [ LOGS_AUTO_REFRESH_KEY ] ) . toBe ( 'enabled' ) ;
@@ -243,7 +331,7 @@ describe('LogsPage', function () {
243
331
244
332
expect ( eventTableMock ) . toHaveBeenCalledTimes ( 1 ) ;
245
333
eventTableMock . mockClear ( ) ;
246
- eventTableMock = _setupEventsMock ( autorefreshBaseFixtures . slice ( 0 , 5 ) ) ;
334
+ eventTableMock = setupEventsMock ( autorefreshBaseFixtures . slice ( 0 , 5 ) ) ;
247
335
248
336
await userEvent . click ( switchInput ) ;
249
337
0 commit comments