projectCard.spec.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. const {container} = createWrapper();
  30. expect(container).toSnapshot();
  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={TestStubs.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={TestStubs.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={TestStubs.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={TestStubs.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. });