pageHeaderActions.spec.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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(<PageHeaderActions showAddMetricButton addCustomMetric={addCustomMetric} />);
  12. const button = screen.getByRole('button', {name: 'Add Custom Metrics'});
  13. expect(button).toBeInTheDocument();
  14. await userEvent.click(button);
  15. expect(addCustomMetric).toHaveBeenCalled();
  16. });
  17. it('display "add new metric" button', async function () {
  18. render(
  19. <PageHeaderActions showAddMetricButton addCustomMetric={() => jest.fn()} />,
  20. {
  21. organization: OrganizationFixture({
  22. features: [
  23. 'custom-metrics-extraction-rule',
  24. 'custom-metrics-extraction-rule-ui',
  25. ],
  26. }),
  27. }
  28. );
  29. const button = screen.getByRole('button', {name: 'Add New Metric'});
  30. expect(button).toBeInTheDocument();
  31. await userEvent.click(button);
  32. expect(navigateTo).toHaveBeenCalledWith(
  33. `/settings/projects/:projectId/metrics/configure-metric/`,
  34. expect.objectContaining({
  35. params: expect.objectContaining({
  36. projectId: 'project-slug',
  37. }),
  38. })
  39. );
  40. });
  41. });
  42. });