payAsYouGoBudgetEdit.spec.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {OnDemandBudgetMode} from 'getsentry/types';
  3. import PayAsYouGoBudgetEdit from 'getsentry/views/onDemandBudgets/payAsYouGoBudgetEdit';
  4. describe('PayAsYouGoBudgetEdit', function () {
  5. it('renders', function () {
  6. render(
  7. <PayAsYouGoBudgetEdit
  8. payAsYouGoBudget={{
  9. budgetMode: OnDemandBudgetMode.SHARED,
  10. sharedMaxBudget: 500_00,
  11. }}
  12. setPayAsYouGoBudget={jest.fn()}
  13. />
  14. );
  15. expect(screen.getByText('Pay-as-you-go Budget')).toBeInTheDocument();
  16. expect(screen.getByRole('textbox', {name: 'Pay-as-you-go budget'})).toHaveValue(
  17. '500'
  18. );
  19. });
  20. it('renders alert when PAYG is 0', function () {
  21. render(
  22. <PayAsYouGoBudgetEdit
  23. payAsYouGoBudget={{budgetMode: OnDemandBudgetMode.SHARED, sharedMaxBudget: 0}}
  24. setPayAsYouGoBudget={jest.fn()}
  25. />
  26. );
  27. expect(screen.getByText('Pay-as-you-go Budget')).toBeInTheDocument();
  28. expect(screen.getByRole('textbox', {name: 'Pay-as-you-go budget'})).toHaveValue('0');
  29. expect(
  30. screen.getByText(
  31. 'Setting this to $0 may result in you losing the ability to fully monitor your applications within Sentry.'
  32. )
  33. ).toBeInTheDocument();
  34. });
  35. it('handles input edge cases', async function () {
  36. render(
  37. <PayAsYouGoBudgetEdit
  38. payAsYouGoBudget={{budgetMode: OnDemandBudgetMode.SHARED, sharedMaxBudget: 0}}
  39. setPayAsYouGoBudget={jest.fn()}
  40. />
  41. );
  42. expect(screen.getByText('Pay-as-you-go Budget')).toBeInTheDocument();
  43. const input = screen.getByRole('textbox', {name: 'Pay-as-you-go budget'});
  44. await userEvent.type(input, 'a');
  45. expect(input).toHaveValue('0');
  46. await userEvent.type(input, '-50');
  47. expect(input).toHaveValue('0');
  48. await userEvent.type(input, '-');
  49. expect(input).toHaveValue('0');
  50. await userEvent.clear(input);
  51. await userEvent.type(input, '10e');
  52. expect(input).toHaveValue('0');
  53. await userEvent.clear(input);
  54. await userEvent.type(input, 'e');
  55. expect(input).toHaveValue('0');
  56. await userEvent.clear(input);
  57. await userEvent.type(input, '75..');
  58. expect(input).toHaveValue('0');
  59. await userEvent.clear(input);
  60. await userEvent.type(input, '.');
  61. expect(input).toHaveValue('0');
  62. });
  63. });