ConfigEditor.test.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { shallow } from 'enzyme';
  2. import React from 'react';
  3. import ConfigEditor, { Props } from './ConfigEditor';
  4. jest.mock('lodash', () => {
  5. const uniqueId = (prefix: string) => `${prefix}42`;
  6. const orig = jest.requireActual('lodash');
  7. return {
  8. ...orig,
  9. uniqueId,
  10. };
  11. });
  12. const setup = (propOverrides?: object) => {
  13. const props: Props = {
  14. options: {
  15. id: 21,
  16. uid: 'z',
  17. orgId: 1,
  18. name: 'InfluxDB-3',
  19. type: 'influxdb',
  20. typeName: 'Influx',
  21. typeLogoUrl: '',
  22. access: 'proxy',
  23. url: '',
  24. user: '',
  25. database: '',
  26. basicAuth: false,
  27. basicAuthUser: '',
  28. withCredentials: false,
  29. isDefault: false,
  30. jsonData: {
  31. httpMode: 'POST',
  32. timeInterval: '4',
  33. },
  34. secureJsonFields: {},
  35. version: 1,
  36. readOnly: false,
  37. },
  38. onOptionsChange: jest.fn(),
  39. };
  40. Object.assign(props, propOverrides);
  41. return shallow(<ConfigEditor {...props} />);
  42. };
  43. describe('Render', () => {
  44. it('should render component', () => {
  45. const wrapper = setup();
  46. expect(wrapper).toMatchSnapshot();
  47. });
  48. it('should disable basic auth password input', () => {
  49. const wrapper = setup({
  50. secureJsonFields: {
  51. basicAuthPassword: true,
  52. },
  53. });
  54. expect(wrapper).toMatchSnapshot();
  55. });
  56. it('should hide white listed cookies input when browser access chosen', () => {
  57. const wrapper = setup({
  58. access: 'direct',
  59. });
  60. expect(wrapper).toMatchSnapshot();
  61. });
  62. it('should hide basic auth fields when switch off', () => {
  63. const wrapper = setup({
  64. basicAuth: false,
  65. });
  66. expect(wrapper).toMatchSnapshot();
  67. });
  68. });