123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- import {mountWithTheme} from 'sentry-test/enzyme';
- import ProjectPerformance from 'sentry/views/settings/projectPerformance/projectPerformance';
- describe('projectPerformance', function () {
- const org = TestStubs.Organization({
- features: ['performance-view', 'performance-issues-dev'],
- });
- const project = TestStubs.ProjectDetails();
- const configUrl = '/projects/org-slug/project-slug/transaction-threshold/configure/';
- let getMock, postMock, deleteMock, performanceIssuesMock;
- beforeEach(function () {
- MockApiClient.clearMockResponses();
- getMock = MockApiClient.addMockResponse({
- url: configUrl,
- method: 'GET',
- body: {
- id: project.id,
- threshold: '300',
- metric: 'duration',
- },
- statusCode: 200,
- });
- postMock = MockApiClient.addMockResponse({
- url: configUrl,
- method: 'POST',
- body: {
- id: project.id,
- threshold: '400',
- metric: 'lcp',
- },
- statusCode: 200,
- });
- deleteMock = MockApiClient.addMockResponse({
- url: configUrl,
- method: 'DELETE',
- statusCode: 200,
- });
- MockApiClient.addMockResponse({
- url: '/projects/org-slug/project-slug/',
- method: 'GET',
- body: {},
- statusCode: 200,
- });
- performanceIssuesMock = MockApiClient.addMockResponse({
- url: '/projects/org-slug/project-slug/performance-issues/configure/',
- method: 'GET',
- body: {},
- statusCode: 200,
- });
- });
- it('renders the fields', async function () {
- const wrapper = mountWithTheme(
- <ProjectPerformance
- params={{orgId: org.slug, projectId: project.slug}}
- organization={org}
- project={project}
- />
- );
- await tick();
- expect(wrapper.find('input[name="threshold"]').prop('value')).toBe('300');
- expect(wrapper.find('input[name="metric"]').prop('value')).toBe('duration');
- expect(getMock).toHaveBeenCalledTimes(1);
- });
- it('updates the field', async function () {
- const wrapper = mountWithTheme(
- <ProjectPerformance
- params={{orgId: org.slug, projectId: project.slug}}
- organization={org}
- project={project}
- />
- );
- await tick();
- wrapper
- .find('input[name="threshold"]')
- .simulate('change', {target: {value: '400'}})
- .simulate('blur');
- await tick();
- expect(postMock).toHaveBeenCalledWith(
- configUrl,
- expect.objectContaining({
- data: {threshold: '400'},
- })
- );
- expect(wrapper.find('input[name="threshold"]').prop('value')).toBe('400');
- });
- it('clears the data', async function () {
- const wrapper = mountWithTheme(
- <ProjectPerformance
- params={{orgId: org.slug, projectId: project.slug}}
- organization={org}
- project={project}
- />
- );
- await tick();
- wrapper.find('Actions').find('Button').simulate('click');
- await tick();
- expect(deleteMock).toHaveBeenCalled();
- });
- it('does not get performance issues settings without the feature flag', async function () {
- const org_without_perf_issues = TestStubs.Organization({
- features: ['performance-view'],
- });
- mountWithTheme(
- <ProjectPerformance
- params={{orgId: org.slug, projectId: project.slug}}
- organization={org_without_perf_issues}
- project={project}
- />
- );
- await tick();
- expect(performanceIssuesMock).not.toHaveBeenCalled();
- });
- });
|