details.spec.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import {UptimeRuleFixture} from 'sentry-fixture/uptimeRule';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import UptimeAlertDetails from './details';
  5. describe('UptimeAlertDetails', function () {
  6. const {organization, project, routerProps} = initializeOrg();
  7. beforeEach(function () {
  8. MockApiClient.addMockResponse({
  9. url: `/organizations/${organization.slug}/projects/`,
  10. body: [project],
  11. });
  12. MockApiClient.addMockResponse({
  13. url: `/organizations/${organization.slug}/users/`,
  14. body: [],
  15. });
  16. MockApiClient.addMockResponse({
  17. url: `/organizations/${organization.slug}/issues/?limit=20&project=${project.id}&query=issue.category%3Auptime%20tags%5Buptime_rule%5D%3A1&statsPeriod=14d`,
  18. body: [],
  19. });
  20. });
  21. it('renders', async function () {
  22. MockApiClient.addMockResponse({
  23. url: `/projects/${organization.slug}/${project.slug}/uptime/1/`,
  24. body: UptimeRuleFixture({name: 'Uptime Test Rule'}),
  25. });
  26. render(
  27. <UptimeAlertDetails
  28. {...routerProps}
  29. params={{...routerProps.params, uptimeRuleId: '1'}}
  30. />,
  31. {organization}
  32. );
  33. expect(await screen.findAllByText('Uptime Test Rule')).toHaveLength(2);
  34. });
  35. it('shows a message for invalid uptime alert', async function () {
  36. MockApiClient.addMockResponse({
  37. url: `/projects/${organization.slug}/${project.slug}/uptime/2/`,
  38. statusCode: 404,
  39. });
  40. render(
  41. <UptimeAlertDetails
  42. {...routerProps}
  43. params={{...routerProps.params, uptimeRuleId: '2'}}
  44. />,
  45. {organization}
  46. );
  47. expect(
  48. await screen.findByText('The uptime alert rule you were looking for was not found.')
  49. ).toBeInTheDocument();
  50. });
  51. });