details.spec.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {MonitorFixture} from 'sentry-fixture/monitor';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import MonitorDetails from 'sentry/views/monitors/details';
  5. describe('Monitor Details', () => {
  6. const monitor = MonitorFixture();
  7. const {organization, project, routerProps} = initializeOrg({
  8. router: {params: {monitorSlug: monitor.slug, projectId: monitor.project.slug}},
  9. });
  10. beforeEach(() => {
  11. MockApiClient.clearMockResponses();
  12. MockApiClient.addMockResponse({
  13. url: `/projects/${organization.slug}/${project.slug}/monitors/${monitor.slug}/`,
  14. body: {...monitor},
  15. });
  16. MockApiClient.addMockResponse({
  17. url: `/organizations/${organization.slug}/users/`,
  18. body: [],
  19. });
  20. MockApiClient.addMockResponse({
  21. url: `/organizations/${organization.slug}/issues/?limit=20&project=${project.id}&query=monitor.slug%3A${monitor.slug}%20environment%3A%5Bproduction%5D%20is%3Aunresolved&statsPeriod=14d`,
  22. body: [],
  23. });
  24. MockApiClient.addMockResponse({
  25. url: `/projects/${organization.slug}/${project.slug}/monitors/${monitor.slug}/stats/`,
  26. body: [],
  27. });
  28. MockApiClient.addMockResponse({
  29. url: `/projects/${organization.slug}/${project.slug}/monitors/${monitor.slug}/checkins/`,
  30. body: [],
  31. });
  32. });
  33. it('renders', async function () {
  34. render(<MonitorDetails {...routerProps} />);
  35. expect(await screen.findByText(monitor.slug, {exact: false})).toBeInTheDocument();
  36. });
  37. it('renders error when monitor is not found', async function () {
  38. MockApiClient.addMockResponse({
  39. url: `/projects/${organization.slug}/${project.slug}/monitors/${monitor.slug}/`,
  40. statusCode: 404,
  41. });
  42. render(<MonitorDetails {...routerProps} />);
  43. expect(
  44. await screen.findByText('The monitor you were looking for was not found.')
  45. ).toBeInTheDocument();
  46. });
  47. });