Skip to content

Commit 5830719

Browse files
committed
✅ tests for detector settings!
1 parent 348d3ab commit 5830719

File tree

2 files changed

+141
-17
lines changed

2 files changed

+141
-17
lines changed

static/app/views/settings/projectPerformance/projectPerformance.spec.tsx

Lines changed: 130 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,38 @@ import ProjectPerformance, {
1919
DetectorConfigCustomer,
2020
} from 'sentry/views/settings/projectPerformance/projectPerformance';
2121

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+
2254
describe('projectPerformance', function () {
2355
const org = OrganizationFixture({features: ['performance-view']});
2456
const project = ProjectFixture();
@@ -145,13 +177,11 @@ describe('projectPerformance', function () {
145177
initialRouterConfig,
146178
});
147179

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();
152182

153183
const toggle = screen.getByRole('checkbox', {
154-
name: 'N+1 DB Queries Detection Enabled',
184+
name: 'N+1 DB Queries Detection',
155185
});
156186
await userEvent.click(toggle);
157187

@@ -419,4 +449,99 @@ describe('projectPerformance', function () {
419449

420450
expect(delete_request_mock).toHaveBeenCalled();
421451
});
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+
);
422547
});

static/app/views/settings/projectPerformance/projectPerformance.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ function ProjectPerformance() {
340340
[IssueTitle.PERFORMANCE_N_PLUS_ONE_DB_QUERIES]: {
341341
name: DetectorConfigAdmin.N_PLUS_DB_ENABLED,
342342
type: 'boolean',
343-
label: t('N+1 DB Queries Detection Enabled'),
343+
label: t('N+1 DB Queries Detection'),
344344
defaultValue: true,
345345
onChange: value => {
346346
setApiQueryData<ProjectPerformanceSettings>(
@@ -356,7 +356,7 @@ function ProjectPerformance() {
356356
[IssueTitle.PERFORMANCE_SLOW_DB_QUERY]: {
357357
name: DetectorConfigAdmin.SLOW_DB_ENABLED,
358358
type: 'boolean',
359-
label: t('Slow DB Queries Detection Enabled'),
359+
label: t('Slow DB Queries Detection'),
360360
defaultValue: true,
361361
onChange: value => {
362362
setApiQueryData<ProjectPerformanceSettings>(
@@ -372,7 +372,7 @@ function ProjectPerformance() {
372372
[IssueTitle.PERFORMANCE_N_PLUS_ONE_API_CALLS]: {
373373
name: DetectorConfigAdmin.N_PLUS_ONE_API_CALLS_ENABLED,
374374
type: 'boolean',
375-
label: t('N+1 API Calls Detection Enabled'),
375+
label: t('N+1 API Calls Detection'),
376376
defaultValue: true,
377377
onChange: value => {
378378
setApiQueryData<ProjectPerformanceSettings>(
@@ -388,7 +388,7 @@ function ProjectPerformance() {
388388
[IssueTitle.PERFORMANCE_RENDER_BLOCKING_ASSET]: {
389389
name: DetectorConfigAdmin.RENDER_BLOCK_ASSET_ENABLED,
390390
type: 'boolean',
391-
label: t('Large Render Blocking Asset Detection Enabled'),
391+
label: t('Large Render Blocking Asset Detection'),
392392
defaultValue: true,
393393
onChange: value => {
394394
setApiQueryData<ProjectPerformanceSettings>(
@@ -404,7 +404,7 @@ function ProjectPerformance() {
404404
[IssueTitle.PERFORMANCE_CONSECUTIVE_DB_QUERIES]: {
405405
name: DetectorConfigAdmin.CONSECUTIVE_DB_ENABLED,
406406
type: 'boolean',
407-
label: t('Consecutive DB Queries Detection Enabled'),
407+
label: t('Consecutive DB Queries Detection'),
408408
defaultValue: true,
409409
onChange: value => {
410410
setApiQueryData<ProjectPerformanceSettings>(
@@ -420,7 +420,7 @@ function ProjectPerformance() {
420420
[IssueTitle.PERFORMANCE_LARGE_HTTP_PAYLOAD]: {
421421
name: DetectorConfigAdmin.LARGE_HTTP_PAYLOAD_ENABLED,
422422
type: 'boolean',
423-
label: t('Large HTTP Payload Detection Enabled'),
423+
label: t('Large HTTP Payload Detection'),
424424
defaultValue: true,
425425
onChange: value => {
426426
setApiQueryData<ProjectPerformanceSettings>(
@@ -436,7 +436,7 @@ function ProjectPerformance() {
436436
[IssueTitle.PERFORMANCE_DB_MAIN_THREAD]: {
437437
name: DetectorConfigAdmin.DB_MAIN_THREAD_ENABLED,
438438
type: 'boolean',
439-
label: t('DB On Main Thread Detection Enabled'),
439+
label: t('DB on Main Thread Detection'),
440440
defaultValue: true,
441441
onChange: value => {
442442
setApiQueryData<ProjectPerformanceSettings>(
@@ -452,7 +452,7 @@ function ProjectPerformance() {
452452
[IssueTitle.PERFORMANCE_FILE_IO_MAIN_THREAD]: {
453453
name: DetectorConfigAdmin.FILE_IO_ENABLED,
454454
type: 'boolean',
455-
label: t('File I/O on Main Thread Detection Enabled'),
455+
label: t('File I/O on Main Thread Detection'),
456456
defaultValue: true,
457457
onChange: value => {
458458
setApiQueryData<ProjectPerformanceSettings>(
@@ -468,7 +468,7 @@ function ProjectPerformance() {
468468
[IssueTitle.PERFORMANCE_UNCOMPRESSED_ASSET]: {
469469
name: DetectorConfigAdmin.UNCOMPRESSED_ASSET_ENABLED,
470470
type: 'boolean',
471-
label: t('Uncompressed Assets Detection Enabled'),
471+
label: t('Uncompressed Assets Detection'),
472472
defaultValue: true,
473473
onChange: value => {
474474
setApiQueryData<ProjectPerformanceSettings>(
@@ -484,7 +484,7 @@ function ProjectPerformance() {
484484
[IssueTitle.PERFORMANCE_CONSECUTIVE_HTTP]: {
485485
name: DetectorConfigAdmin.CONSECUTIVE_HTTP_ENABLED,
486486
type: 'boolean',
487-
label: t('Consecutive HTTP Detection Enabled'),
487+
label: t('Consecutive HTTP Detection'),
488488
defaultValue: true,
489489
onChange: value => {
490490
setApiQueryData<ProjectPerformanceSettings>(
@@ -500,7 +500,7 @@ function ProjectPerformance() {
500500
[IssueTitle.PERFORMANCE_HTTP_OVERHEAD]: {
501501
name: DetectorConfigAdmin.HTTP_OVERHEAD_ENABLED,
502502
type: 'boolean',
503-
label: t('HTTP/1.1 Overhead Enabled'),
503+
label: t('HTTP/1.1 Overhead Detection'),
504504
defaultValue: true,
505505
onChange: value => {
506506
setApiQueryData<ProjectPerformanceSettings>(
@@ -906,7 +906,6 @@ function ProjectPerformance() {
906906
fields: [
907907
{
908908
...manageField,
909-
label: t('Enable Issue Detection'),
910909
help: t(
911910
'Controls whether or not Sentry should detect this type of issue.'
912911
),

0 commit comments

Comments
 (0)