mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* support folderuid in FolderPicker * support folderuid in unified alerting * support folderuid when returning to view mode after editing a panel * support folderuid when preselecting the folderpicker in dashboard general settings * support folderuid when saving dashboard * support folderuid when pre-selecting folderpicker in dashboard form * support folderuid in routes when loading a dashboard * support folderuid when saving dashboard json * support folderuid when validating new dashboard name * support folderuid when moving dashboard to another folder * support folderuid on dashboard action buttons * support folderuid when creating a new dashboard on an empty folder * support folderuid when showing library panel modal * support folderuid when saving library panel * support folderuid when importing dashboard * fixed broken tests * use folderuid when importing dashboards * remove commented line * fix typo when comparing uid values
139 lines
3.7 KiB
TypeScript
139 lines
3.7 KiB
TypeScript
import { LoadingState } from '@grafana/data';
|
|
|
|
import { reducerTester } from '../../../../../test/core/redux/reducerTester';
|
|
import { LibraryElementDTO, LibraryElementKind } from '../../types';
|
|
|
|
import {
|
|
changePage,
|
|
initialLibraryPanelsViewState,
|
|
initSearch,
|
|
libraryPanelsViewReducer,
|
|
LibraryPanelsViewState,
|
|
searchCompleted,
|
|
} from './reducer';
|
|
|
|
describe('libraryPanelsViewReducer', () => {
|
|
describe('when initSearch is dispatched', () => {
|
|
it('then the state should be correct', () => {
|
|
reducerTester<LibraryPanelsViewState>()
|
|
.givenReducer(libraryPanelsViewReducer, { ...initialLibraryPanelsViewState })
|
|
.whenActionIsDispatched(initSearch())
|
|
.thenStateShouldEqual({
|
|
...initialLibraryPanelsViewState,
|
|
loadingState: LoadingState.Loading,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('when searchCompleted is dispatched', () => {
|
|
it('then the state should be correct', () => {
|
|
const payload = {
|
|
perPage: 10,
|
|
page: 3,
|
|
libraryPanels: getLibraryPanelMocks(2),
|
|
totalCount: 200,
|
|
};
|
|
|
|
reducerTester<LibraryPanelsViewState>()
|
|
.givenReducer(libraryPanelsViewReducer, { ...initialLibraryPanelsViewState })
|
|
.whenActionIsDispatched(searchCompleted(payload))
|
|
.thenStateShouldEqual({
|
|
...initialLibraryPanelsViewState,
|
|
perPage: 10,
|
|
page: 3,
|
|
libraryPanels: payload.libraryPanels,
|
|
totalCount: 200,
|
|
loadingState: LoadingState.Done,
|
|
numberOfPages: 20,
|
|
});
|
|
});
|
|
|
|
describe('and page is greater than the current number of pages', () => {
|
|
it('then the state should be correct', () => {
|
|
const payload = {
|
|
perPage: 10,
|
|
page: 21,
|
|
libraryPanels: getLibraryPanelMocks(2),
|
|
totalCount: 200,
|
|
};
|
|
|
|
reducerTester<LibraryPanelsViewState>()
|
|
.givenReducer(libraryPanelsViewReducer, { ...initialLibraryPanelsViewState })
|
|
.whenActionIsDispatched(searchCompleted(payload))
|
|
.thenStateShouldEqual({
|
|
...initialLibraryPanelsViewState,
|
|
perPage: 10,
|
|
page: 20,
|
|
libraryPanels: payload.libraryPanels,
|
|
totalCount: 200,
|
|
loadingState: LoadingState.Done,
|
|
numberOfPages: 20,
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('when changePage is dispatched', () => {
|
|
it('then the state should be correct', () => {
|
|
reducerTester<LibraryPanelsViewState>()
|
|
.givenReducer(libraryPanelsViewReducer, { ...initialLibraryPanelsViewState })
|
|
.whenActionIsDispatched(changePage({ page: 42 }))
|
|
.thenStateShouldEqual({
|
|
...initialLibraryPanelsViewState,
|
|
page: 42,
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
function getLibraryPanelMocks(count: number): LibraryElementDTO[] {
|
|
const mocks: LibraryElementDTO[] = [];
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
mocks.push(
|
|
mockLibraryPanel({
|
|
uid: i.toString(10),
|
|
id: i,
|
|
name: `Test Panel ${i}`,
|
|
})
|
|
);
|
|
}
|
|
|
|
return mocks;
|
|
}
|
|
|
|
function mockLibraryPanel({
|
|
uid = '1',
|
|
id = 1,
|
|
orgId = 1,
|
|
folderUid = '',
|
|
name = 'Test Panel',
|
|
model = { type: 'text', title: 'Test Panel' },
|
|
meta = {
|
|
folderName: 'General',
|
|
folderUid: '',
|
|
connectedDashboards: 0,
|
|
created: '2021-01-01T00:00:00',
|
|
createdBy: { id: 1, name: 'User X', avatarUrl: '/avatar/abc' },
|
|
updated: '2021-01-02T00:00:00',
|
|
updatedBy: { id: 2, name: 'User Y', avatarUrl: '/avatar/xyz' },
|
|
},
|
|
version = 1,
|
|
description = 'a description',
|
|
type = 'text',
|
|
}: Partial<LibraryElementDTO> = {}): LibraryElementDTO {
|
|
return {
|
|
uid,
|
|
id,
|
|
orgId,
|
|
folderUid,
|
|
name,
|
|
kind: LibraryElementKind.Panel,
|
|
model,
|
|
version,
|
|
meta,
|
|
description,
|
|
type,
|
|
};
|
|
}
|