projectCard.spec.jsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import {render, screen, within} from 'sentry-test/reactTestingLibrary';
  2. import {ProjectCard} from 'sentry/views/projectsDashboard/projectCard';
  3. // NOTE: Unmocking debounce so that the actionCreator never fires
  4. jest.unmock('lodash/debounce');
  5. describe('ProjectCard', function () {
  6. const createWrapper = () =>
  7. render(
  8. <ProjectCard
  9. organization={TestStubs.Organization()}
  10. project={TestStubs.Project({
  11. stats: [
  12. [1525042800, 1],
  13. [1525046400, 2],
  14. ],
  15. transactionStats: [
  16. [1525042800, 4],
  17. [1525046400, 8],
  18. ],
  19. platform: 'javascript',
  20. })}
  21. params={{orgId: 'org-slug'}}
  22. />
  23. );
  24. afterEach(function () {
  25. MockApiClient.clearMockResponses();
  26. });
  27. it('renders', function () {
  28. const {container} = createWrapper();
  29. expect(container).toSnapshot();
  30. });
  31. it('renders latest 2 deploys', function () {
  32. const latestDeploys = {
  33. beta: {
  34. dateFinished: '2018-05-10T20:56:40.092Z',
  35. version: '123456',
  36. },
  37. staging: {
  38. dateFinished: '2018-05-08T20:56:40.092Z',
  39. version: '789789',
  40. },
  41. production: {
  42. dateFinished: '2018-05-09T20:56:40.092Z',
  43. version: '123123',
  44. },
  45. };
  46. render(
  47. <ProjectCard
  48. organization={TestStubs.Organization()}
  49. project={TestStubs.Project({
  50. stats: [
  51. [1525042800, 1],
  52. [1525046400, 2],
  53. ],
  54. platform: 'javascript',
  55. latestDeploys,
  56. })}
  57. params={{orgId: 'org-slug'}}
  58. />
  59. );
  60. expect(screen.queryByRole('button', {name: 'Track Deploys'})).not.toBeInTheDocument();
  61. expect(screen.getByText('beta')).toBeInTheDocument();
  62. expect(screen.getByText('production')).toBeInTheDocument();
  63. expect(screen.queryByText('staging')).not.toBeInTheDocument();
  64. });
  65. it('renders empty state if no deploys', function () {
  66. createWrapper();
  67. expect(screen.getByRole('button', {name: 'Track Deploys'})).toBeInTheDocument();
  68. });
  69. it('renders with platform', function () {
  70. createWrapper();
  71. expect(screen.getByRole('img')).toBeInTheDocument();
  72. expect(screen.getByTestId('platform-icon-javascript')).toBeInTheDocument();
  73. });
  74. it('renders header link for errors', function () {
  75. render(
  76. <ProjectCard
  77. organization={TestStubs.Organization()}
  78. project={TestStubs.Project({
  79. stats: [
  80. [1525042800, 3],
  81. [1525046400, 3],
  82. ],
  83. platform: 'javascript',
  84. })}
  85. params={{orgId: 'org-slug'}}
  86. />
  87. );
  88. expect(screen.getByTestId('project-errors')).toBeInTheDocument();
  89. expect(screen.getByText('Errors: 6')).toBeInTheDocument();
  90. // No transacions as the feature isn't set.
  91. expect(screen.queryByTestId('project-transactions')).not.toBeInTheDocument();
  92. });
  93. it('renders header link for transactions', function () {
  94. render(
  95. <ProjectCard
  96. organization={TestStubs.Organization({features: ['performance-view']})}
  97. project={TestStubs.Project({
  98. stats: [
  99. [1525042800, 3],
  100. [1525046400, 3],
  101. ],
  102. transactionStats: [
  103. [1525042800, 4],
  104. [1525046400, 4],
  105. ],
  106. platform: 'javascript',
  107. })}
  108. params={{orgId: 'org-slug'}}
  109. />
  110. );
  111. expect(screen.getByTestId('project-errors')).toBeInTheDocument();
  112. expect(screen.getByTestId('project-transactions')).toBeInTheDocument();
  113. expect(screen.getByText('Transactions: 8')).toBeInTheDocument();
  114. });
  115. it('renders loading placeholder card if there are no stats', function () {
  116. render(
  117. <ProjectCard
  118. organization={TestStubs.Organization()}
  119. project={TestStubs.Project()}
  120. params={{orgId: 'org-slug'}}
  121. />
  122. );
  123. const chartContainer = screen.getByTestId('chart-container');
  124. expect(within(chartContainer).getByTestId('loading-placeholder')).toBeInTheDocument();
  125. });
  126. });