ServerStats.test.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { render, screen } from '@testing-library/react';
  2. import React from 'react';
  3. import { ServerStats } from './ServerStats';
  4. import { ServerStat } from './state/apis';
  5. const stats: ServerStat = {
  6. activeAdmins: 1,
  7. activeEditors: 0,
  8. activeSessions: 1,
  9. activeUsers: 1,
  10. activeViewers: 0,
  11. admins: 1,
  12. alerts: 5,
  13. dashboards: 1599,
  14. datasources: 54,
  15. editors: 2,
  16. orgs: 1,
  17. playlists: 1,
  18. snapshots: 1,
  19. stars: 3,
  20. tags: 42,
  21. users: 5,
  22. viewers: 2,
  23. };
  24. jest.mock('./state/apis', () => ({
  25. getServerStats: async () => stats,
  26. }));
  27. jest.mock('../../core/services/context_srv', () => ({
  28. contextSrv: {
  29. hasAccess: () => true,
  30. },
  31. }));
  32. describe('ServerStats', () => {
  33. it('Should render page with stats', async () => {
  34. render(<ServerStats />);
  35. expect(await screen.findByRole('heading', { name: /instance statistics/i })).toBeInTheDocument();
  36. expect(screen.getByText('Dashboards (starred)')).toBeInTheDocument();
  37. expect(screen.getByText('Tags')).toBeInTheDocument();
  38. expect(screen.getByText('Playlists')).toBeInTheDocument();
  39. expect(screen.getByText('Snapshots')).toBeInTheDocument();
  40. expect(screen.getByRole('link', { name: 'Manage dashboards' })).toBeInTheDocument();
  41. expect(screen.getByRole('link', { name: 'Manage data sources' })).toBeInTheDocument();
  42. expect(screen.getByRole('link', { name: 'Alerts' })).toBeInTheDocument();
  43. expect(screen.getByRole('link', { name: 'Manage users' })).toBeInTheDocument();
  44. });
  45. });