projectVelocityScoreCard.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import ProjectVelocityScoreCard from './projectVelocityScoreCard';
  4. describe('ProjectDetail > ProjectVelocity', function () {
  5. const organization = OrganizationFixture();
  6. const selection = {
  7. projects: [1],
  8. environments: [],
  9. datetime: {
  10. start: null,
  11. end: null,
  12. period: '14d',
  13. utc: null,
  14. },
  15. };
  16. afterEach(function () {
  17. MockApiClient.clearMockResponses();
  18. });
  19. it('renders release count', async function () {
  20. const previousDataEndpointMock = MockApiClient.addMockResponse({
  21. url: `/organizations/${organization.slug}/releases/stats/`,
  22. body: Array.from({length: 98}).map((_item, index) => ({
  23. version: `0.0.${index + 100}`,
  24. })),
  25. status: 200,
  26. });
  27. const currentDataEndpointMock = MockApiClient.addMockResponse({
  28. url: `/organizations/${organization.slug}/releases/stats/`,
  29. body: Array.from({length: 202}).map((_item, index) => ({
  30. version: `0.0.${index + 100}`,
  31. })),
  32. status: 200,
  33. match: [MockApiClient.matchQuery({statsPeriod: '14d'})],
  34. });
  35. render(
  36. <ProjectVelocityScoreCard
  37. organization={organization}
  38. selection={selection}
  39. isProjectStabilized
  40. />
  41. );
  42. expect(await screen.findByText('Number of Releases')).toBeInTheDocument();
  43. expect(await screen.findByText('202')).toBeInTheDocument();
  44. expect(await screen.findByText('104')).toBeInTheDocument();
  45. expect(currentDataEndpointMock).toHaveBeenCalledTimes(1);
  46. expect(currentDataEndpointMock).toHaveBeenNthCalledWith(
  47. 1,
  48. `/organizations/${organization.slug}/releases/stats/`,
  49. expect.objectContaining({
  50. query: {
  51. environment: [],
  52. project: 1,
  53. statsPeriod: '14d',
  54. },
  55. })
  56. );
  57. expect(previousDataEndpointMock).toHaveBeenCalledTimes(1);
  58. expect(previousDataEndpointMock).toHaveBeenNthCalledWith(
  59. 1,
  60. `/organizations/${organization.slug}/releases/stats/`,
  61. expect.objectContaining({
  62. query: {
  63. environment: [],
  64. project: 1,
  65. start: '2017-09-19T02:41:20',
  66. end: '2017-10-03T02:41:20',
  67. },
  68. })
  69. );
  70. });
  71. it('renders without releases', async function () {
  72. const dataEndpointMock = MockApiClient.addMockResponse({
  73. url: `/organizations/${organization.slug}/releases/stats/`,
  74. body: [],
  75. status: 200,
  76. });
  77. render(
  78. <ProjectVelocityScoreCard
  79. organization={{...organization, features: ['performance-view']}}
  80. selection={selection}
  81. isProjectStabilized
  82. />
  83. );
  84. expect(await screen.findByRole('button', {name: 'Start Setup'})).toBeInTheDocument();
  85. expect(await screen.findByRole('button', {name: 'Get Tour'})).toBeInTheDocument();
  86. expect(dataEndpointMock).toHaveBeenCalledTimes(3);
  87. });
  88. });