ClusterWidget.spec.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 'components/Dashboard/ClustersWidget/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-success')).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. describe('when cluster is read-only', () => {
  65. it('renders the tag', () => {
  66. expect(
  67. shallow(
  68. <ClusterWidget cluster={{ ...onlineCluster, readOnly: true }} />
  69. )
  70. .find('.title')
  71. .childAt(1)
  72. .text()
  73. ).toEqual('readonly');
  74. });
  75. });
  76. });