AlertRuleItem.test.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { render, screen, fireEvent } from '@testing-library/react';
  2. import React from 'react';
  3. import AlertRuleItem, { Props } from './AlertRuleItem';
  4. const setup = (propOverrides?: object) => {
  5. const props: Props = {
  6. rule: {
  7. id: 1,
  8. dashboardId: 1,
  9. panelId: 1,
  10. name: 'Some rule',
  11. state: 'Open',
  12. stateText: 'state text',
  13. stateIcon: 'icon',
  14. stateClass: 'state class',
  15. stateAge: 'age',
  16. url: 'https://something.something.darkside',
  17. },
  18. search: '',
  19. onTogglePause: jest.fn(),
  20. };
  21. Object.assign(props, propOverrides);
  22. return render(<AlertRuleItem {...props} />);
  23. };
  24. describe('AlertRuleItem', () => {
  25. it('should render component', () => {
  26. const mockToggle = jest.fn();
  27. setup({ onTogglePause: mockToggle });
  28. expect(screen.getByText('Some rule')).toBeInTheDocument();
  29. expect(screen.getByText('state text')).toBeInTheDocument();
  30. expect(screen.getByText('Pause')).toBeInTheDocument();
  31. expect(screen.getByText('Edit alert')).toBeInTheDocument();
  32. fireEvent.click(screen.getByText('Pause'));
  33. expect(mockToggle).toHaveBeenCalled();
  34. });
  35. });