Cluster.spec.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import React from 'react';
  2. import { Cluster, ClusterFeaturesEnum } from 'generated-sources';
  3. import ClusterComponent from 'components/Cluster/Cluster';
  4. import { screen, waitFor } from '@testing-library/react';
  5. import { render, WithRoute } from 'lib/testHelpers';
  6. import {
  7. clusterBrokersPath,
  8. clusterConnectorsPath,
  9. clusterConnectsPath,
  10. clusterConsumerGroupsPath,
  11. clusterKsqlDbPath,
  12. clusterPath,
  13. clusterSchemasPath,
  14. clusterTopicsPath,
  15. } from 'lib/paths';
  16. import { useClusters } from 'lib/hooks/api/clusters';
  17. import { onlineClusterPayload } from 'lib/fixtures/clusters';
  18. const CLusterCompText = {
  19. Topics: 'Topics',
  20. Schemas: 'Schemas',
  21. Connect: 'Connect',
  22. Brokers: 'Brokers',
  23. ConsumerGroups: 'ConsumerGroups',
  24. KsqlDb: 'KsqlDb',
  25. };
  26. jest.mock('components/Topics/Topics', () => () => (
  27. <div>{CLusterCompText.Topics}</div>
  28. ));
  29. jest.mock('components/Schemas/Schemas', () => () => (
  30. <div>{CLusterCompText.Schemas}</div>
  31. ));
  32. jest.mock('components/Connect/Connect', () => () => (
  33. <div>{CLusterCompText.Connect}</div>
  34. ));
  35. jest.mock('components/Brokers/Brokers', () => () => (
  36. <div>{CLusterCompText.Brokers}</div>
  37. ));
  38. jest.mock('components/ConsumerGroups/ConsumerGroups', () => () => (
  39. <div>{CLusterCompText.ConsumerGroups}</div>
  40. ));
  41. jest.mock('components/KsqlDb/KsqlDb', () => () => (
  42. <div>{CLusterCompText.KsqlDb}</div>
  43. ));
  44. jest.mock('lib/hooks/api/clusters', () => ({
  45. useClusters: jest.fn(),
  46. }));
  47. describe('Cluster', () => {
  48. const renderComponent = async (pathname: string, payload: Cluster[] = []) => {
  49. (useClusters as jest.Mock).mockImplementation(() => ({
  50. data: payload,
  51. }));
  52. await render(
  53. <WithRoute path={`${clusterPath()}/*`}>
  54. <ClusterComponent />
  55. </WithRoute>,
  56. { initialEntries: [pathname] }
  57. );
  58. await waitFor(() => {
  59. expect(screen.queryByRole('progressbar')).not.toBeInTheDocument();
  60. });
  61. };
  62. it('renders Brokers', async () => {
  63. await renderComponent(clusterBrokersPath('second'));
  64. expect(screen.getByText(CLusterCompText.Brokers)).toBeInTheDocument();
  65. });
  66. it('renders Topics', async () => {
  67. await renderComponent(clusterTopicsPath('second'));
  68. expect(screen.getByText(CLusterCompText.Topics)).toBeInTheDocument();
  69. });
  70. it('renders ConsumerGroups', async () => {
  71. await renderComponent(clusterConsumerGroupsPath('second'));
  72. expect(
  73. screen.getByText(CLusterCompText.ConsumerGroups)
  74. ).toBeInTheDocument();
  75. });
  76. describe('configured features', () => {
  77. const itCorrectlyHandlesConfiguredSchema = (
  78. feature: ClusterFeaturesEnum,
  79. text: string,
  80. path: string
  81. ) => {
  82. it(`renders Schemas if ${feature} is configured`, async () => {
  83. await renderComponent(path, [
  84. {
  85. ...onlineClusterPayload,
  86. features: [feature],
  87. },
  88. ]);
  89. expect(screen.getByText(text)).toBeInTheDocument();
  90. });
  91. it(`does not render Schemas if ${feature} is not configured`, async () => {
  92. await renderComponent(path, [
  93. { ...onlineClusterPayload, features: [] },
  94. ]);
  95. expect(screen.queryByText(text)).not.toBeInTheDocument();
  96. });
  97. };
  98. itCorrectlyHandlesConfiguredSchema(
  99. ClusterFeaturesEnum.SCHEMA_REGISTRY,
  100. CLusterCompText.Schemas,
  101. clusterSchemasPath(onlineClusterPayload.name)
  102. );
  103. itCorrectlyHandlesConfiguredSchema(
  104. ClusterFeaturesEnum.KAFKA_CONNECT,
  105. CLusterCompText.Connect,
  106. clusterConnectsPath(onlineClusterPayload.name)
  107. );
  108. itCorrectlyHandlesConfiguredSchema(
  109. ClusterFeaturesEnum.KAFKA_CONNECT,
  110. CLusterCompText.Connect,
  111. clusterConnectorsPath(onlineClusterPayload.name)
  112. );
  113. itCorrectlyHandlesConfiguredSchema(
  114. ClusterFeaturesEnum.KSQL_DB,
  115. CLusterCompText.KsqlDb,
  116. clusterKsqlDbPath(onlineClusterPayload.name)
  117. );
  118. });
  119. });