mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Scenes: Support new top nav * Page: Make Page component support new and old dashboard page layouts * Pass scrollbar props * Fixing flex layout for dashboard * Progress on dashboard settings working with topnav * Updated * Annotations working * Starting to work fully * Fix merge issue * Fixed tests * Added buttons to annotations editor * Updating tests * Move Page component to each page * fixed general settings page * Fixed versions * Fixed annotation item page * Variables section working * Fixed tests * Minor fixes to versions * Update * Fixing unit tests * Adding add variable button * Restore annotations edit form so it's the same as before * Fixed semicolon in dashboard permissions * Fixing unit tests * Fixing tests * Minor test update * Fixing unit test * Fixing e2e tests * fix for e2e test * fix a11y issues * Changing places Settings -> General * Trying to fix a11y * I hope this fixes the e2e test * Fixing merge issue * tweak
69 lines
2.9 KiB
TypeScript
69 lines
2.9 KiB
TypeScript
import { initialState } from '../../dashboard/state/reducers';
|
|
import { variableAdapters } from '../adapters';
|
|
import { createConstantVariableAdapter } from '../constant/adapter';
|
|
import { initialConstantVariableModelState } from '../constant/reducer';
|
|
import * as inspectUtils from '../inspect/utils';
|
|
import { constantBuilder, customBuilder } from '../shared/testing/builders';
|
|
import { initialKeyedVariablesState, toKeyedAction } from '../state/keyedVariablesReducer';
|
|
import * as selectors from '../state/selectors';
|
|
import { addVariable } from '../state/sharedReducer';
|
|
|
|
import { getNextAvailableId, initListMode, createNewVariable } from './actions';
|
|
|
|
describe('getNextAvailableId', () => {
|
|
describe('when called with a custom type and there is already 2 variables', () => {
|
|
it('then the correct id should be created', () => {
|
|
const custom1 = customBuilder().withId('custom0').withName('custom0').build();
|
|
const constant1 = constantBuilder().withId('custom1').withName('custom1').build();
|
|
const variables = [custom1, constant1];
|
|
const type = 'custom';
|
|
|
|
const result = getNextAvailableId(type, variables);
|
|
|
|
expect(result).toEqual('custom2');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('createNewVariable', () => {
|
|
variableAdapters.setInit(() => [createConstantVariableAdapter()]);
|
|
|
|
it('should dispatch with the correct rootStateKey', () => {
|
|
jest.spyOn(selectors, 'getVariablesByKey').mockReturnValue([]);
|
|
jest.spyOn(selectors, 'getNewVariableIndex').mockReturnValue(0);
|
|
const mockId = 'constant0';
|
|
const mockGetState = jest.fn().mockReturnValue({ templating: initialKeyedVariablesState });
|
|
const mockDispatch = jest.fn();
|
|
const model = { ...initialConstantVariableModelState, name: mockId, id: mockId, rootStateKey: 'null' };
|
|
|
|
createNewVariable(null, 'constant')(mockDispatch, mockGetState, undefined);
|
|
expect(mockDispatch).toHaveBeenCalledTimes(1);
|
|
expect(mockDispatch.mock.calls[0][0]).toEqual(
|
|
toKeyedAction('null', addVariable({ data: { global: false, index: 0, model }, type: 'constant', id: mockId }))
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('initListMode', () => {
|
|
variableAdapters.setInit(() => [createConstantVariableAdapter()]);
|
|
|
|
it('should dispatch with the correct rootStateKey', () => {
|
|
jest.spyOn(selectors, 'getEditorVariables').mockReturnValue([]);
|
|
jest.spyOn(inspectUtils, 'createUsagesNetwork').mockReturnValue({ usages: [], unUsed: [] });
|
|
jest.spyOn(inspectUtils, 'transformUsagesToNetwork').mockReturnValue([]);
|
|
const mockGetState = jest.fn().mockReturnValue({ templating: initialKeyedVariablesState, dashboard: initialState });
|
|
const mockDispatch = jest.fn();
|
|
|
|
initListMode(null)(mockDispatch, mockGetState, undefined);
|
|
const keyedAction = {
|
|
type: expect.any(String),
|
|
payload: {
|
|
key: 'null',
|
|
action: expect.any(Object),
|
|
},
|
|
};
|
|
expect(mockDispatch).toHaveBeenCalledTimes(1);
|
|
expect(mockDispatch.mock.calls[0][0]).toMatchObject(keyedAction);
|
|
});
|
|
});
|