diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-31 12:08:16 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-31 12:08:16 +0300 |
commit | 6044caed20964a70c1ac6c5a3365d567ed96dfde (patch) | |
tree | 3fe8f14b4acbd542265544843efeb6f59b5d3efe /spec/frontend/monitoring/components/embeds/metric_embed_spec.js | |
parent | 92077e0f8d70c70a908395808b16f98ecd3a5fcd (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/monitoring/components/embeds/metric_embed_spec.js')
-rw-r--r-- | spec/frontend/monitoring/components/embeds/metric_embed_spec.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/spec/frontend/monitoring/components/embeds/metric_embed_spec.js b/spec/frontend/monitoring/components/embeds/metric_embed_spec.js new file mode 100644 index 00000000000..d0fe22cefec --- /dev/null +++ b/spec/frontend/monitoring/components/embeds/metric_embed_spec.js @@ -0,0 +1,102 @@ +import { createLocalVue, shallowMount } from '@vue/test-utils'; +import Vuex from 'vuex'; +import PanelType from 'ee_else_ce/monitoring/components/panel_type.vue'; +import { TEST_HOST } from 'helpers/test_constants'; +import MetricEmbed from '~/monitoring/components/embeds/metric_embed.vue'; +import { groups, initialState, metricsData, metricsWithData } from './mock_data'; + +const localVue = createLocalVue(); +localVue.use(Vuex); + +describe('MetricEmbed', () => { + let wrapper; + let store; + let actions; + let metricsWithDataGetter; + + function mountComponent() { + wrapper = shallowMount(MetricEmbed, { + localVue, + store, + propsData: { + dashboardUrl: TEST_HOST, + }, + }); + } + + beforeEach(() => { + actions = { + setFeatureFlags: jest.fn(), + setShowErrorBanner: jest.fn(), + setEndpoints: jest.fn(), + setTimeRange: jest.fn(), + fetchDashboard: jest.fn(), + }; + + metricsWithDataGetter = jest.fn(); + + store = new Vuex.Store({ + modules: { + monitoringDashboard: { + namespaced: true, + actions, + getters: { + metricsWithData: () => metricsWithDataGetter, + }, + state: initialState, + }, + }, + }); + }); + + afterEach(() => { + metricsWithDataGetter.mockClear(); + if (wrapper) { + wrapper.destroy(); + } + }); + + describe('no metrics are available yet', () => { + beforeEach(() => { + mountComponent(); + }); + + it('shows an empty state when no metrics are present', () => { + expect(wrapper.find('.metrics-embed').exists()).toBe(true); + expect(wrapper.find(PanelType).exists()).toBe(false); + }); + }); + + describe('metrics are available', () => { + beforeEach(() => { + store.state.monitoringDashboard.dashboard.panelGroups = groups; + store.state.monitoringDashboard.dashboard.panelGroups[0].panels = metricsData; + + metricsWithDataGetter.mockReturnValue(metricsWithData); + + mountComponent(); + }); + + it('calls actions to fetch data', () => { + const expectedTimeRangePayload = expect.objectContaining({ + start: expect.any(String), + end: expect.any(String), + }); + + expect(actions.setTimeRange).toHaveBeenCalledTimes(1); + expect(actions.setTimeRange.mock.calls[0][1]).toEqual(expectedTimeRangePayload); + + expect(actions.fetchDashboard).toHaveBeenCalled(); + }); + + it('shows a chart when metrics are present', () => { + expect(wrapper.find('.metrics-embed').exists()).toBe(true); + expect(wrapper.find(PanelType).exists()).toBe(true); + expect(wrapper.findAll(PanelType).length).toBe(2); + }); + + it('includes groupId with dashboardUrl', () => { + expect(wrapper.find(PanelType).props('groupId')).toBe(TEST_HOST); + }); + }); +}); |