DataSourcePermissionsList.test.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { render, screen } from '@testing-library/react';
  2. import React from 'react';
  3. import { DataSourcePermission } from '../types';
  4. import { DataSourcePermissionsList, Props } from './DataSourcePermissionsList';
  5. import {
  6. getMockDataSourcePermissionsTeam,
  7. getMockDataSourcePermissionsUser,
  8. } from './__mocks__/dataSourcePermissionMocks';
  9. jest.mock('app/core/core', () => {
  10. return {
  11. contextSrv: {
  12. hasPermission: () => true,
  13. },
  14. };
  15. });
  16. const setup = (propOverrides?: object) => {
  17. const props: Props = {
  18. items: [] as DataSourcePermission[],
  19. onRemoveItem: jest.fn(),
  20. };
  21. Object.assign(props, propOverrides);
  22. render(<DataSourcePermissionsList {...props} />);
  23. };
  24. describe('Render', () => {
  25. it('should render component', () => {
  26. setup();
  27. expect(screen.getByRole('table')).toBeInTheDocument();
  28. expect(screen.getAllByRole('row')).toHaveLength(1);
  29. });
  30. it('should render items', () => {
  31. setup({
  32. items: [getMockDataSourcePermissionsUser(), getMockDataSourcePermissionsTeam()],
  33. });
  34. expect(screen.getAllByRole('row')).toHaveLength(3);
  35. expect(screen.getAllByAltText('Avatar for user 3')).toHaveLength(1);
  36. expect(screen.getAllByAltText('Avatar for team 1')).toHaveLength(1);
  37. });
  38. });