projectCard.spec.jsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import {mount} from 'enzyme';
  2. import React from 'react';
  3. import {ProjectCard} from 'app/views/projectsDashboard/projectCard';
  4. // NOTE: Unmocking debounce so that the actionCreator never fires
  5. jest.unmock('lodash/debounce');
  6. describe('ProjectCard', function() {
  7. let wrapper;
  8. beforeEach(function() {
  9. wrapper = mount(
  10. <ProjectCard
  11. organization={TestStubs.Organization()}
  12. project={TestStubs.Project({
  13. stats: [[1525042800, 1], [1525046400, 2]],
  14. platform: 'javascript',
  15. })}
  16. params={{orgId: 'org-slug'}}
  17. />,
  18. TestStubs.routerContext()
  19. );
  20. });
  21. afterEach(function() {
  22. MockApiClient.clearMockResponses();
  23. });
  24. it('renders', function() {
  25. expect(wrapper).toMatchSnapshot();
  26. });
  27. it('renders latest 2 deploys', function() {
  28. const latestDeploys = [
  29. {
  30. environment: 'beta',
  31. dateFinished: '2018-05-10T20:56:40.092Z',
  32. version: '123456',
  33. },
  34. {
  35. environment: 'staging',
  36. dateFinished: '2018-05-08T20:56:40.092Z',
  37. version: '789789',
  38. },
  39. {
  40. environment: 'production',
  41. dateFinished: '2018-05-09T20:56:40.092Z',
  42. version: '123123',
  43. },
  44. ];
  45. wrapper = mount(
  46. <ProjectCard
  47. organization={TestStubs.Organization()}
  48. project={TestStubs.Project({
  49. stats: [[1525042800, 1], [1525046400, 2]],
  50. platform: 'javascript',
  51. latestDeploys,
  52. })}
  53. params={{orgId: 'org-slug'}}
  54. />,
  55. TestStubs.routerContext()
  56. );
  57. expect(wrapper.find('Deploy')).toHaveLength(2);
  58. expect(wrapper.find('NoDeploys')).toHaveLength(0);
  59. expect(wrapper.find('Environment[children="beta"]')).toHaveLength(1);
  60. expect(wrapper.find('Environment[children="production"]')).toHaveLength(1);
  61. expect(wrapper.find('Environment[children="staging"]')).toHaveLength(0);
  62. });
  63. it('renders empty state if no deploys', function() {
  64. expect(wrapper.find('NoDeploys')).toHaveLength(1);
  65. });
  66. it('renders with platform', function() {
  67. expect(wrapper.find('PlatformList')).toHaveLength(1);
  68. const icons = wrapper.find('StyledPlatformIcon');
  69. expect(icons.first().prop('platform')).toBe('javascript');
  70. });
  71. it('renders loading placeholder card if there are no stats', function() {
  72. wrapper = mount(
  73. <ProjectCard
  74. organization={TestStubs.Organization()}
  75. project={TestStubs.Project()}
  76. params={{orgId: 'org-slug'}}
  77. />,
  78. TestStubs.routerContext()
  79. );
  80. expect(wrapper.find('LoadingCard')).toHaveLength(1);
  81. });
  82. });