SnapshotListTable.test.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { locationService } from '@grafana/runtime';
  2. import { getSnapshots } from './SnapshotListTable';
  3. jest.mock('@grafana/runtime', () => ({
  4. ...(jest.requireActual('@grafana/runtime') as unknown as object),
  5. getBackendSrv: () => ({
  6. get: jest.fn().mockResolvedValue([
  7. {
  8. name: 'Snap 1',
  9. key: 'JRXqfKihKZek70FM6Xaq502NxH7OyyEs',
  10. external: true,
  11. externalUrl: 'https://www.externalSnapshotUrl.com',
  12. },
  13. {
  14. id: 3,
  15. name: 'Snap 2',
  16. key: 'RziRfhlBDTjwyYGoHAjnWyrMNQ1zUg3j',
  17. external: false,
  18. externalUrl: '',
  19. },
  20. ]),
  21. }),
  22. }));
  23. describe('getSnapshots', () => {
  24. (global as any).window = Object.create(window);
  25. Object.defineProperty(window, 'location', {
  26. value: {
  27. href: 'http://localhost:3000/grafana/dashboard/snapshots',
  28. },
  29. writable: true,
  30. });
  31. locationService.push('/dashboard/snapshots');
  32. test('returns correct snapshot urls', async () => {
  33. const results = await getSnapshots();
  34. expect(results).toMatchInlineSnapshot(`
  35. Array [
  36. Object {
  37. "external": true,
  38. "externalUrl": "https://www.externalSnapshotUrl.com",
  39. "key": "JRXqfKihKZek70FM6Xaq502NxH7OyyEs",
  40. "name": "Snap 1",
  41. "url": "/dashboard/snapshot/JRXqfKihKZek70FM6Xaq502NxH7OyyEs",
  42. },
  43. Object {
  44. "external": false,
  45. "externalUrl": "",
  46. "id": 3,
  47. "key": "RziRfhlBDTjwyYGoHAjnWyrMNQ1zUg3j",
  48. "name": "Snap 2",
  49. "url": "/dashboard/snapshot/RziRfhlBDTjwyYGoHAjnWyrMNQ1zUg3j",
  50. },
  51. ]
  52. `);
  53. });
  54. });