FolderSettingsPage.test.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { shallow } from 'enzyme';
  2. import React from 'react';
  3. import { mockToolkitActionCreator } from 'test/core/redux/mocks';
  4. import { NavModel } from '@grafana/data';
  5. import { getRouteComponentProps } from 'app/core/navigation/__mocks__/routeProps';
  6. import { FolderSettingsPage, Props } from './FolderSettingsPage';
  7. import { setFolderTitle } from './state/reducers';
  8. const setup = (propOverrides?: object) => {
  9. const props: Props = {
  10. ...getRouteComponentProps(),
  11. navModel: {} as NavModel,
  12. folderUid: '1234',
  13. folder: {
  14. id: 0,
  15. uid: '1234',
  16. title: 'loading',
  17. canSave: true,
  18. canDelete: true,
  19. url: 'url',
  20. hasChanged: false,
  21. version: 1,
  22. permissions: [],
  23. canViewFolderPermissions: true,
  24. },
  25. getFolderByUid: jest.fn(),
  26. setFolderTitle: mockToolkitActionCreator(setFolderTitle),
  27. saveFolder: jest.fn(),
  28. deleteFolder: jest.fn(),
  29. };
  30. Object.assign(props, propOverrides);
  31. const wrapper = shallow(<FolderSettingsPage {...props} />);
  32. const instance = wrapper.instance() as FolderSettingsPage;
  33. return {
  34. wrapper,
  35. instance,
  36. };
  37. };
  38. describe('Render', () => {
  39. it('should render component', () => {
  40. const { wrapper } = setup();
  41. expect(wrapper).toMatchSnapshot();
  42. });
  43. it('should enable save button', () => {
  44. const { wrapper } = setup({
  45. folder: {
  46. id: 1,
  47. uid: '1234',
  48. title: 'loading',
  49. canSave: true,
  50. canDelete: true,
  51. hasChanged: true,
  52. version: 1,
  53. },
  54. });
  55. expect(wrapper).toMatchSnapshot();
  56. });
  57. });