existingOrCreate.spec.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import {UptimeRuleFixture} from 'sentry-fixture/uptimeRule';
  2. import {render, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import ExistingOrCreate from './existingOrCreate';
  4. describe('ExistingOrCreate', () => {
  5. it('redirects to create a new alert when none exist', async function () {
  6. MockApiClient.addMockResponse({
  7. url: '/organizations/org-slug/combined-rules/',
  8. body: [],
  9. });
  10. const {router} = render(<ExistingOrCreate />, {disableRouterMocks: true});
  11. await waitFor(() =>
  12. expect(router.location.pathname).toBe('/organizations/org-slug/alerts/new/uptime/')
  13. );
  14. });
  15. it('redirects to specific alert when one exists', async function () {
  16. MockApiClient.addMockResponse({
  17. url: '/organizations/org-slug/combined-rules/',
  18. body: [UptimeRuleFixture()],
  19. });
  20. const {router} = render(<ExistingOrCreate />, {disableRouterMocks: true});
  21. await waitFor(() =>
  22. expect(router.location.pathname).toBe(
  23. '/organizations/org-slug/alerts/uptime-rules/project-slug/1/'
  24. )
  25. );
  26. });
  27. it('redirects to the list when multiple eixst', async function () {
  28. MockApiClient.addMockResponse({
  29. url: '/organizations/org-slug/combined-rules/',
  30. body: [UptimeRuleFixture({id: '1'}), UptimeRuleFixture({id: '2'})],
  31. });
  32. const {router} = render(<ExistingOrCreate />, {disableRouterMocks: true});
  33. await waitFor(() =>
  34. expect(router.location.pathname).toBe('/organizations/org-slug/alerts/rules/')
  35. );
  36. expect(router.location.query).toEqual({alertType: 'uptime'});
  37. });
  38. });