Schemas.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import React from 'react';
  2. import { Provider } from 'react-redux';
  3. import { mount } from 'enzyme';
  4. import configureStore from 'redux/store/configureStore';
  5. import { StaticRouter } from 'react-router-dom';
  6. import Schemas, { SchemasProps } from '../Schemas';
  7. import SchemasContainer from '../SchemasContainer';
  8. describe('Schemas', () => {
  9. const pathname = `/ui/clusters/clusterName/schemas`;
  10. describe('Container', () => {
  11. const store = configureStore();
  12. it('renders view', () => {
  13. const component = mount(
  14. <Provider store={store}>
  15. <StaticRouter location={{ pathname }} context={{}}>
  16. <SchemasContainer />
  17. </StaticRouter>
  18. </Provider>
  19. );
  20. expect(component.exists()).toBeTruthy();
  21. });
  22. describe('View', () => {
  23. const setupWrapper = (props: Partial<SchemasProps> = {}) => (
  24. <StaticRouter location={{ pathname }} context={{}}>
  25. <Schemas
  26. isFetching
  27. fetchSchemasByClusterName={jest.fn()}
  28. isReadOnly={false}
  29. {...props}
  30. />
  31. </StaticRouter>
  32. );
  33. describe('Initial state', () => {
  34. let useEffect: jest.SpyInstance<
  35. void,
  36. [
  37. effect: React.EffectCallback,
  38. deps?: React.DependencyList | undefined
  39. ]
  40. >;
  41. const mockedFn = jest.fn();
  42. const mockedUseEffect = () => {
  43. useEffect.mockImplementationOnce(mockedFn);
  44. };
  45. beforeEach(() => {
  46. useEffect = jest.spyOn(React, 'useEffect');
  47. mockedUseEffect();
  48. });
  49. it('should call fetchSchemasByClusterName every render', () => {
  50. mount(setupWrapper({ fetchSchemasByClusterName: mockedFn }));
  51. expect(mockedFn).toHaveBeenCalled();
  52. });
  53. });
  54. describe('when page is loading', () => {
  55. const wrapper = mount(setupWrapper({ isFetching: true }));
  56. it('renders PageLoader', () => {
  57. expect(wrapper.exists('PageLoader')).toBeTruthy();
  58. });
  59. });
  60. });
  61. });
  62. });