overview.spec.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {TeamFixture} from 'sentry-fixture/team';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import OrganizationStore from 'sentry/stores/organizationStore';
  5. import {useNavigate} from 'sentry/utils/useNavigate';
  6. import Monitors from 'sentry/views/monitors/overview';
  7. jest.mock('sentry/utils/useNavigate', () => ({
  8. useNavigate: jest.fn(),
  9. }));
  10. const mockUseNavigate = jest.mocked(useNavigate);
  11. const mockNavigate = jest.fn();
  12. mockUseNavigate.mockReturnValue(mockNavigate);
  13. describe('Monitors Overview', function () {
  14. const team = TeamFixture();
  15. beforeEach(function () {
  16. OrganizationStore.init();
  17. MockApiClient.clearMockResponses();
  18. MockApiClient.addMockResponse({
  19. url: '/organizations/org-slug/monitors/',
  20. body: [],
  21. });
  22. MockApiClient.addMockResponse({
  23. url: '/organizations/org-slug/processing-errors/',
  24. body: [],
  25. });
  26. MockApiClient.addMockResponse({
  27. url: '/organizations/org-slug/projects/',
  28. body: [],
  29. });
  30. MockApiClient.addMockResponse({
  31. url: '/organizations/org-slug/members/',
  32. body: [],
  33. });
  34. MockApiClient.addMockResponse({
  35. url: '/organizations/org-slug/teams/',
  36. body: [team],
  37. });
  38. });
  39. it('renders', async function () {
  40. const {organization, router} = initializeOrg();
  41. OrganizationStore.onUpdate(organization);
  42. render(<Monitors />, {organization, router});
  43. expect(await screen.findByText('Cron Monitors')).toBeInTheDocument();
  44. });
  45. it('correctly filters on owner', async function () {
  46. const {organization, router} = initializeOrg({
  47. router: {location: {query: {cursor: 'test-cursor'}}},
  48. });
  49. OrganizationStore.onUpdate(organization);
  50. render(<Monitors />, {organization, router});
  51. expect(await screen.findByText('Cron Monitors')).toBeInTheDocument();
  52. await userEvent.click(screen.getByRole('button', {name: 'All Owners'}));
  53. await userEvent.click(screen.getByRole('option', {name: '#team-slug'}));
  54. expect(mockNavigate).toHaveBeenLastCalledWith(
  55. {
  56. query: {
  57. cursor: undefined, // Confirm that the cursor is reset
  58. owner: ['team:1'],
  59. },
  60. },
  61. {replace: true}
  62. );
  63. });
  64. });