projectCard.spec.tsx 4.1 KB

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