mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Refactor: Adds Redux Toolkit package * Refactor: Uses configureStore from Redux Toolkit * Refactor: Migrates applicationReducer * Refactor: Migrates appNotificationsReducer * Refactor: Migrates locationReducer * Refactor: Migrates navModelReducer * Refactor: Migrates teamsReducer and teamReducer * Refactor: Migrates cleanUpAction * Refactor: Migrates alertRulesReducer * Refactor: Cleans up recursiveCleanState * Refactor: Switched to Angular compatible reducers * Refactor: Migrates folderReducer * Refactor: Migrates dashboardReducer * Migrates panelEditorReducer * Refactor: Migrates dataSourcesReducer * Refactor: Migrates usersReducer * Refactor: Migrates organizationReducer * Refactor: Migrates pluginsReducer * Refactor: Migrates ldapReducer and ldapUserReducer * Refactor: Migrates apiKeysReducer * Refactor: Migrates exploreReducer and itemReducer * Refactor: Removes actionCreatorFactory and reducerFactory * Refactor: Moves mocks to test section * Docs: Removes sections about home grown framework * Update contribute/style-guides/redux.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Refactor: Cleans up some code * Refactor: Adds state typings * Refactor: Cleans up typings * Refactor: Adds comment about ImmerJs autoFreeze Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
152 lines
4.5 KiB
TypeScript
152 lines
4.5 KiB
TypeScript
import { reducerTester } from '../../../../test/core/redux/reducerTester';
|
|
import { PluginsState } from '../../../types';
|
|
import {
|
|
initialState,
|
|
pluginDashboardsLoad,
|
|
pluginDashboardsLoaded,
|
|
pluginsLoaded,
|
|
pluginsReducer,
|
|
setPluginsLayoutMode,
|
|
setPluginsSearchQuery,
|
|
} from './reducers';
|
|
import { PluginMetaInfo, PluginType } from '@grafana/data';
|
|
import { LayoutModes } from '../../../core/components/LayoutSelector/LayoutSelector';
|
|
|
|
describe('pluginsReducer', () => {
|
|
describe('when pluginsLoaded is dispatched', () => {
|
|
it('then state should be correct', () => {
|
|
reducerTester<PluginsState>()
|
|
.givenReducer(pluginsReducer, { ...initialState })
|
|
.whenActionIsDispatched(
|
|
pluginsLoaded([
|
|
{
|
|
id: 'some-id',
|
|
baseUrl: 'some-url',
|
|
module: 'some module',
|
|
name: 'Some Plugin',
|
|
type: PluginType.app,
|
|
info: {} as PluginMetaInfo,
|
|
},
|
|
])
|
|
)
|
|
.thenStateShouldEqual({
|
|
...initialState,
|
|
hasFetched: true,
|
|
plugins: [
|
|
{
|
|
baseUrl: 'some-url',
|
|
id: 'some-id',
|
|
info: {} as PluginMetaInfo,
|
|
module: 'some module',
|
|
name: 'Some Plugin',
|
|
type: PluginType.app,
|
|
},
|
|
],
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('when setPluginsSearchQuery is dispatched', () => {
|
|
it('then state should be correct', () => {
|
|
reducerTester<PluginsState>()
|
|
.givenReducer(pluginsReducer, { ...initialState })
|
|
.whenActionIsDispatched(setPluginsSearchQuery('A query'))
|
|
.thenStateShouldEqual({
|
|
...initialState,
|
|
searchQuery: 'A query',
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('when setPluginsLayoutMode is dispatched', () => {
|
|
it('then state should be correct', () => {
|
|
reducerTester<PluginsState>()
|
|
.givenReducer(pluginsReducer, { ...initialState })
|
|
.whenActionIsDispatched(setPluginsLayoutMode(LayoutModes.List))
|
|
.thenStateShouldEqual({
|
|
...initialState,
|
|
layoutMode: LayoutModes.List,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('when pluginDashboardsLoad is dispatched', () => {
|
|
it('then state should be correct', () => {
|
|
reducerTester<PluginsState>()
|
|
.givenReducer(pluginsReducer, {
|
|
...initialState,
|
|
dashboards: [
|
|
{
|
|
dashboardId: 1,
|
|
title: 'Some Dash',
|
|
description: 'Some Desc',
|
|
folderId: 2,
|
|
imported: false,
|
|
importedRevision: 1,
|
|
importedUri: 'some-uri',
|
|
importedUrl: 'some-url',
|
|
path: 'some/path',
|
|
pluginId: 'some-plugin-id',
|
|
removed: false,
|
|
revision: 22,
|
|
slug: 'someSlug',
|
|
},
|
|
],
|
|
})
|
|
.whenActionIsDispatched(pluginDashboardsLoad())
|
|
.thenStateShouldEqual({
|
|
...initialState,
|
|
dashboards: [],
|
|
isLoadingPluginDashboards: true,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('when pluginDashboardsLoad is dispatched', () => {
|
|
it('then state should be correct', () => {
|
|
reducerTester<PluginsState>()
|
|
.givenReducer(pluginsReducer, { ...initialState, isLoadingPluginDashboards: true })
|
|
.whenActionIsDispatched(
|
|
pluginDashboardsLoaded([
|
|
{
|
|
dashboardId: 1,
|
|
title: 'Some Dash',
|
|
description: 'Some Desc',
|
|
folderId: 2,
|
|
imported: false,
|
|
importedRevision: 1,
|
|
importedUri: 'some-uri',
|
|
importedUrl: 'some-url',
|
|
path: 'some/path',
|
|
pluginId: 'some-plugin-id',
|
|
removed: false,
|
|
revision: 22,
|
|
slug: 'someSlug',
|
|
},
|
|
])
|
|
)
|
|
.thenStateShouldEqual({
|
|
...initialState,
|
|
dashboards: [
|
|
{
|
|
dashboardId: 1,
|
|
title: 'Some Dash',
|
|
description: 'Some Desc',
|
|
folderId: 2,
|
|
imported: false,
|
|
importedRevision: 1,
|
|
importedUri: 'some-uri',
|
|
importedUrl: 'some-url',
|
|
path: 'some/path',
|
|
pluginId: 'some-plugin-id',
|
|
removed: false,
|
|
revision: 22,
|
|
slug: 'someSlug',
|
|
},
|
|
],
|
|
isLoadingPluginDashboards: false,
|
|
});
|
|
});
|
|
});
|
|
});
|