UsersActionBar.test.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { render, screen } from '@testing-library/react';
  2. import React from 'react';
  3. import { mockToolkitActionCreator } from 'test/core/redux/mocks';
  4. import { Props, UsersActionBar } from './UsersActionBar';
  5. import { setUsersSearchQuery } from './state/reducers';
  6. jest.mock('app/core/core', () => ({
  7. contextSrv: {
  8. hasPermission: () => true,
  9. hasAccess: () => true,
  10. },
  11. }));
  12. const setup = (propOverrides?: object) => {
  13. const props: Props = {
  14. searchQuery: '',
  15. setUsersSearchQuery: mockToolkitActionCreator(setUsersSearchQuery),
  16. onShowInvites: jest.fn(),
  17. pendingInvitesCount: 0,
  18. canInvite: false,
  19. externalUserMngLinkUrl: '',
  20. externalUserMngLinkName: '',
  21. showInvites: false,
  22. };
  23. Object.assign(props, propOverrides);
  24. const { rerender } = render(<UsersActionBar {...props} />);
  25. return { rerender, props };
  26. };
  27. describe('Render', () => {
  28. it('should render component', () => {
  29. setup();
  30. expect(screen.getByTestId('users-action-bar')).toBeInTheDocument();
  31. });
  32. it('should render pending invites button', () => {
  33. setup({
  34. pendingInvitesCount: 5,
  35. });
  36. expect(screen.getByRole('radio', { name: 'Pending Invites (5)' })).toBeInTheDocument();
  37. });
  38. it('should show invite button', () => {
  39. setup({
  40. canInvite: true,
  41. });
  42. expect(screen.getByRole('link', { name: 'Invite' })).toHaveAttribute('href', 'org/users/invite');
  43. });
  44. it('should show external user management button', () => {
  45. setup({
  46. externalUserMngLinkUrl: 'some/url',
  47. externalUserMngLinkName: 'someUrl',
  48. });
  49. expect(screen.getByRole('link', { name: 'someUrl' })).toHaveAttribute('href', 'some/url');
  50. });
  51. });