|
|
@ -46,6 +46,10 @@ jest.mock('../../plugins/plugin_loader', () => ({ |
|
|
|
importDataSourcePlugin: () => mocks.pluginLoader.importDataSourcePlugin(), |
|
|
|
importDataSourcePlugin: () => mocks.pluginLoader.importDataSourcePlugin(), |
|
|
|
})); |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jest.mock('../../templating/template_srv', () => ({ |
|
|
|
|
|
|
|
replace: jest.fn().mockReturnValue(''), |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
describe('query actions', () => { |
|
|
|
describe('query actions', () => { |
|
|
|
variableAdapters.setInit(() => [createQueryVariableAdapter()]); |
|
|
|
variableAdapters.setInit(() => [createQueryVariableAdapter()]); |
|
|
|
|
|
|
|
|
|
|
@ -63,12 +67,13 @@ describe('query actions', () => { |
|
|
|
.whenAsyncActionIsDispatched(updateQueryVariableOptions(toVariablePayload(variable)), true); |
|
|
|
.whenAsyncActionIsDispatched(updateQueryVariableOptions(toVariablePayload(variable)), true); |
|
|
|
|
|
|
|
|
|
|
|
const option = createOption(ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE); |
|
|
|
const option = createOption(ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE); |
|
|
|
|
|
|
|
const update = { results: optionsMetrics, templatedRegex: '' }; |
|
|
|
|
|
|
|
|
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
const [updateOptions, updateTags, setCurrentAction] = actions; |
|
|
|
const [updateOptions, updateTags, setCurrentAction] = actions; |
|
|
|
const expectedNumberOfActions = 3; |
|
|
|
const expectedNumberOfActions = 3; |
|
|
|
|
|
|
|
|
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, optionsMetrics))); |
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, update))); |
|
|
|
expect(updateTags).toEqual(updateVariableTags(toVariablePayload(variable, tagsMetrics))); |
|
|
|
expect(updateTags).toEqual(updateVariableTags(toVariablePayload(variable, tagsMetrics))); |
|
|
|
expect(setCurrentAction).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
expect(setCurrentAction).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
return actions.length === expectedNumberOfActions; |
|
|
|
return actions.length === expectedNumberOfActions; |
|
|
@ -90,12 +95,13 @@ describe('query actions', () => { |
|
|
|
.whenAsyncActionIsDispatched(updateQueryVariableOptions(toVariablePayload(variable)), true); |
|
|
|
.whenAsyncActionIsDispatched(updateQueryVariableOptions(toVariablePayload(variable)), true); |
|
|
|
|
|
|
|
|
|
|
|
const option = createOption('A'); |
|
|
|
const option = createOption('A'); |
|
|
|
|
|
|
|
const update = { results: optionsMetrics, templatedRegex: '' }; |
|
|
|
|
|
|
|
|
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
const [updateOptions, updateTags, setCurrentAction] = actions; |
|
|
|
const [updateOptions, updateTags, setCurrentAction] = actions; |
|
|
|
const expectedNumberOfActions = 3; |
|
|
|
const expectedNumberOfActions = 3; |
|
|
|
|
|
|
|
|
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, optionsMetrics))); |
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, update))); |
|
|
|
expect(updateTags).toEqual(updateVariableTags(toVariablePayload(variable, tagsMetrics))); |
|
|
|
expect(updateTags).toEqual(updateVariableTags(toVariablePayload(variable, tagsMetrics))); |
|
|
|
expect(setCurrentAction).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
expect(setCurrentAction).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
return actions.length === expectedNumberOfActions; |
|
|
|
return actions.length === expectedNumberOfActions; |
|
|
@ -116,12 +122,13 @@ describe('query actions', () => { |
|
|
|
.whenAsyncActionIsDispatched(updateQueryVariableOptions(toVariablePayload(variable)), true); |
|
|
|
.whenAsyncActionIsDispatched(updateQueryVariableOptions(toVariablePayload(variable)), true); |
|
|
|
|
|
|
|
|
|
|
|
const option = createOption('A'); |
|
|
|
const option = createOption('A'); |
|
|
|
|
|
|
|
const update = { results: optionsMetrics, templatedRegex: '' }; |
|
|
|
|
|
|
|
|
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
const [updateOptions, setCurrentAction] = actions; |
|
|
|
const [updateOptions, setCurrentAction] = actions; |
|
|
|
const expectedNumberOfActions = 2; |
|
|
|
const expectedNumberOfActions = 2; |
|
|
|
|
|
|
|
|
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, optionsMetrics))); |
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, update))); |
|
|
|
expect(setCurrentAction).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
expect(setCurrentAction).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
return actions.length === expectedNumberOfActions; |
|
|
|
return actions.length === expectedNumberOfActions; |
|
|
|
}); |
|
|
|
}); |
|
|
@ -141,12 +148,13 @@ describe('query actions', () => { |
|
|
|
.whenAsyncActionIsDispatched(updateQueryVariableOptions(toVariablePayload(variable)), true); |
|
|
|
.whenAsyncActionIsDispatched(updateQueryVariableOptions(toVariablePayload(variable)), true); |
|
|
|
|
|
|
|
|
|
|
|
const option = createOption(ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE); |
|
|
|
const option = createOption(ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE); |
|
|
|
|
|
|
|
const update = { results: optionsMetrics, templatedRegex: '' }; |
|
|
|
|
|
|
|
|
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
const [updateOptions, setCurrentAction] = actions; |
|
|
|
const [updateOptions, setCurrentAction] = actions; |
|
|
|
const expectedNumberOfActions = 2; |
|
|
|
const expectedNumberOfActions = 2; |
|
|
|
|
|
|
|
|
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, optionsMetrics))); |
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, update))); |
|
|
|
expect(setCurrentAction).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
expect(setCurrentAction).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
return actions.length === expectedNumberOfActions; |
|
|
|
return actions.length === expectedNumberOfActions; |
|
|
|
}); |
|
|
|
}); |
|
|
@ -167,13 +175,14 @@ describe('query actions', () => { |
|
|
|
.whenAsyncActionIsDispatched(updateQueryVariableOptions(toVariablePayload(variable)), true); |
|
|
|
.whenAsyncActionIsDispatched(updateQueryVariableOptions(toVariablePayload(variable)), true); |
|
|
|
|
|
|
|
|
|
|
|
const option = createOption(ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE); |
|
|
|
const option = createOption(ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE); |
|
|
|
|
|
|
|
const update = { results: optionsMetrics, templatedRegex: '' }; |
|
|
|
|
|
|
|
|
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
const [clearErrors, updateOptions, setCurrentAction] = actions; |
|
|
|
const [clearErrors, updateOptions, setCurrentAction] = actions; |
|
|
|
const expectedNumberOfActions = 3; |
|
|
|
const expectedNumberOfActions = 3; |
|
|
|
|
|
|
|
|
|
|
|
expect(clearErrors).toEqual(removeVariableEditorError({ errorProp: 'update' })); |
|
|
|
expect(clearErrors).toEqual(removeVariableEditorError({ errorProp: 'update' })); |
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, optionsMetrics))); |
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, update))); |
|
|
|
expect(setCurrentAction).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
expect(setCurrentAction).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
return actions.length === expectedNumberOfActions; |
|
|
|
return actions.length === expectedNumberOfActions; |
|
|
|
}); |
|
|
|
}); |
|
|
@ -399,6 +408,7 @@ describe('query actions', () => { |
|
|
|
.whenAsyncActionIsDispatched(changeQueryVariableQuery(toVariablePayload(variable), query, definition), true); |
|
|
|
.whenAsyncActionIsDispatched(changeQueryVariableQuery(toVariablePayload(variable), query, definition), true); |
|
|
|
|
|
|
|
|
|
|
|
const option = createOption(ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE); |
|
|
|
const option = createOption(ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE); |
|
|
|
|
|
|
|
const update = { results: optionsMetrics, templatedRegex: '' }; |
|
|
|
|
|
|
|
|
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
const [clearError, changeQuery, changeDefinition, updateOptions, updateTags, setOption] = actions; |
|
|
|
const [clearError, changeQuery, changeDefinition, updateOptions, updateTags, setOption] = actions; |
|
|
@ -411,7 +421,7 @@ describe('query actions', () => { |
|
|
|
expect(changeDefinition).toEqual( |
|
|
|
expect(changeDefinition).toEqual( |
|
|
|
changeVariableProp(toVariablePayload(variable, { propName: 'definition', propValue: definition })) |
|
|
|
changeVariableProp(toVariablePayload(variable, { propName: 'definition', propValue: definition })) |
|
|
|
); |
|
|
|
); |
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, optionsMetrics))); |
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, update))); |
|
|
|
expect(updateTags).toEqual(updateVariableTags(toVariablePayload(variable, tagsMetrics))); |
|
|
|
expect(updateTags).toEqual(updateVariableTags(toVariablePayload(variable, tagsMetrics))); |
|
|
|
expect(setOption).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
expect(setOption).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
|
|
|
|
|
|
|
@ -436,6 +446,7 @@ describe('query actions', () => { |
|
|
|
.whenAsyncActionIsDispatched(changeQueryVariableQuery(toVariablePayload(variable), query, definition), true); |
|
|
|
.whenAsyncActionIsDispatched(changeQueryVariableQuery(toVariablePayload(variable), query, definition), true); |
|
|
|
|
|
|
|
|
|
|
|
const option = createOption(ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE); |
|
|
|
const option = createOption(ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE); |
|
|
|
|
|
|
|
const update = { results: optionsMetrics, templatedRegex: '' }; |
|
|
|
|
|
|
|
|
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
const [clearError, changeQuery, changeDefinition, updateOptions, setOption] = actions; |
|
|
|
const [clearError, changeQuery, changeDefinition, updateOptions, setOption] = actions; |
|
|
@ -448,7 +459,7 @@ describe('query actions', () => { |
|
|
|
expect(changeDefinition).toEqual( |
|
|
|
expect(changeDefinition).toEqual( |
|
|
|
changeVariableProp(toVariablePayload(variable, { propName: 'definition', propValue: definition })) |
|
|
|
changeVariableProp(toVariablePayload(variable, { propName: 'definition', propValue: definition })) |
|
|
|
); |
|
|
|
); |
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, optionsMetrics))); |
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, update))); |
|
|
|
expect(setOption).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
expect(setOption).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
|
|
|
|
|
|
|
|
return actions.length === expectedNumberOfActions; |
|
|
|
return actions.length === expectedNumberOfActions; |
|
|
@ -471,6 +482,7 @@ describe('query actions', () => { |
|
|
|
.whenAsyncActionIsDispatched(changeQueryVariableQuery(toVariablePayload(variable), query, definition), true); |
|
|
|
.whenAsyncActionIsDispatched(changeQueryVariableQuery(toVariablePayload(variable), query, definition), true); |
|
|
|
|
|
|
|
|
|
|
|
const option = createOption('A'); |
|
|
|
const option = createOption('A'); |
|
|
|
|
|
|
|
const update = { results: optionsMetrics, templatedRegex: '' }; |
|
|
|
|
|
|
|
|
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
tester.thenDispatchedActionsPredicateShouldEqual(actions => { |
|
|
|
const [clearError, changeQuery, changeDefinition, updateOptions, setOption] = actions; |
|
|
|
const [clearError, changeQuery, changeDefinition, updateOptions, setOption] = actions; |
|
|
@ -483,7 +495,7 @@ describe('query actions', () => { |
|
|
|
expect(changeDefinition).toEqual( |
|
|
|
expect(changeDefinition).toEqual( |
|
|
|
changeVariableProp(toVariablePayload(variable, { propName: 'definition', propValue: definition })) |
|
|
|
changeVariableProp(toVariablePayload(variable, { propName: 'definition', propValue: definition })) |
|
|
|
); |
|
|
|
); |
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, optionsMetrics))); |
|
|
|
expect(updateOptions).toEqual(updateVariableOptions(toVariablePayload(variable, update))); |
|
|
|
expect(setOption).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
expect(setOption).toEqual(setCurrentVariableValue(toVariablePayload(variable, { option }))); |
|
|
|
|
|
|
|
|
|
|
|
return actions.length === expectedNumberOfActions; |
|
|
|
return actions.length === expectedNumberOfActions; |
|
|
@ -559,14 +571,13 @@ function createOption(text: string, value?: string) { |
|
|
|
const metric = createMetric(text); |
|
|
|
const metric = createMetric(text); |
|
|
|
return { |
|
|
|
return { |
|
|
|
...metric, |
|
|
|
...metric, |
|
|
|
value: value ?? metric.value, |
|
|
|
value: value ?? metric.text, |
|
|
|
selected: false, |
|
|
|
selected: false, |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function createMetric(value: string) { |
|
|
|
function createMetric(value: string) { |
|
|
|
return { |
|
|
|
return { |
|
|
|
value: value, |
|
|
|
|
|
|
|
text: value, |
|
|
|
text: value, |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|