actions.test.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { thunkTester } from 'test/core/thunk/thunkTester';
  2. import { setBackendSrv } from '@grafana/runtime';
  3. import { importDashboard } from './actions';
  4. import { DataSourceInput, ImportDashboardDTO, initialImportDashboardState, InputType } from './reducers';
  5. describe('importDashboard', () => {
  6. it('Should send data source uid', async () => {
  7. const form: ImportDashboardDTO = {
  8. title: 'Asda',
  9. uid: '12',
  10. gnetId: 'asd',
  11. constants: [],
  12. dataSources: [
  13. {
  14. id: 1,
  15. uid: 'ds-uid',
  16. name: 'ds-name',
  17. type: 'prometheus',
  18. } as any,
  19. ],
  20. elements: [],
  21. folder: {
  22. id: 1,
  23. title: 'title',
  24. },
  25. };
  26. let postArgs: any;
  27. setBackendSrv({
  28. post: (url: string, args: any) => {
  29. postArgs = args;
  30. return Promise.resolve({
  31. importedUrl: '/my/dashboard',
  32. });
  33. },
  34. } as any);
  35. await thunkTester({
  36. importDashboard: {
  37. ...initialImportDashboardState,
  38. inputs: {
  39. dataSources: [
  40. {
  41. name: 'ds-name',
  42. pluginId: 'prometheus',
  43. type: InputType.DataSource,
  44. },
  45. ] as DataSourceInput[],
  46. constants: [],
  47. libraryPanels: [],
  48. },
  49. },
  50. })
  51. .givenThunk(importDashboard)
  52. .whenThunkIsDispatched(form);
  53. expect(postArgs).toEqual({
  54. dashboard: {
  55. title: 'Asda',
  56. uid: '12',
  57. },
  58. folderId: 1,
  59. inputs: [
  60. {
  61. name: 'ds-name',
  62. pluginId: 'prometheus',
  63. type: 'datasource',
  64. value: 'ds-uid',
  65. },
  66. ],
  67. overwrite: true,
  68. });
  69. });
  70. });