thresholdsStep.spec.tsx 1.5 KB

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