diff options
Diffstat (limited to 'spec/frontend/monitoring/store')
-rw-r--r-- | spec/frontend/monitoring/store/actions_spec.js | 116 | ||||
-rw-r--r-- | spec/frontend/monitoring/store/getters_spec.js | 40 | ||||
-rw-r--r-- | spec/frontend/monitoring/store/index_spec.js | 23 | ||||
-rw-r--r-- | spec/frontend/monitoring/store/mutations_spec.js | 26 | ||||
-rw-r--r-- | spec/frontend/monitoring/store/utils_spec.js | 188 | ||||
-rw-r--r-- | spec/frontend/monitoring/store/variable_mapping_spec.js | 27 |
6 files changed, 313 insertions, 107 deletions
diff --git a/spec/frontend/monitoring/store/actions_spec.js b/spec/frontend/monitoring/store/actions_spec.js index 8914f2e66ea..d0290386f12 100644 --- a/spec/frontend/monitoring/store/actions_spec.js +++ b/spec/frontend/monitoring/store/actions_spec.js @@ -8,7 +8,7 @@ import createFlash from '~/flash'; import { defaultTimeRange } from '~/vue_shared/constants'; import { ENVIRONMENT_AVAILABLE_STATE } from '~/monitoring/constants'; -import store from '~/monitoring/stores'; +import { createStore } from '~/monitoring/stores'; import * as types from '~/monitoring/stores/mutation_types'; import { fetchData, @@ -26,7 +26,7 @@ import { clearExpandedPanel, setGettingStartedEmptyState, duplicateSystemDashboard, - updateVariableValues, + updateVariablesAndFetchData, } from '~/monitoring/stores/actions'; import { gqClient, @@ -52,20 +52,16 @@ import { jest.mock('~/flash'); -const resetStore = str => { - str.replaceState({ - showEmptyState: true, - emptyState: 'loading', - groups: [], - }); -}; - describe('Monitoring store actions', () => { const { convertObjectPropsToCamelCase } = commonUtils; let mock; + let store; + let state; beforeEach(() => { + store = createStore(); + state = store.state.monitoringDashboard; mock = new MockAdapter(axios); jest.spyOn(commonUtils, 'backOff').mockImplementation(callback => { @@ -83,7 +79,6 @@ describe('Monitoring store actions', () => { }); }); afterEach(() => { - resetStore(store); mock.reset(); commonUtils.backOff.mockReset(); @@ -92,8 +87,6 @@ describe('Monitoring store actions', () => { describe('fetchData', () => { it('dispatches fetchEnvironmentsData and fetchEnvironmentsData', () => { - const { state } = store; - return testAction( fetchData, null, @@ -111,8 +104,6 @@ describe('Monitoring store actions', () => { const origGon = window.gon; window.gon = { features: { metricsDashboardAnnotations: true } }; - const { state } = store; - return testAction( fetchData, null, @@ -131,7 +122,6 @@ describe('Monitoring store actions', () => { describe('fetchDeploymentsData', () => { it('dispatches receiveDeploymentsDataSuccess on success', () => { - const { state } = store; state.deploymentsEndpoint = '/success'; mock.onGet(state.deploymentsEndpoint).reply(200, { deployments: deploymentData, @@ -146,7 +136,6 @@ describe('Monitoring store actions', () => { ); }); it('dispatches receiveDeploymentsDataFailure on error', () => { - const { state } = store; state.deploymentsEndpoint = '/error'; mock.onGet(state.deploymentsEndpoint).reply(500); @@ -164,11 +153,8 @@ describe('Monitoring store actions', () => { }); describe('fetchEnvironmentsData', () => { - const { state } = store; - state.projectPath = 'gitlab-org/gitlab-test'; - - afterEach(() => { - resetStore(store); + beforeEach(() => { + state.projectPath = 'gitlab-org/gitlab-test'; }); it('setting SET_ENVIRONMENTS_FILTER should dispatch fetchEnvironmentsData', () => { @@ -269,17 +255,14 @@ describe('Monitoring store actions', () => { }); describe('fetchAnnotations', () => { - const { state } = store; - state.timeRange = { - start: '2020-04-15T12:54:32.137Z', - end: '2020-08-15T12:54:32.137Z', - }; - state.projectPath = 'gitlab-org/gitlab-test'; - state.currentEnvironmentName = 'production'; - state.currentDashboard = '.gitlab/dashboards/custom_dashboard.yml'; - - afterEach(() => { - resetStore(store); + beforeEach(() => { + state.timeRange = { + start: '2020-04-15T12:54:32.137Z', + end: '2020-08-15T12:54:32.137Z', + }; + state.projectPath = 'gitlab-org/gitlab-test'; + state.currentEnvironmentName = 'production'; + state.currentDashboard = '.gitlab/dashboards/custom_dashboard.yml'; }); it('fetches annotations data and dispatches receiveAnnotationsSuccess', () => { @@ -353,7 +336,6 @@ describe('Monitoring store actions', () => { }); describe('Toggles starred value of current dashboard', () => { - const { state } = store; let unstarredDashboard; let starredDashboard; @@ -379,7 +361,13 @@ describe('Monitoring store actions', () => { return testAction(toggleStarredValue, null, state, [ { type: types.REQUEST_DASHBOARD_STARRING }, - { type: types.RECEIVE_DASHBOARD_STARRING_SUCCESS, payload: true }, + { + type: types.RECEIVE_DASHBOARD_STARRING_SUCCESS, + payload: { + newStarredValue: true, + selectedDashboard: unstarredDashboard, + }, + }, ]); }); @@ -396,23 +384,19 @@ describe('Monitoring store actions', () => { }); describe('Set initial state', () => { - let mockedState; - beforeEach(() => { - mockedState = storeState(); - }); it('should commit SET_INITIAL_STATE mutation', done => { testAction( setInitialState, { - metricsEndpoint: 'additional_metrics.json', + currentDashboard: '.gitlab/dashboards/dashboard.yml', deploymentsEndpoint: 'deployments.json', }, - mockedState, + state, [ { type: types.SET_INITIAL_STATE, payload: { - metricsEndpoint: 'additional_metrics.json', + currentDashboard: '.gitlab/dashboards/dashboard.yml', deploymentsEndpoint: 'deployments.json', }, }, @@ -423,15 +407,11 @@ describe('Monitoring store actions', () => { }); }); describe('Set empty states', () => { - let mockedState; - beforeEach(() => { - mockedState = storeState(); - }); it('should commit SET_METRICS_ENDPOINT mutation', done => { testAction( setGettingStartedEmptyState, null, - mockedState, + state, [ { type: types.SET_GETTING_STARTED_EMPTY_STATE, @@ -443,23 +423,23 @@ describe('Monitoring store actions', () => { }); }); - describe('updateVariableValues', () => { - let mockedState; - beforeEach(() => { - mockedState = storeState(); - }); - it('should commit UPDATE_VARIABLE_VALUES mutation', done => { + describe('updateVariablesAndFetchData', () => { + it('should commit UPDATE_VARIABLES mutation and fetch data', done => { testAction( - updateVariableValues, + updateVariablesAndFetchData, { pod: 'POD' }, - mockedState, + state, [ { - type: types.UPDATE_VARIABLE_VALUES, + type: types.UPDATE_VARIABLES, payload: { pod: 'POD' }, }, ], - [], + [ + { + type: 'fetchDashboardData', + }, + ], done, ); }); @@ -467,13 +447,11 @@ describe('Monitoring store actions', () => { describe('fetchDashboard', () => { let dispatch; - let state; let commit; const response = metricsDashboardResponse; beforeEach(() => { dispatch = jest.fn(); commit = jest.fn(); - state = storeState(); state.dashboardEndpoint = '/dashboard'; }); @@ -557,12 +535,10 @@ describe('Monitoring store actions', () => { describe('receiveMetricsDashboardSuccess', () => { let commit; let dispatch; - let state; beforeEach(() => { commit = jest.fn(); dispatch = jest.fn(); - state = storeState(); }); it('stores groups', () => { @@ -623,13 +599,11 @@ describe('Monitoring store actions', () => { describe('fetchDashboardData', () => { let commit; let dispatch; - let state; beforeEach(() => { jest.spyOn(Tracking, 'event'); commit = jest.fn(); dispatch = jest.fn(); - state = storeState(); state.timeRange = defaultTimeRange; }); @@ -731,7 +705,6 @@ describe('Monitoring store actions', () => { step: 60, }; let metric; - let state; let data; let prometheusEndpointPath; @@ -929,10 +902,7 @@ describe('Monitoring store actions', () => { }); describe('duplicateSystemDashboard', () => { - let state; - beforeEach(() => { - state = storeState(); state.dashboardsEndpoint = '/dashboards.json'; }); @@ -1010,12 +980,6 @@ describe('Monitoring store actions', () => { }); describe('setExpandedPanel', () => { - let state; - - beforeEach(() => { - state = storeState(); - }); - it('Sets a panel as expanded', () => { const group = 'group_1'; const panel = { title: 'A Panel' }; @@ -1031,12 +995,6 @@ describe('Monitoring store actions', () => { }); describe('clearExpandedPanel', () => { - let state; - - beforeEach(() => { - state = storeState(); - }); - it('Clears a panel as expanded', () => { return testAction( clearExpandedPanel, diff --git a/spec/frontend/monitoring/store/getters_spec.js b/spec/frontend/monitoring/store/getters_spec.js index 19ca001c281..933ccb1e46c 100644 --- a/spec/frontend/monitoring/store/getters_spec.js +++ b/spec/frontend/monitoring/store/getters_spec.js @@ -8,6 +8,7 @@ import { metricsResult, dashboardGitResponse, mockTemplatingDataResponses, + mockLinks, } from '../mock_data'; import { metricsDashboardPayload, @@ -334,11 +335,11 @@ describe('Monitoring store Getters', () => { beforeEach(() => { state = { - promVariables: {}, + variables: {}, }; }); - it('transforms the promVariables object to an array in the [variable, variable_value] format for all variable types', () => { + it('transforms the variables object to an array in the [variable, variable_value] format for all variable types', () => { mutations[types.SET_VARIABLES](state, mockTemplatingDataResponses.allVariableTypes); const variablesArray = getters.getCustomVariablesParams(state); @@ -350,7 +351,7 @@ describe('Monitoring store Getters', () => { }); }); - it('transforms the promVariables object to an empty array when no keys are present', () => { + it('transforms the variables object to an empty array when no keys are present', () => { mutations[types.SET_VARIABLES](state, {}); const variablesArray = getters.getCustomVariablesParams(state); @@ -401,4 +402,37 @@ describe('Monitoring store Getters', () => { expect(selectedDashboard(state)).toEqual(null); }); }); + + describe('linksWithMetadata', () => { + let state; + const setupState = (initState = {}) => { + state = { + ...state, + ...initState, + }; + }; + + beforeAll(() => { + setupState({ + links: mockLinks, + }); + }); + + afterAll(() => { + state = null; + }); + + it.each` + timeRange | output + ${{}} | ${''} + ${{ start: '2020-01-01T00:00:00.000Z', end: '2020-01-31T23:59:00.000Z' }} | ${'start=2020-01-01T00%3A00%3A00.000Z&end=2020-01-31T23%3A59%3A00.000Z'} + ${{ duration: { seconds: 86400 } }} | ${'duration_seconds=86400'} + `('linksWithMetadata returns URLs with time range', ({ timeRange, output }) => { + setupState({ timeRange }); + const links = getters.linksWithMetadata(state); + links.forEach(({ url }) => { + expect(url).toMatch(output); + }); + }); + }); }); diff --git a/spec/frontend/monitoring/store/index_spec.js b/spec/frontend/monitoring/store/index_spec.js new file mode 100644 index 00000000000..4184687eec8 --- /dev/null +++ b/spec/frontend/monitoring/store/index_spec.js @@ -0,0 +1,23 @@ +import { createStore } from '~/monitoring/stores'; + +describe('Monitoring Store Index', () => { + it('creates store with a `monitoringDashboard` namespace', () => { + expect(createStore().state).toEqual({ + monitoringDashboard: expect.any(Object), + }); + }); + + it('creates store with initial values', () => { + const defaults = { + deploymentsEndpoint: '/mock/deployments', + dashboardEndpoint: '/mock/dashboard', + dashboardsEndpoint: '/mock/dashboards', + }; + + const { state } = createStore(defaults); + + expect(state).toEqual({ + monitoringDashboard: expect.objectContaining(defaults), + }); + }); +}); diff --git a/spec/frontend/monitoring/store/mutations_spec.js b/spec/frontend/monitoring/store/mutations_spec.js index 4306243689a..0283f1a86a4 100644 --- a/spec/frontend/monitoring/store/mutations_spec.js +++ b/spec/frontend/monitoring/store/mutations_spec.js @@ -93,14 +93,20 @@ describe('Monitoring mutations', () => { }); it('sets a dashboard as starred', () => { - mutations[types.RECEIVE_DASHBOARD_STARRING_SUCCESS](stateCopy, true); + mutations[types.RECEIVE_DASHBOARD_STARRING_SUCCESS](stateCopy, { + selectedDashboard: stateCopy.allDashboards[1], + newStarredValue: true, + }); expect(stateCopy.isUpdatingStarredValue).toBe(false); expect(stateCopy.allDashboards[1].starred).toBe(true); }); it('sets a dashboard as unstarred', () => { - mutations[types.RECEIVE_DASHBOARD_STARRING_SUCCESS](stateCopy, false); + mutations[types.RECEIVE_DASHBOARD_STARRING_SUCCESS](stateCopy, { + selectedDashboard: stateCopy.allDashboards[1], + newStarredValue: false, + }); expect(stateCopy.isUpdatingStarredValue).toBe(false); expect(stateCopy.allDashboards[1].starred).toBe(false); @@ -128,13 +134,11 @@ describe('Monitoring mutations', () => { describe('SET_INITIAL_STATE', () => { it('should set all the endpoints', () => { mutations[types.SET_INITIAL_STATE](stateCopy, { - metricsEndpoint: 'additional_metrics.json', deploymentsEndpoint: 'deployments.json', dashboardEndpoint: 'dashboard.json', projectPath: '/gitlab-org/gitlab-foss', currentEnvironmentName: 'production', }); - expect(stateCopy.metricsEndpoint).toEqual('additional_metrics.json'); expect(stateCopy.deploymentsEndpoint).toEqual('deployments.json'); expect(stateCopy.dashboardEndpoint).toEqual('dashboard.json'); expect(stateCopy.projectPath).toEqual('/gitlab-org/gitlab-foss'); @@ -179,12 +183,10 @@ describe('Monitoring mutations', () => { describe('SET_ENDPOINTS', () => { it('should set all the endpoints', () => { mutations[types.SET_ENDPOINTS](stateCopy, { - metricsEndpoint: 'additional_metrics.json', deploymentsEndpoint: 'deployments.json', dashboardEndpoint: 'dashboard.json', projectPath: '/gitlab-org/gitlab-foss', }); - expect(stateCopy.metricsEndpoint).toEqual('additional_metrics.json'); expect(stateCopy.deploymentsEndpoint).toEqual('deployments.json'); expect(stateCopy.dashboardEndpoint).toEqual('dashboard.json'); expect(stateCopy.projectPath).toEqual('/gitlab-org/gitlab-foss'); @@ -412,26 +414,26 @@ describe('Monitoring mutations', () => { it('stores an empty variables array when no custom variables are given', () => { mutations[types.SET_VARIABLES](stateCopy, {}); - expect(stateCopy.promVariables).toEqual({}); + expect(stateCopy.variables).toEqual({}); }); it('stores variables in the key key_value format in the array', () => { mutations[types.SET_VARIABLES](stateCopy, { pod: 'POD', stage: 'main ops' }); - expect(stateCopy.promVariables).toEqual({ pod: 'POD', stage: 'main ops' }); + expect(stateCopy.variables).toEqual({ pod: 'POD', stage: 'main ops' }); }); }); - describe('UPDATE_VARIABLE_VALUES', () => { + describe('UPDATE_VARIABLES', () => { afterEach(() => { mutations[types.SET_VARIABLES](stateCopy, {}); }); - it('updates only the value of the variable in promVariables', () => { + it('updates only the value of the variable in variables', () => { mutations[types.SET_VARIABLES](stateCopy, { environment: { value: 'prod', type: 'text' } }); - mutations[types.UPDATE_VARIABLE_VALUES](stateCopy, { key: 'environment', value: 'new prod' }); + mutations[types.UPDATE_VARIABLES](stateCopy, { key: 'environment', value: 'new prod' }); - expect(stateCopy.promVariables).toEqual({ environment: { value: 'new prod', type: 'text' } }); + expect(stateCopy.variables).toEqual({ environment: { value: 'new prod', type: 'text' } }); }); }); }); diff --git a/spec/frontend/monitoring/store/utils_spec.js b/spec/frontend/monitoring/store/utils_spec.js index fe5754e1216..3a70bda51da 100644 --- a/spec/frontend/monitoring/store/utils_spec.js +++ b/spec/frontend/monitoring/store/utils_spec.js @@ -5,6 +5,9 @@ import { parseAnnotationsResponse, removeLeadingSlash, mapToDashboardViewModel, + normalizeQueryResult, + convertToGrafanaTimeRange, + addDashboardMetaDataToLink, } from '~/monitoring/stores/utils'; import { annotationsData } from '../mock_data'; import { NOT_IN_DB_PREFIX } from '~/monitoring/constants'; @@ -16,6 +19,8 @@ describe('mapToDashboardViewModel', () => { expect(mapToDashboardViewModel({})).toEqual({ dashboard: '', panelGroups: [], + links: [], + variables: {}, }); }); @@ -44,6 +49,8 @@ describe('mapToDashboardViewModel', () => { expect(mapToDashboardViewModel(response)).toEqual({ dashboard: 'Dashboard Name', + links: [], + variables: {}, panelGroups: [ { group: 'Group 1', @@ -63,6 +70,7 @@ describe('mapToDashboardViewModel', () => { format: 'engineering', precision: 2, }, + links: [], metrics: [], }, ], @@ -75,6 +83,8 @@ describe('mapToDashboardViewModel', () => { it('key', () => { const response = { dashboard: 'Dashboard Name', + links: [], + variables: {}, panel_groups: [ { group: 'Group A', @@ -147,6 +157,7 @@ describe('mapToDashboardViewModel', () => { format: SUPPORTED_FORMATS.engineering, precision: 2, }, + links: [], metrics: [], }); }); @@ -170,6 +181,7 @@ describe('mapToDashboardViewModel', () => { format: SUPPORTED_FORMATS.engineering, precision: 2, }, + links: [], metrics: [], }); }); @@ -238,6 +250,77 @@ describe('mapToDashboardViewModel', () => { expect(getMappedPanel().maxValue).toBe(100); }); + + describe('panel with links', () => { + const title = 'Example'; + const url = 'https://example.com'; + + it('maps an empty link collection', () => { + setupWithPanel({ + links: undefined, + }); + + expect(getMappedPanel().links).toEqual([]); + }); + + it('maps a link', () => { + setupWithPanel({ links: [{ title, url }] }); + + expect(getMappedPanel().links).toEqual([{ title, url }]); + }); + + it('maps a link without a title', () => { + setupWithPanel({ + links: [{ url }], + }); + + expect(getMappedPanel().links).toEqual([{ title: url, url }]); + }); + + it('maps a link without a url', () => { + setupWithPanel({ + links: [{ title }], + }); + + expect(getMappedPanel().links).toEqual([{ title, url: '#' }]); + }); + + it('maps a link without a url or title', () => { + setupWithPanel({ + links: [{}], + }); + + expect(getMappedPanel().links).toEqual([{ title: 'null', url: '#' }]); + }); + + it('maps a link with an unsafe url safely', () => { + // eslint-disable-next-line no-script-url + const unsafeUrl = 'javascript:alert("XSS")'; + + setupWithPanel({ + links: [ + { + title, + url: unsafeUrl, + }, + ], + }); + + expect(getMappedPanel().links).toEqual([{ title, url: '#' }]); + }); + + it('maps multple links', () => { + setupWithPanel({ + links: [{ title, url }, { url }, { title }], + }); + + expect(getMappedPanel().links).toEqual([ + { title, url }, + { title: url, url }, + { title, url: '#' }, + ]); + }); + }); }); describe('metrics mapping', () => { @@ -317,6 +400,28 @@ describe('mapToDashboardViewModel', () => { }); }); +describe('normalizeQueryResult', () => { + const testData = { + metric: { + __name__: 'up', + job: 'prometheus', + instance: 'localhost:9090', + }, + values: [[1435781430.781, '1'], [1435781445.781, '1'], [1435781460.781, '1']], + }; + + it('processes a simple matrix result', () => { + expect(normalizeQueryResult(testData)).toEqual({ + metric: { __name__: 'up', job: 'prometheus', instance: 'localhost:9090' }, + values: [ + ['2015-07-01T20:10:30.781Z', 1], + ['2015-07-01T20:10:45.781Z', 1], + ['2015-07-01T20:11:00.781Z', 1], + ], + }); + }); +}); + describe('uniqMetricsId', () => { [ { input: { id: 1 }, expected: `${NOT_IN_DB_PREFIX}_1` }, @@ -419,3 +524,86 @@ describe('removeLeadingSlash', () => { }); }); }); + +describe('user-defined links utils', () => { + const mockRelativeTimeRange = { + metricsDashboard: { + duration: { + seconds: 86400, + }, + }, + grafana: { + from: 'now-86400s', + to: 'now', + }, + }; + const mockAbsoluteTimeRange = { + metricsDashboard: { + start: '2020-06-08T16:13:01.995Z', + end: '2020-06-08T21:12:32.243Z', + }, + grafana: { + from: 1591632781995, + to: 1591650752243, + }, + }; + describe('convertToGrafanaTimeRange', () => { + it('converts relative timezone to grafana timezone', () => { + expect(convertToGrafanaTimeRange(mockRelativeTimeRange.metricsDashboard)).toEqual( + mockRelativeTimeRange.grafana, + ); + }); + + it('converts absolute timezone to grafana timezone', () => { + expect(convertToGrafanaTimeRange(mockAbsoluteTimeRange.metricsDashboard)).toEqual( + mockAbsoluteTimeRange.grafana, + ); + }); + }); + + describe('addDashboardMetaDataToLink', () => { + const link = { title: 'title', url: 'https://gitlab.com' }; + const grafanaLink = { ...link, type: 'grafana' }; + + it('adds relative time range to link w/o type for metrics dashboards', () => { + const adder = addDashboardMetaDataToLink({ + timeRange: mockRelativeTimeRange.metricsDashboard, + }); + expect(adder(link)).toMatchObject({ + title: 'title', + url: 'https://gitlab.com?duration_seconds=86400', + }); + }); + + it('adds relative time range to Grafana type links', () => { + const adder = addDashboardMetaDataToLink({ + timeRange: mockRelativeTimeRange.metricsDashboard, + }); + expect(adder(grafanaLink)).toMatchObject({ + title: 'title', + url: 'https://gitlab.com?from=now-86400s&to=now', + }); + }); + + it('adds absolute time range to link w/o type for metrics dashboard', () => { + const adder = addDashboardMetaDataToLink({ + timeRange: mockAbsoluteTimeRange.metricsDashboard, + }); + expect(adder(link)).toMatchObject({ + title: 'title', + url: + 'https://gitlab.com?start=2020-06-08T16%3A13%3A01.995Z&end=2020-06-08T21%3A12%3A32.243Z', + }); + }); + + it('adds absolute time range to Grafana type links', () => { + const adder = addDashboardMetaDataToLink({ + timeRange: mockAbsoluteTimeRange.metricsDashboard, + }); + expect(adder(grafanaLink)).toMatchObject({ + title: 'title', + url: 'https://gitlab.com?from=1591632781995&to=1591650752243', + }); + }); + }); +}); diff --git a/spec/frontend/monitoring/store/variable_mapping_spec.js b/spec/frontend/monitoring/store/variable_mapping_spec.js index 47681ac7c65..c44bb957166 100644 --- a/spec/frontend/monitoring/store/variable_mapping_spec.js +++ b/spec/frontend/monitoring/store/variable_mapping_spec.js @@ -3,19 +3,20 @@ import { mockTemplatingData, mockTemplatingDataResponses } from '../mock_data'; describe('parseTemplatingVariables', () => { it.each` - case | input | expected - ${'Returns empty object for no dashboard input'} | ${{}} | ${{}} - ${'Returns empty object for empty dashboard input'} | ${{ dashboard: {} }} | ${{}} - ${'Returns empty object for empty templating prop'} | ${mockTemplatingData.emptyTemplatingProp} | ${{}} - ${'Returns empty object for empty variables prop'} | ${mockTemplatingData.emptyVariablesProp} | ${{}} - ${'Returns parsed object for simple text variable'} | ${mockTemplatingData.simpleText} | ${mockTemplatingDataResponses.simpleText} - ${'Returns parsed object for advanced text variable'} | ${mockTemplatingData.advText} | ${mockTemplatingDataResponses.advText} - ${'Returns parsed object for simple custom variable'} | ${mockTemplatingData.simpleCustom} | ${mockTemplatingDataResponses.simpleCustom} - ${'Returns parsed object for advanced custom variable without options'} | ${mockTemplatingData.advCustomWithoutOpts} | ${mockTemplatingDataResponses.advCustomWithoutOpts} - ${'Returns parsed object for advanced custom variable without type'} | ${mockTemplatingData.advCustomWithoutType} | ${{}} - ${'Returns parsed object for advanced custom variable without label'} | ${mockTemplatingData.advCustomWithoutLabel} | ${mockTemplatingDataResponses.advCustomWithoutLabel} - ${'Returns parsed object for simple and advanced custom variables'} | ${mockTemplatingData.simpleAndAdv} | ${mockTemplatingDataResponses.simpleAndAdv} - ${'Returns parsed object for all variable types'} | ${mockTemplatingData.allVariableTypes} | ${mockTemplatingDataResponses.allVariableTypes} + case | input | expected + ${'Returns empty object for no dashboard input'} | ${{}} | ${{}} + ${'Returns empty object for empty dashboard input'} | ${{ dashboard: {} }} | ${{}} + ${'Returns empty object for empty templating prop'} | ${mockTemplatingData.emptyTemplatingProp} | ${{}} + ${'Returns empty object for empty variables prop'} | ${mockTemplatingData.emptyVariablesProp} | ${{}} + ${'Returns parsed object for simple text variable'} | ${mockTemplatingData.simpleText} | ${mockTemplatingDataResponses.simpleText} + ${'Returns parsed object for advanced text variable'} | ${mockTemplatingData.advText} | ${mockTemplatingDataResponses.advText} + ${'Returns parsed object for simple custom variable'} | ${mockTemplatingData.simpleCustom} | ${mockTemplatingDataResponses.simpleCustom} + ${'Returns parsed object for advanced custom variable without options'} | ${mockTemplatingData.advCustomWithoutOpts} | ${mockTemplatingDataResponses.advCustomWithoutOpts} + ${'Returns parsed object for advanced custom variable for option without text'} | ${mockTemplatingData.advCustomWithoutOptText} | ${mockTemplatingDataResponses.advCustomWithoutOptText} + ${'Returns parsed object for advanced custom variable without type'} | ${mockTemplatingData.advCustomWithoutType} | ${{}} + ${'Returns parsed object for advanced custom variable without label'} | ${mockTemplatingData.advCustomWithoutLabel} | ${mockTemplatingDataResponses.advCustomWithoutLabel} + ${'Returns parsed object for simple and advanced custom variables'} | ${mockTemplatingData.simpleAndAdv} | ${mockTemplatingDataResponses.simpleAndAdv} + ${'Returns parsed object for all variable types'} | ${mockTemplatingData.allVariableTypes} | ${mockTemplatingDataResponses.allVariableTypes} `('$case', ({ input, expected }) => { expect(parseTemplatingVariables(input?.dashboard?.templating)).toEqual(expected); }); |