InsightsConfig.test.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import InsightsConfig, { Props } from './InsightsConfig';
  4. const setup = (propOverrides?: object) => {
  5. const props: Props = {
  6. datasourceConfig: {
  7. id: 21,
  8. orgId: 1,
  9. name: 'Azure Monitor-10-10',
  10. type: 'grafana-azure-monitor-datasource',
  11. typeLogoUrl: '',
  12. access: 'proxy',
  13. url: '',
  14. password: '',
  15. user: '',
  16. database: '',
  17. basicAuth: false,
  18. basicAuthUser: '',
  19. basicAuthPassword: '',
  20. withCredentials: false,
  21. isDefault: false,
  22. jsonData: {},
  23. secureJsonFields: {
  24. appInsightsApiKey: false,
  25. },
  26. editorJsonData: {
  27. appInsightsAppId: 'cddcc020-2c94-460a-a3d0-df3147ffa792',
  28. },
  29. editorSecureJsonData: {
  30. appInsightsApiKey: 'e7f3f661-a933-4b3f-8176-51c4f982ec48',
  31. },
  32. version: 1,
  33. readOnly: false,
  34. },
  35. onDatasourceUpdate: jest.fn(),
  36. };
  37. Object.assign(props, propOverrides);
  38. return shallow(<InsightsConfig {...props} />);
  39. };
  40. describe('Render', () => {
  41. it('should render component', () => {
  42. const wrapper = setup();
  43. expect(wrapper).toMatchSnapshot();
  44. });
  45. it('should disable insights api key input', () => {
  46. const wrapper = setup({
  47. datasourceConfig: {
  48. secureJsonFields: {
  49. appInsightsApiKey: true,
  50. },
  51. editorJsonData: {
  52. appInsightsAppId: 'cddcc020-2c94-460a-a3d0-df3147ffa792',
  53. },
  54. editorSecureJsonData: {
  55. appInsightsApiKey: 'e7f3f661-a933-4b3f-8176-51c4f982ec48',
  56. },
  57. },
  58. });
  59. expect(wrapper).toMatchSnapshot();
  60. });
  61. it('should enable insights api key input', () => {
  62. const wrapper = setup({
  63. datasourceConfig: {
  64. secureJsonFields: {
  65. appInsightsApiKey: false,
  66. },
  67. editorJsonData: {
  68. appInsightsAppId: 'cddcc020-2c94-460a-a3d0-df3147ffa792',
  69. },
  70. editorSecureJsonData: {
  71. appInsightsApiKey: 'e7f3f661-a933-4b3f-8176-51c4f982ec48',
  72. },
  73. },
  74. });
  75. expect(wrapper).toMatchSnapshot();
  76. });
  77. });