thresholdsStep.spec.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import type {ThresholdsConfig} from './thresholdsStep';
  3. import ThresholdsStep from './thresholdsStep';
  4. const exampleThresholdsConfig: ThresholdsConfig = {
  5. max_values: {
  6. max1: 100,
  7. max2: 200,
  8. },
  9. unit: null,
  10. };
  11. describe('Widget Builder > ThresholdsStep', function () {
  12. it('renders thresholds step', function () {
  13. const onChange = jest.fn();
  14. render(
  15. <ThresholdsStep
  16. thresholdsConfig={exampleThresholdsConfig}
  17. onThresholdChange={onChange}
  18. onUnitChange={onChange}
  19. errors={{max1: 'error'}}
  20. />
  21. );
  22. expect(screen.getByText('Set thresholds')).toBeInTheDocument();
  23. // Check minimum value boxes are disabled
  24. expect(screen.getByLabelText('First Minimum')).toBeDisabled();
  25. expect(screen.getByLabelText('Second Minimum')).toBeDisabled();
  26. expect(screen.getByLabelText('Third Minimum')).toBeDisabled();
  27. // Check minimum values
  28. expect(screen.getByLabelText('First Minimum', {selector: 'input'})).toHaveValue(0);
  29. expect(screen.getByLabelText('Second Minimum', {selector: 'input'})).toHaveValue(100);
  30. expect(screen.getByLabelText('Third Minimum', {selector: 'input'})).toHaveValue(200);
  31. // Check max values
  32. expect(screen.getByLabelText('First Maximum', {selector: 'input'})).toHaveValue(100);
  33. expect(screen.getByLabelText('Second Maximum', {selector: 'input'})).toHaveValue(200);
  34. expect(screen.getByLabelText('Third Maximum', {selector: 'input'})).toHaveAttribute(
  35. 'placeholder',
  36. 'No max'
  37. );
  38. });
  39. });