ConfigEditor.test.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { shallow } from 'enzyme';
  2. import React from 'react';
  3. import { AwsAuthType } from '@grafana/aws-sdk';
  4. import { ConfigEditor, Props } from './ConfigEditor';
  5. jest.mock('app/features/plugins/datasource_srv', () => ({
  6. getDatasourceSrv: () => ({
  7. loadDatasource: jest.fn().mockImplementation(() =>
  8. Promise.resolve({
  9. getRegions: jest.fn().mockReturnValue([
  10. {
  11. label: 'ap-east-1',
  12. value: 'ap-east-1',
  13. },
  14. ]),
  15. })
  16. ),
  17. }),
  18. }));
  19. const setup = (propOverrides?: object) => {
  20. const props: Props = {
  21. options: {
  22. id: 1,
  23. uid: 'z',
  24. orgId: 1,
  25. typeLogoUrl: '',
  26. name: 'CloudWatch',
  27. access: 'proxy',
  28. url: '',
  29. database: '',
  30. type: 'cloudwatch',
  31. typeName: 'Cloudwatch',
  32. user: '',
  33. basicAuth: false,
  34. basicAuthUser: '',
  35. isDefault: true,
  36. readOnly: false,
  37. withCredentials: false,
  38. secureJsonFields: {
  39. accessKey: false,
  40. secretKey: false,
  41. },
  42. jsonData: {
  43. assumeRoleArn: '',
  44. externalId: '',
  45. database: '',
  46. customMetricsNamespaces: '',
  47. authType: AwsAuthType.Keys,
  48. defaultRegion: 'us-east-2',
  49. timeField: '@timestamp',
  50. },
  51. secureJsonData: {
  52. secretKey: '',
  53. accessKey: '',
  54. },
  55. },
  56. onOptionsChange: jest.fn(),
  57. };
  58. Object.assign(props, propOverrides);
  59. return shallow(<ConfigEditor {...props} />);
  60. };
  61. describe('Render', () => {
  62. it('should render component', () => {
  63. const wrapper = setup();
  64. expect(wrapper).toMatchSnapshot();
  65. });
  66. it('should disable access key id field', () => {
  67. const wrapper = setup({
  68. secureJsonFields: {
  69. secretKey: true,
  70. },
  71. });
  72. expect(wrapper).toMatchSnapshot();
  73. });
  74. it('should show credentials profile name field', () => {
  75. const wrapper = setup({
  76. jsonData: {
  77. authType: 'credentials',
  78. },
  79. });
  80. expect(wrapper).toMatchSnapshot();
  81. });
  82. it('should show access key and secret access key fields', () => {
  83. const wrapper = setup({
  84. jsonData: {
  85. authType: 'keys',
  86. },
  87. });
  88. expect(wrapper).toMatchSnapshot();
  89. });
  90. it('should show arn role field', () => {
  91. const wrapper = setup({
  92. jsonData: {
  93. authType: 'arn',
  94. },
  95. });
  96. expect(wrapper).toMatchSnapshot();
  97. });
  98. });