pageHeaderActions.spec.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import {navigateTo} from 'sentry/actionCreators/navigation';
  4. import {PageHeaderActions} from 'sentry/views/metrics/pageHeaderActions';
  5. jest.mock('sentry/actionCreators/navigation');
  6. jest.mock('sentry/views/metrics/useCreateDashboard');
  7. describe('Metrics Page Header Actions', function () {
  8. describe('add metric buttons', function () {
  9. it('display "add custom metrics" button', async function () {
  10. const addCustomMetric = jest.fn();
  11. render(
  12. <PageHeaderActions showCustomMetricButton addCustomMetric={addCustomMetric} />
  13. );
  14. const button = screen.getByRole('button', {name: 'Add Custom Metrics'});
  15. expect(button).toBeInTheDocument();
  16. await userEvent.click(button);
  17. expect(addCustomMetric).toHaveBeenCalled();
  18. });
  19. it('display "add new metric" button', async function () {
  20. render(
  21. <PageHeaderActions showCustomMetricButton addCustomMetric={() => jest.fn()} />,
  22. {
  23. organization: OrganizationFixture({
  24. features: ['custom-metrics-extraction-rule'],
  25. }),
  26. }
  27. );
  28. const button = screen.getByRole('button', {name: 'Add New Metric'});
  29. expect(button).toBeInTheDocument();
  30. await userEvent.click(button);
  31. expect(navigateTo).toHaveBeenCalledWith(
  32. `/settings/projects/:projectId/metrics/`,
  33. expect.objectContaining({
  34. params: expect.objectContaining({
  35. projectId: 'project-slug',
  36. }),
  37. })
  38. );
  39. });
  40. });
  41. });