projectApdexScoreCard.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import ProjectApdexScoreCard from 'sentry/views/projectDetail/projectScoreCards/projectApdexScoreCard';
  4. describe('ProjectDetail > ProjectApdex', function () {
  5. let currentDataEndpointMock: jest.Mock;
  6. let previousDataEndpointMock: jest.Mock;
  7. const organization = OrganizationFixture();
  8. const selection = {
  9. projects: [1],
  10. environments: [],
  11. datetime: {
  12. start: null,
  13. end: null,
  14. period: '14d',
  15. utc: null,
  16. },
  17. };
  18. afterEach(function () {
  19. MockApiClient.clearMockResponses();
  20. });
  21. it('renders apdex', async function () {
  22. previousDataEndpointMock = MockApiClient.addMockResponse({
  23. url: `/organizations/${organization.slug}/events/`,
  24. body: {
  25. data: [
  26. {
  27. 'apdex()': 0.678,
  28. },
  29. ],
  30. },
  31. status: 200,
  32. });
  33. currentDataEndpointMock = MockApiClient.addMockResponse({
  34. url: `/organizations/${organization.slug}/events/`,
  35. body: {
  36. data: [
  37. {
  38. 'apdex()': 0.781,
  39. },
  40. ],
  41. },
  42. status: 200,
  43. match: [MockApiClient.matchQuery({statsPeriod: '14d'})],
  44. });
  45. render(
  46. <ProjectApdexScoreCard
  47. organization={{...organization, features: ['discover-basic', 'performance-view']}}
  48. selection={selection}
  49. isProjectStabilized
  50. hasTransactions
  51. />
  52. );
  53. expect(await screen.findByText('Apdex')).toBeInTheDocument();
  54. expect(await screen.findByText('0.781')).toBeInTheDocument();
  55. expect(await screen.findByText('0.102')).toBeInTheDocument();
  56. expect(currentDataEndpointMock).toHaveBeenNthCalledWith(
  57. 1,
  58. `/organizations/${organization.slug}/events/`,
  59. expect.objectContaining({
  60. query: {
  61. environment: [],
  62. field: ['apdex()'],
  63. project: ['1'],
  64. query: 'event.type:transaction count():>0',
  65. statsPeriod: '14d',
  66. },
  67. })
  68. );
  69. expect(previousDataEndpointMock).toHaveBeenNthCalledWith(
  70. 1,
  71. `/organizations/${organization.slug}/events/`,
  72. expect.objectContaining({
  73. query: {
  74. environment: [],
  75. field: ['apdex()'],
  76. project: ['1'],
  77. query: 'event.type:transaction count():>0',
  78. start: '2017-09-19T02:41:20',
  79. end: '2017-10-03T02:41:20',
  80. },
  81. })
  82. );
  83. });
  84. it('renders without performance', async function () {
  85. const endpointMock = MockApiClient.addMockResponse({
  86. url: `/organizations/${organization.slug}/events/`,
  87. body: {
  88. detail: 'test error',
  89. },
  90. status: 404,
  91. });
  92. render(
  93. <ProjectApdexScoreCard
  94. organization={{...organization, features: ['performance-view']}}
  95. hasTransactions={false}
  96. selection={selection}
  97. isProjectStabilized
  98. query="test-query"
  99. />
  100. );
  101. expect(await screen.findByText('Apdex')).toBeInTheDocument();
  102. expect(await screen.findByRole('button', {name: 'Start Setup'})).toBeInTheDocument();
  103. expect(await screen.findByRole('button', {name: 'Get Tour'})).toBeInTheDocument();
  104. expect(endpointMock).not.toHaveBeenCalled();
  105. });
  106. });