grafana/public/app/features/manage-dashboards/components/SnapshotListTable.test.tsx
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

61 lines
1.6 KiB
TypeScript

import { locationService } from '@grafana/runtime';
import { getSnapshots } from './SnapshotListTable';
jest.mock('@grafana/runtime', () => ({
...(jest.requireActual('@grafana/runtime') as unknown as object),
getBackendSrv: () => ({
get: jest.fn().mockResolvedValue([
{
name: 'Snap 1',
key: 'JRXqfKihKZek70FM6Xaq502NxH7OyyEs',
external: true,
externalUrl: 'https://www.externalSnapshotUrl.com',
},
{
id: 3,
name: 'Snap 2',
key: 'RziRfhlBDTjwyYGoHAjnWyrMNQ1zUg3j',
external: false,
externalUrl: '',
},
]),
}),
}));
describe('getSnapshots', () => {
(global as any).window = Object.create(window);
Object.defineProperty(window, 'location', {
value: {
href: 'http://localhost:3000/grafana/dashboard/snapshots',
},
writable: true,
});
locationService.push('/dashboard/snapshots');
test('returns correct snapshot urls', async () => {
const results = await getSnapshots();
expect(results).toMatchInlineSnapshot(`
Array [
Object {
"external": true,
"externalUrl": "https://www.externalSnapshotUrl.com",
"key": "JRXqfKihKZek70FM6Xaq502NxH7OyyEs",
"name": "Snap 1",
"url": "/dashboard/snapshot/JRXqfKihKZek70FM6Xaq502NxH7OyyEs",
},
Object {
"external": false,
"externalUrl": "",
"id": 3,
"key": "RziRfhlBDTjwyYGoHAjnWyrMNQ1zUg3j",
"name": "Snap 2",
"url": "/dashboard/snapshot/RziRfhlBDTjwyYGoHAjnWyrMNQ1zUg3j",
},
]
`);
});
});