DataSourceList.test.tsx 902 B

123456789101112131415161718192021222324252627282930
  1. import { render, screen } from '@testing-library/react';
  2. import React from 'react';
  3. import { LayoutModes } from '@grafana/data';
  4. import DataSourcesList from './DataSourcesList';
  5. import { getMockDataSources } from './__mocks__/dataSourcesMocks';
  6. const setup = () => {
  7. const props = {
  8. dataSources: getMockDataSources(3),
  9. layoutMode: LayoutModes.Grid,
  10. };
  11. return render(<DataSourcesList {...props} />);
  12. };
  13. describe('DataSourcesList', () => {
  14. it('should render list of datasources', () => {
  15. setup();
  16. expect(screen.getAllByRole('listitem')).toHaveLength(3);
  17. expect(screen.getAllByRole('heading')).toHaveLength(3);
  18. });
  19. it('should render all elements in the list item', () => {
  20. setup();
  21. expect(screen.getByRole('heading', { name: 'dataSource-0' })).toBeInTheDocument();
  22. expect(screen.getByRole('link', { name: 'dataSource-0' })).toBeInTheDocument();
  23. });
  24. });