Brokers.spec.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import React from 'react';
  2. import { mount } from 'enzyme';
  3. import Brokers from 'components/Brokers/Brokers';
  4. import { ClusterName } from 'redux/interfaces';
  5. import { StaticRouter } from 'react-router';
  6. import { ClusterStats } from 'generated-sources';
  7. interface Props extends ClusterStats {
  8. isFetched: boolean;
  9. fetchClusterStats: (clusterName: ClusterName) => void;
  10. fetchBrokers: (clusterName: ClusterName) => void;
  11. }
  12. describe('Brokers Component', () => {
  13. const pathname = `ui/clusters/local/brokers`;
  14. describe('Brokers Empty', () => {
  15. const setupEmptyComponent = (props: Partial<Props> = {}) => (
  16. <StaticRouter location={{ pathname }} context={{}}>
  17. <Brokers
  18. brokerCount={0}
  19. activeControllers={0}
  20. zooKeeperStatus={0}
  21. onlinePartitionCount={0}
  22. offlinePartitionCount={0}
  23. inSyncReplicasCount={0}
  24. outOfSyncReplicasCount={0}
  25. underReplicatedPartitionCount={0}
  26. version="1"
  27. fetchClusterStats={jest.fn()}
  28. fetchBrokers={jest.fn()}
  29. diskUsage={undefined}
  30. isFetched={false}
  31. {...props}
  32. />
  33. </StaticRouter>
  34. );
  35. it('renders section', () => {
  36. const component = mount(setupEmptyComponent());
  37. expect(component.exists('.section')).toBeTruthy();
  38. });
  39. it('renders section with is-danger selector', () => {
  40. const component = mount(setupEmptyComponent());
  41. expect(component.exists('.is-danger')).toBeTruthy();
  42. });
  43. it('matches Brokers Empty snapshot', () => {
  44. expect(mount(setupEmptyComponent())).toMatchSnapshot();
  45. });
  46. });
  47. describe('Brokers', () => {
  48. const setupComponent = (props: Partial<Props> = {}) => (
  49. <StaticRouter location={{ pathname }} context={{}}>
  50. <Brokers
  51. brokerCount={1}
  52. activeControllers={1}
  53. zooKeeperStatus={1}
  54. onlinePartitionCount={64}
  55. offlinePartitionCount={0}
  56. inSyncReplicasCount={64}
  57. outOfSyncReplicasCount={0}
  58. underReplicatedPartitionCount={0}
  59. version="1"
  60. fetchClusterStats={jest.fn()}
  61. fetchBrokers={jest.fn()}
  62. diskUsage={[
  63. {
  64. brokerId: 1,
  65. segmentCount: 64,
  66. segmentSize: 60718,
  67. },
  68. ]}
  69. isFetched
  70. {...props}
  71. />
  72. </StaticRouter>
  73. );
  74. it('renders section with is-success selector', () => {
  75. const component = mount(setupComponent());
  76. expect(component.exists('.is-success')).toBeTruthy();
  77. });
  78. it('matches snapshot', () => {
  79. expect(mount(setupComponent())).toMatchSnapshot();
  80. });
  81. });
  82. });