AzureCredentialsForm.test.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { shallow } from 'enzyme';
  2. import React from 'react';
  3. import AzureCredentialsForm, { Props } from './AzureCredentialsForm';
  4. const setup = (propsFunc?: (props: Props) => Props) => {
  5. let props: Props = {
  6. managedIdentityEnabled: false,
  7. credentials: {
  8. authType: 'clientsecret',
  9. azureCloud: 'azuremonitor',
  10. tenantId: 'e7f3f661-a933-3h3f-0294-31c4f962ec48',
  11. clientId: '34509fad-c0r9-45df-9e25-f1ee34af6900',
  12. clientSecret: undefined,
  13. defaultSubscriptionId: '44987801-6nn6-49he-9b2d-9106972f9789',
  14. },
  15. azureCloudOptions: [
  16. { value: 'azuremonitor', label: 'Azure' },
  17. { value: 'govazuremonitor', label: 'Azure US Government' },
  18. { value: 'germanyazuremonitor', label: 'Azure Germany' },
  19. { value: 'chinaazuremonitor', label: 'Azure China' },
  20. ],
  21. onCredentialsChange: jest.fn(),
  22. getSubscriptions: jest.fn(),
  23. };
  24. if (propsFunc) {
  25. props = propsFunc(props);
  26. }
  27. return shallow(<AzureCredentialsForm {...props} />);
  28. };
  29. describe('Render', () => {
  30. it('should render component', () => {
  31. const wrapper = setup();
  32. expect(wrapper).toMatchSnapshot();
  33. });
  34. it('should disable azure monitor secret input', () => {
  35. const wrapper = setup((props) => ({
  36. ...props,
  37. credentials: {
  38. authType: 'clientsecret',
  39. azureCloud: 'azuremonitor',
  40. tenantId: 'e7f3f661-a933-3h3f-0294-31c4f962ec48',
  41. clientId: '34509fad-c0r9-45df-9e25-f1ee34af6900',
  42. clientSecret: Symbol(),
  43. },
  44. }));
  45. expect(wrapper).toMatchSnapshot();
  46. });
  47. it('should enable azure monitor load subscriptions button', () => {
  48. const wrapper = setup((props) => ({
  49. ...props,
  50. credentials: {
  51. authType: 'clientsecret',
  52. azureCloud: 'azuremonitor',
  53. tenantId: 'e7f3f661-a933-3h3f-0294-31c4f962ec48',
  54. clientId: '34509fad-c0r9-45df-9e25-f1ee34af6900',
  55. clientSecret: 'e7f3f661-a933-4b3f-8176-51c4f982ec48',
  56. },
  57. }));
  58. expect(wrapper).toMatchSnapshot();
  59. });
  60. });