projectCard.spec.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. hasProjectAccess={false}
  22. api={new MockApiClient()}
  23. />
  24. );
  25. afterEach(function () {
  26. MockApiClient.clearMockResponses();
  27. });
  28. it('renders', function () {
  29. createWrapper();
  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. hasProjectAccess={false}
  58. api={new MockApiClient()}
  59. />
  60. );
  61. expect(screen.queryByRole('button', {name: 'Track Deploys'})).not.toBeInTheDocument();
  62. expect(screen.getByText('beta')).toBeInTheDocument();
  63. expect(screen.getByText('production')).toBeInTheDocument();
  64. expect(screen.queryByText('staging')).not.toBeInTheDocument();
  65. });
  66. it('renders empty state if no deploys', function () {
  67. createWrapper();
  68. expect(screen.getByRole('button', {name: 'Track Deploys'})).toBeInTheDocument();
  69. });
  70. it('renders with platform', function () {
  71. createWrapper();
  72. expect(screen.getByRole('img')).toBeInTheDocument();
  73. expect(screen.getByTestId('platform-icon-javascript')).toBeInTheDocument();
  74. });
  75. it('renders header link for errors', function () {
  76. render(
  77. <ProjectCard
  78. organization={TestStubs.Organization()}
  79. project={TestStubs.Project({
  80. stats: [
  81. [1525042800, 3],
  82. [1525046400, 3],
  83. ],
  84. platform: 'javascript',
  85. })}
  86. hasProjectAccess={false}
  87. api={new MockApiClient()}
  88. />
  89. );
  90. expect(screen.getByTestId('project-errors')).toBeInTheDocument();
  91. expect(screen.getByText('Errors: 6')).toBeInTheDocument();
  92. // No transacions as the feature isn't set.
  93. expect(screen.queryByTestId('project-transactions')).not.toBeInTheDocument();
  94. });
  95. it('renders header link for transactions', function () {
  96. render(
  97. <ProjectCard
  98. organization={TestStubs.Organization({features: ['performance-view']})}
  99. project={TestStubs.Project({
  100. stats: [
  101. [1525042800, 3],
  102. [1525046400, 3],
  103. ],
  104. transactionStats: [
  105. [1525042800, 4],
  106. [1525046400, 4],
  107. ],
  108. platform: 'javascript',
  109. })}
  110. hasProjectAccess={false}
  111. api={new MockApiClient()}
  112. />
  113. );
  114. expect(screen.getByTestId('project-errors')).toBeInTheDocument();
  115. expect(screen.getByTestId('project-transactions')).toBeInTheDocument();
  116. expect(screen.getByText('Transactions: 8')).toBeInTheDocument();
  117. });
  118. it('renders loading placeholder card if there are no stats', function () {
  119. render(
  120. <ProjectCard
  121. organization={TestStubs.Organization()}
  122. project={TestStubs.Project()}
  123. hasProjectAccess={false}
  124. api={new MockApiClient()}
  125. />
  126. );
  127. const chartContainer = screen.getByTestId('chart-container');
  128. expect(within(chartContainer).getByTestId('loading-placeholder')).toBeInTheDocument();
  129. });
  130. });