mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* wip for pagination * kind of doing pagination, but only for the root folder * wip * wip * refactor paginated fetchChildren * make sure dashboards are loaded if a folder contains only dashboards * rename lastKindHasMoreItems * load additional root pages * undo accidental commit * return promise from loadMoreChildren, and prevent loading additional page while a request is already in flight * rename browseDashboards/fetchChildren action so it's more clear * starting to revalidate children after an action * unset general uid * comment * clean up * fix tests omg * cleanup * fix items not loading after invalidating loaded cache * comment * fix lints
81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import { configureStore } from 'app/store/configureStore';
|
|
import { useSelector } from 'app/types';
|
|
|
|
import { fullyLoadedViewItemCollection } from '../fixtures/state.fixtures';
|
|
import { BrowseDashboardsState } from '../types';
|
|
|
|
import { useBrowseLoadingStatus } from './hooks';
|
|
|
|
jest.mock('app/types', () => {
|
|
const original = jest.requireActual('app/types');
|
|
return {
|
|
...original,
|
|
useSelector: jest.fn(),
|
|
};
|
|
});
|
|
|
|
function createInitialState(partial: Partial<BrowseDashboardsState>): BrowseDashboardsState {
|
|
return {
|
|
rootItems: undefined,
|
|
childrenByParentUID: {},
|
|
openFolders: {},
|
|
selectedItems: {
|
|
$all: false,
|
|
dashboard: {},
|
|
folder: {},
|
|
panel: {},
|
|
},
|
|
|
|
...partial,
|
|
};
|
|
}
|
|
|
|
describe('browse-dashboards state hooks', () => {
|
|
const folderUID = 'abc-123';
|
|
|
|
function mockState(browseState: BrowseDashboardsState) {
|
|
const wholeState = configureStore().getState();
|
|
wholeState.browseDashboards = browseState;
|
|
|
|
jest.mocked(useSelector).mockImplementationOnce((callback) => {
|
|
return callback(wholeState);
|
|
});
|
|
}
|
|
|
|
describe('useBrowseLoadingStatus', () => {
|
|
it('returns loading when root view is loading', () => {
|
|
mockState(createInitialState({ rootItems: undefined }));
|
|
|
|
const status = useBrowseLoadingStatus(undefined);
|
|
expect(status).toEqual('pending');
|
|
});
|
|
|
|
it('returns loading when folder view is loading', () => {
|
|
mockState(createInitialState({ childrenByParentUID: {} }));
|
|
|
|
const status = useBrowseLoadingStatus(folderUID);
|
|
expect(status).toEqual('pending');
|
|
});
|
|
|
|
it('returns fulfilled when root view is finished loading', () => {
|
|
mockState(createInitialState({ rootItems: fullyLoadedViewItemCollection([]) }));
|
|
|
|
const status = useBrowseLoadingStatus(undefined);
|
|
expect(status).toEqual('fulfilled');
|
|
});
|
|
|
|
it('returns fulfilled when folder view is finished loading', () => {
|
|
mockState(
|
|
createInitialState({
|
|
childrenByParentUID: {
|
|
[folderUID]: fullyLoadedViewItemCollection([]),
|
|
},
|
|
})
|
|
);
|
|
|
|
const status = useBrowseLoadingStatus(folderUID);
|
|
expect(status).toEqual('fulfilled');
|
|
});
|
|
});
|
|
});
|