pageHeaderActions.spec.tsx 1.5 KB

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