ClusterWidget.spec.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import { ServerStatus } from 'generated-sources';
  4. import { clusterBrokersPath, clusterTopicsPath } from 'lib/paths';
  5. import ClusterWidget from '../ClusterWidget';
  6. import { offlineCluster, onlineCluster } from './fixtures';
  7. describe('ClusterWidget', () => {
  8. describe('when cluster is online', () => {
  9. it('renders with correct tag', () => {
  10. const tag = shallow(<ClusterWidget cluster={onlineCluster} />).find(
  11. '.tag'
  12. );
  13. expect(tag.hasClass('is-primary')).toBeTruthy();
  14. expect(tag.text()).toEqual(ServerStatus.Online);
  15. });
  16. it('renders table', () => {
  17. const table = shallow(<ClusterWidget cluster={onlineCluster} />).find(
  18. 'table'
  19. );
  20. expect(table.hasClass('is-fullwidth')).toBeTruthy();
  21. expect(
  22. table.find(`NavLink[to="${clusterBrokersPath(onlineCluster.name)}"]`)
  23. .exists
  24. ).toBeTruthy();
  25. expect(
  26. table.find(`NavLink[to="${clusterTopicsPath(onlineCluster.name)}"]`)
  27. .exists
  28. ).toBeTruthy();
  29. });
  30. it('matches snapshot', () => {
  31. expect(
  32. shallow(<ClusterWidget cluster={onlineCluster} />)
  33. ).toMatchSnapshot();
  34. });
  35. });
  36. describe('when cluster is offline', () => {
  37. it('renders with correct tag', () => {
  38. const tag = shallow(<ClusterWidget cluster={offlineCluster} />).find(
  39. '.tag'
  40. );
  41. expect(tag.hasClass('is-danger')).toBeTruthy();
  42. expect(tag.text()).toEqual(ServerStatus.Offline);
  43. });
  44. it('renders table', () => {
  45. const table = shallow(<ClusterWidget cluster={offlineCluster} />).find(
  46. 'table'
  47. );
  48. expect(table.hasClass('is-fullwidth')).toBeTruthy();
  49. expect(
  50. table.find(`NavLink[to="${clusterBrokersPath(onlineCluster.name)}"]`)
  51. .exists
  52. ).toBeTruthy();
  53. expect(
  54. table.find(`NavLink[to="${clusterTopicsPath(onlineCluster.name)}"]`)
  55. .exists
  56. ).toBeTruthy();
  57. });
  58. it('matches snapshot', () => {
  59. expect(
  60. shallow(<ClusterWidget cluster={offlineCluster} />)
  61. ).toMatchSnapshot();
  62. });
  63. });
  64. });