From 72cd81c8036d9222043ebf52db5e2a28394fa3c5 Mon Sep 17 00:00:00 2001 From: Ashley Harrison Date: Fri, 2 Feb 2024 17:30:05 +0000 Subject: [PATCH] fix unit tests --- .betterer.results | 3 -- .../manage-dashboards/state/actions.test.ts | 45 ++++++++++--------- public/test/core/thunk/thunkTester.ts | 4 +- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.betterer.results b/.betterer.results index 845ba047936..f49138d6152 100644 --- a/.betterer.results +++ b/.betterer.results @@ -3998,9 +3998,6 @@ exports[`better eslint`] = { [0, 0, 0, "Styles should be written using objects.", "4"], [0, 0, 0, "Styles should be written using objects.", "5"] ], - "public/app/features/manage-dashboards/state/actions.test.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/features/manage-dashboards/state/actions.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], diff --git a/public/app/features/manage-dashboards/state/actions.test.ts b/public/app/features/manage-dashboards/state/actions.test.ts index 1b9f123473f..f9f465989f6 100644 --- a/public/app/features/manage-dashboards/state/actions.test.ts +++ b/public/app/features/manage-dashboards/state/actions.test.ts @@ -1,7 +1,7 @@ import { thunkTester } from 'test/core/thunk/thunkTester'; import { DataSourceInstanceSettings, ThresholdsMode } from '@grafana/data'; -import { BackendSrv, setBackendSrv } from '@grafana/runtime'; +import { BackendSrv, BackendSrvRequest, setBackendSrv } from '@grafana/runtime'; import { defaultDashboard, FieldColorModeId } from '@grafana/schema'; import { getLibraryPanel } from 'app/features/library-panels/state/api'; @@ -40,14 +40,11 @@ describe('importDashboard', () => { }, }; - let postArgs: any; + let fetchArgs: unknown; setBackendSrv({ - post: (url, args) => { - postArgs = args; - return Promise.resolve({ - importedUrl: '/my/dashboard', - }); + fetch: (options: BackendSrvRequest) => { + fetchArgs = options; }, } as BackendSrv); @@ -70,22 +67,26 @@ describe('importDashboard', () => { .givenThunk(importDashboard) .whenThunkIsDispatched(form); - expect(postArgs).toEqual({ - dashboard: { - title: 'Asda', - uid: '12', - }, - folderUid: '5v6e5VH4z', - inputs: [ - { - name: 'ds-name', - pluginId: 'prometheus', - type: 'datasource', - value: 'ds-uid', + expect(fetchArgs).toEqual( + expect.objectContaining({ + data: { + dashboard: { + title: 'Asda', + uid: '12', + }, + folderUid: '5v6e5VH4z', + inputs: [ + { + name: 'ds-name', + pluginId: 'prometheus', + type: 'datasource', + value: 'ds-uid', + }, + ], + overwrite: true, }, - ], - overwrite: true, - }); + }) + ); }); }); diff --git a/public/test/core/thunk/thunkTester.ts b/public/test/core/thunk/thunkTester.ts index 9e228630d2e..947e57c01ad 100644 --- a/public/test/core/thunk/thunkTester.ts +++ b/public/test/core/thunk/thunkTester.ts @@ -2,7 +2,9 @@ import { PayloadAction } from '@reduxjs/toolkit'; import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; -const mockStore = configureMockStore([thunk]); +import { browseDashboardsAPI } from 'app/features/browse-dashboards/api/browseDashboardsAPI'; + +const mockStore = configureMockStore([thunk, browseDashboardsAPI.middleware]); export interface ThunkGiven { givenThunk: (thunkFunction: any) => ThunkWhen;