@@ -19,6 +19,38 @@ import ProjectPerformance, {
19
19
DetectorConfigCustomer ,
20
20
} from 'sentry/views/settings/projectPerformance/projectPerformance' ;
21
21
22
+ const manageDetectorData = [
23
+ { label : 'N+1 DB Queries Detection' , key : 'n_plus_one_db_queries_detection_enabled' } ,
24
+ { label : 'Slow DB Queries Detection' , key : 'slow_db_queries_detection_enabled' } ,
25
+ { label : 'DB on Main Thread Detection' , key : 'db_on_main_thread_detection_enabled' } ,
26
+ {
27
+ label : 'File I/O on Main Thread Detection' ,
28
+ key : 'file_io_on_main_thread_detection_enabled' ,
29
+ } ,
30
+ {
31
+ label : 'Consecutive DB Queries Detection' ,
32
+ key : 'consecutive_db_queries_detection_enabled' ,
33
+ } ,
34
+ {
35
+ label : 'Large Render Blocking Asset Detection' ,
36
+ key : 'large_render_blocking_asset_detection_enabled' ,
37
+ } ,
38
+ {
39
+ label : 'Uncompressed Assets Detection' ,
40
+ key : 'uncompressed_assets_detection_enabled' ,
41
+ } ,
42
+ { label : 'Large HTTP Payload Detection' , key : 'large_http_payload_detection_enabled' } ,
43
+ { label : 'N+1 API Calls Detection' , key : 'n_plus_one_api_calls_detection_enabled' } ,
44
+ {
45
+ label : 'Consecutive HTTP Detection' ,
46
+ key : 'consecutive_http_spans_detection_enabled' ,
47
+ } ,
48
+ {
49
+ label : 'HTTP/1.1 Overhead Detection' ,
50
+ key : 'http_overhead_detection_enabled' ,
51
+ } ,
52
+ ] ;
53
+
22
54
describe ( 'projectPerformance' , function ( ) {
23
55
const org = OrganizationFixture ( { features : [ 'performance-view' ] } ) ;
24
56
const project = ProjectFixture ( ) ;
@@ -145,13 +177,11 @@ describe('projectPerformance', function () {
145
177
initialRouterConfig,
146
178
} ) ;
147
179
148
- expect (
149
- await screen . findByText ( 'N+1 DB Queries Detection Enabled' )
150
- ) . toBeInTheDocument ( ) ;
151
- expect ( screen . getByText ( 'Slow DB Queries Detection Enabled' ) ) . toBeInTheDocument ( ) ;
180
+ expect ( await screen . findByText ( 'N+1 DB Queries Detection' ) ) . toBeInTheDocument ( ) ;
181
+ expect ( screen . getByText ( 'Slow DB Queries Detection' ) ) . toBeInTheDocument ( ) ;
152
182
153
183
const toggle = screen . getByRole ( 'checkbox' , {
154
- name : 'N+1 DB Queries Detection Enabled ' ,
184
+ name : 'N+1 DB Queries Detection' ,
155
185
} ) ;
156
186
await userEvent . click ( toggle ) ;
157
187
@@ -419,4 +449,99 @@ describe('projectPerformance', function () {
419
449
420
450
expect ( delete_request_mock ) . toHaveBeenCalled ( ) ;
421
451
} ) ;
452
+
453
+ it . each ( manageDetectorData ) (
454
+ 'allows project admins to manage $label' ,
455
+ async function ( { label, key} ) {
456
+ MockApiClient . addMockResponse ( {
457
+ url : '/projects/org-slug/project-slug/' ,
458
+ method : 'GET' ,
459
+ body : ProjectFixture ( { access : [ 'project:admin' ] } ) ,
460
+ statusCode : 200 ,
461
+ } ) ;
462
+
463
+ render ( < ProjectPerformance /> , {
464
+ organization : OrganizationFixture ( {
465
+ features : [ 'performance-view' , 'performance-manage-detectors' ] ,
466
+ } ) ,
467
+ initialRouterConfig,
468
+ } ) ;
469
+ await screen . findByText ( 'Performance Issues - Detector Threshold Settings' ) ;
470
+
471
+ // Hidden by form panels being collapsed
472
+ let toggle = screen . queryByRole < HTMLInputElement > ( 'checkbox' , { name : label } ) ;
473
+ expect ( toggle ) . not . toBeInTheDocument ( ) ;
474
+
475
+ const chevrons = screen . getAllByTestId ( 'form-panel-collapse-chevron' ) ;
476
+ for ( const chevron of chevrons ) {
477
+ await userEvent . click ( chevron ) ;
478
+ }
479
+
480
+ const mockPut = MockApiClient . addMockResponse ( {
481
+ url : '/projects/org-slug/project-slug/performance-issues/configure/' ,
482
+ method : 'PUT' ,
483
+ } ) ;
484
+
485
+ // Enabled by default
486
+ toggle = screen . getByRole < HTMLInputElement > ( 'checkbox' , { name : label } ) ;
487
+ expect ( toggle ) . toBeChecked ( ) ;
488
+
489
+ // Disable the detector
490
+ await userEvent . click ( toggle ) ;
491
+ expect ( mockPut ) . toHaveBeenCalledWith (
492
+ '/projects/org-slug/project-slug/performance-issues/configure/' ,
493
+ expect . objectContaining ( {
494
+ data : {
495
+ [ key ] : false ,
496
+ } ,
497
+ } )
498
+ ) ;
499
+ mockPut . mockClear ( ) ;
500
+ expect ( toggle ) . not . toBeChecked ( ) ;
501
+
502
+ // Re-enable the detector
503
+ await userEvent . click ( toggle ) ;
504
+ expect ( mockPut ) . toHaveBeenCalledWith (
505
+ '/projects/org-slug/project-slug/performance-issues/configure/' ,
506
+ expect . objectContaining ( {
507
+ data : {
508
+ [ key ] : true ,
509
+ } ,
510
+ } )
511
+ ) ;
512
+ expect ( toggle ) . toBeChecked ( ) ;
513
+ }
514
+ ) ;
515
+
516
+ it . each ( manageDetectorData ) (
517
+ 'does not allow non-admins to manage $label' ,
518
+ async function ( { label} ) {
519
+ MockApiClient . addMockResponse ( {
520
+ url : '/projects/org-slug/project-slug/' ,
521
+ method : 'GET' ,
522
+ body : ProjectFixture ( { access : [ 'project:read' ] } ) ,
523
+ statusCode : 200 ,
524
+ } ) ;
525
+
526
+ render ( < ProjectPerformance /> , {
527
+ organization : OrganizationFixture ( {
528
+ features : [ 'performance-view' , 'performance-manage-detectors' ] ,
529
+ } ) ,
530
+ initialRouterConfig,
531
+ } ) ;
532
+
533
+ await screen . findByText ( 'Performance Issues - Detector Threshold Settings' ) ;
534
+
535
+ let toggle = screen . queryByRole < HTMLInputElement > ( 'checkbox' , { name : label } ) ;
536
+ expect ( toggle ) . not . toBeInTheDocument ( ) ;
537
+
538
+ const chevrons = screen . getAllByTestId ( 'form-panel-collapse-chevron' ) ;
539
+ for ( const chevron of chevrons ) {
540
+ await userEvent . click ( chevron ) ;
541
+ }
542
+
543
+ toggle = screen . queryByRole < HTMLInputElement > ( 'checkbox' , { name : label } ) ;
544
+ expect ( toggle ) . toBeDisabled ( ) ;
545
+ }
546
+ ) ;
422
547
} ) ;
0 commit comments