Commit 9d870883 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'no-mocked-methods-dashboard' into 'master'

Remove mocked methods from dashboard spec

See merge request gitlab-org/gitlab!30486
parents d58353db 98932622
...@@ -11,6 +11,7 @@ import Dashboard from '~/monitoring/components/dashboard.vue'; ...@@ -11,6 +11,7 @@ import Dashboard from '~/monitoring/components/dashboard.vue';
import DateTimePicker from '~/vue_shared/components/date_time_picker/date_time_picker.vue'; import DateTimePicker from '~/vue_shared/components/date_time_picker/date_time_picker.vue';
import CustomMetricsFormFields from '~/custom_metrics/components/custom_metrics_form_fields.vue'; import CustomMetricsFormFields from '~/custom_metrics/components/custom_metrics_form_fields.vue';
import DashboardsDropdown from '~/monitoring/components/dashboards_dropdown.vue'; import DashboardsDropdown from '~/monitoring/components/dashboards_dropdown.vue';
import EmptyState from '~/monitoring/components/empty_state.vue';
import GroupEmptyState from '~/monitoring/components/group_empty_state.vue'; import GroupEmptyState from '~/monitoring/components/group_empty_state.vue';
import DashboardPanel from '~/monitoring/components/dashboard_panel.vue'; import DashboardPanel from '~/monitoring/components/dashboard_panel.vue';
import { createStore } from '~/monitoring/stores'; import { createStore } from '~/monitoring/stores';
...@@ -33,9 +34,6 @@ describe('Dashboard', () => { ...@@ -33,9 +34,6 @@ describe('Dashboard', () => {
const createShallowWrapper = (props = {}, options = {}) => { const createShallowWrapper = (props = {}, options = {}) => {
wrapper = shallowMount(Dashboard, { wrapper = shallowMount(Dashboard, {
propsData: { ...propsData, ...props }, propsData: { ...propsData, ...props },
methods: {
fetchData: jest.fn(),
},
store, store,
...options, ...options,
}); });
...@@ -44,9 +42,6 @@ describe('Dashboard', () => { ...@@ -44,9 +42,6 @@ describe('Dashboard', () => {
const createMountedWrapper = (props = {}, options = {}) => { const createMountedWrapper = (props = {}, options = {}) => {
wrapper = mount(Dashboard, { wrapper = mount(Dashboard, {
propsData: { ...propsData, ...props }, propsData: { ...propsData, ...props },
methods: {
fetchData: jest.fn(),
},
store, store,
stubs: ['graph-group', 'dashboard-panel'], stubs: ['graph-group', 'dashboard-panel'],
...options, ...options,
...@@ -56,14 +51,14 @@ describe('Dashboard', () => { ...@@ -56,14 +51,14 @@ describe('Dashboard', () => {
beforeEach(() => { beforeEach(() => {
store = createStore(); store = createStore();
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
jest.spyOn(store, 'dispatch').mockResolvedValue();
}); });
afterEach(() => { afterEach(() => {
if (wrapper) {
wrapper.destroy();
wrapper = null;
}
mock.restore(); mock.restore();
if (store.dispatch.mockReset) {
store.dispatch.mockReset();
}
}); });
describe('no metrics are available yet', () => { describe('no metrics are available yet', () => {
...@@ -104,9 +99,7 @@ describe('Dashboard', () => { ...@@ -104,9 +99,7 @@ describe('Dashboard', () => {
describe('request information to the server', () => { describe('request information to the server', () => {
it('calls to set time range and fetch data', () => { it('calls to set time range and fetch data', () => {
jest.spyOn(store, 'dispatch'); createShallowWrapper({ hasMetrics: true });
createShallowWrapper({ hasMetrics: true }, { methods: {} });
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(store.dispatch).toHaveBeenCalledWith( expect(store.dispatch).toHaveBeenCalledWith(
...@@ -119,10 +112,13 @@ describe('Dashboard', () => { ...@@ -119,10 +112,13 @@ describe('Dashboard', () => {
}); });
it('shows up a loading state', () => { it('shows up a loading state', () => {
createShallowWrapper({ hasMetrics: true }, { methods: {} }); store.state.monitoringDashboard.emptyState = 'loading';
createShallowWrapper({ hasMetrics: true });
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(wrapper.vm.emptyState).toEqual('loading'); expect(wrapper.find(EmptyState).exists()).toBe(true);
expect(wrapper.find(EmptyState).props('selectedState')).toBe('loading');
}); });
}); });
...@@ -254,6 +250,10 @@ describe('Dashboard', () => { ...@@ -254,6 +250,10 @@ describe('Dashboard', () => {
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
afterEach(() => {
wrapper.destroy();
});
it('renders a search input', () => { it('renders a search input', () => {
expect(wrapper.find({ ref: 'monitorEnvironmentsDropdownSearch' }).exists()).toBe(true); expect(wrapper.find({ ref: 'monitorEnvironmentsDropdownSearch' }).exists()).toBe(true);
}); });
...@@ -322,8 +322,10 @@ describe('Dashboard', () => { ...@@ -322,8 +322,10 @@ describe('Dashboard', () => {
const findRearrangeButton = () => wrapper.find('.js-rearrange-button'); const findRearrangeButton = () => wrapper.find('.js-rearrange-button');
beforeEach(() => { beforeEach(() => {
createShallowWrapper({ hasMetrics: true }); // call original dispatch
store.dispatch.mockRestore();
createShallowWrapper({ hasMetrics: true });
setupStoreWithData(wrapper.vm.$store); setupStoreWithData(wrapper.vm.$store);
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
......
...@@ -18,21 +18,11 @@ describe('Dashboard template', () => { ...@@ -18,21 +18,11 @@ describe('Dashboard template', () => {
}); });
afterEach(() => { afterEach(() => {
if (wrapper) {
wrapper.destroy();
wrapper = null;
}
mock.restore(); mock.restore();
}); });
it('matches the default snapshot', () => { it('matches the default snapshot', () => {
wrapper = shallowMount(Dashboard, { wrapper = shallowMount(Dashboard, { propsData: { ...propsData }, store });
propsData: { ...propsData },
methods: {
fetchData: jest.fn(),
},
store,
});
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment