projectCard.spec.tsx 4.1 KB

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