FolderSettings.test.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React from 'react';
  2. import { FolderSettings } from './FolderSettings';
  3. import { RootStore } from 'app/stores/RootStore/RootStore';
  4. import { backendSrv } from 'test/mocks/common';
  5. import { shallow } from 'enzyme';
  6. describe('FolderSettings', () => {
  7. let wrapper;
  8. let page;
  9. beforeAll(() => {
  10. backendSrv.getFolderByUid.mockReturnValue(
  11. Promise.resolve({
  12. id: 1,
  13. uid: 'uid',
  14. title: 'Folder Name',
  15. url: '/dashboards/f/uid/folder-name',
  16. canSave: true,
  17. version: 1,
  18. })
  19. );
  20. const store = RootStore.create(
  21. {
  22. view: {
  23. path: 'asd',
  24. query: {},
  25. routeParams: {
  26. uid: 'uid-str',
  27. },
  28. },
  29. },
  30. {
  31. backendSrv: backendSrv,
  32. }
  33. );
  34. wrapper = shallow(<FolderSettings backendSrv={backendSrv} {...store} />);
  35. page = wrapper.dive();
  36. return page
  37. .instance()
  38. .loadStore()
  39. .then(() => {
  40. page.update();
  41. });
  42. });
  43. it('should set the title input field', () => {
  44. const titleInput = page.find('.gf-form-input');
  45. expect(titleInput).toHaveLength(1);
  46. expect(titleInput.prop('value')).toBe('Folder Name');
  47. });
  48. it('should update title and enable save button when changed', () => {
  49. const titleInput = page.find('.gf-form-input');
  50. const disabledSubmitButton = page.find('button[type="submit"]');
  51. expect(disabledSubmitButton.prop('disabled')).toBe(true);
  52. titleInput.simulate('change', { target: { value: 'New Title' } });
  53. const updatedTitleInput = page.find('.gf-form-input');
  54. expect(updatedTitleInput.prop('value')).toBe('New Title');
  55. const enabledSubmitButton = page.find('button[type="submit"]');
  56. expect(enabledSubmitButton.prop('disabled')).toBe(false);
  57. });
  58. it('should disable save button if title is changed back to old title', () => {
  59. const titleInput = page.find('.gf-form-input');
  60. titleInput.simulate('change', { target: { value: 'Folder Name' } });
  61. const enabledSubmitButton = page.find('button[type="submit"]');
  62. expect(enabledSubmitButton.prop('disabled')).toBe(true);
  63. });
  64. it('should disable save button if title is changed to empty string', () => {
  65. const titleInput = page.find('.gf-form-input');
  66. titleInput.simulate('change', { target: { value: '' } });
  67. const enabledSubmitButton = page.find('button[type="submit"]');
  68. expect(enabledSubmitButton.prop('disabled')).toBe(true);
  69. });
  70. });