projectCard.spec.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. // @TODO(jonasbadalic): is testing for image and the platform icon both required?
  75. expect(screen.getAllByRole('img')).toHaveLength(3);
  76. expect(screen.getByTestId('platform-icon-javascript')).toBeInTheDocument();
  77. });
  78. it('renders header link for errors', function () {
  79. render(
  80. <ProjectCard
  81. organization={OrganizationFixture()}
  82. project={ProjectFixture({
  83. stats: [
  84. [1525042800, 3],
  85. [1525046400, 3],
  86. ],
  87. platform: 'javascript',
  88. })}
  89. hasProjectAccess={false}
  90. api={new MockApiClient()}
  91. />
  92. );
  93. expect(screen.getByTestId('project-errors')).toBeInTheDocument();
  94. expect(screen.getByText('Errors: 6')).toBeInTheDocument();
  95. // No transacions as the feature isn't set.
  96. expect(screen.queryByTestId('project-transactions')).not.toBeInTheDocument();
  97. });
  98. it('renders header link for transactions', function () {
  99. render(
  100. <ProjectCard
  101. organization={OrganizationFixture({features: ['performance-view']})}
  102. project={ProjectFixture({
  103. stats: [
  104. [1525042800, 3],
  105. [1525046400, 3],
  106. ],
  107. transactionStats: [
  108. [1525042800, 4],
  109. [1525046400, 4],
  110. ],
  111. platform: 'javascript',
  112. })}
  113. hasProjectAccess={false}
  114. api={new MockApiClient()}
  115. />
  116. );
  117. expect(screen.getByTestId('project-errors')).toBeInTheDocument();
  118. expect(screen.getByTestId('project-transactions')).toBeInTheDocument();
  119. expect(screen.getByText('Transactions: 8')).toBeInTheDocument();
  120. });
  121. it('renders loading placeholder card if there are no stats', function () {
  122. render(
  123. <ProjectCard
  124. organization={OrganizationFixture()}
  125. project={ProjectFixture()}
  126. hasProjectAccess={false}
  127. api={new MockApiClient()}
  128. />
  129. );
  130. const chartContainer = screen.getByTestId('chart-container');
  131. expect(within(chartContainer).getByTestId('loading-placeholder')).toBeInTheDocument();
  132. });
  133. });