Commit f9b922f0 authored by Miguel Rincon's avatar Miguel Rincon

Move dashboard dropdown specs to the right file

After creating the dashboard header, the specs where not moved,
this MR addresses moving part of them by moving the dashboard dropdown
specs.
parent ff861e9b
......@@ -3,6 +3,7 @@ import { createStore } from '~/monitoring/stores';
import * as types from '~/monitoring/stores/mutation_types';
import { GlDeprecatedDropdownItem, GlSearchBoxByType, GlLoadingIcon } from '@gitlab/ui';
import DashboardHeader from '~/monitoring/components/dashboard_header.vue';
import DashboardsDropdown from '~/monitoring/components/dashboards_dropdown.vue';
import DuplicateDashboardModal from '~/monitoring/components/duplicate_dashboard_modal.vue';
import CreateDashboardModal from '~/monitoring/components/create_dashboard_modal.vue';
import { setupAllDashboards, setupStoreWithDashboard, setupStoreWithData } from '../store_utils';
......@@ -26,6 +27,8 @@ describe('Dashboard header', () => {
let store;
let wrapper;
const findDashboardDropdown = () => wrapper.find(DashboardsDropdown);
const findEnvsDropdown = () => wrapper.find({ ref: 'monitorEnvironmentsDropdown' });
const findEnvsDropdownItems = () => findEnvsDropdown().findAll(GlDeprecatedDropdownItem);
const findEnvsDropdownSearch = () => findEnvsDropdown().find(GlSearchBoxByType);
......@@ -60,6 +63,41 @@ describe('Dashboard header', () => {
wrapper.destroy();
});
describe('dashboards dropdown', () => {
beforeEach(() => {
store.commit(`monitoringDashboard/${types.SET_INITIAL_STATE}`, {
projectPath: mockProjectPath,
});
createShallowWrapper();
});
it('shows the dashboard dropdown', () => {
expect(findDashboardDropdown().exists()).toBe(true);
});
it('when an out of the box dashboard is selected, encodes dashboard path', () => {
findDashboardDropdown().vm.$emit('selectDashboard', {
path: '.gitlab/dashboards/dashboard&copy.yml',
out_of_the_box_dashboard: true,
display_name: 'A display name',
});
expect(redirectTo).toHaveBeenCalledWith(
`${mockProjectPath}/-/metrics/.gitlab%2Fdashboards%2Fdashboard%26copy.yml`,
);
});
it('when a custom dashboard is selected, encodes dashboard display name', () => {
findDashboardDropdown().vm.$emit('selectDashboard', {
path: '.gitlab/dashboards/file&path.yml',
display_name: 'dashboard&copy.yml',
});
expect(redirectTo).toHaveBeenCalledWith(`${mockProjectPath}/-/metrics/dashboard%26copy.yml`);
});
});
describe('environments dropdown', () => {
beforeEach(() => {
createShallowWrapper();
......
......@@ -13,7 +13,6 @@ import DashboardHeader from '~/monitoring/components/dashboard_header.vue';
import RefreshButton from '~/monitoring/components/refresh_button.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 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 DashboardPanel from '~/monitoring/components/dashboard_panel.vue';
......@@ -396,37 +395,6 @@ describe('Dashboard', () => {
);
});
});
describe('when custom dashboard is selected', () => {
const windowLocation = window.location;
const findDashboardDropdown = () => wrapper.find(DashboardHeader).find(DashboardsDropdown);
beforeEach(() => {
store.commit(`monitoringDashboard/${types.SET_INITIAL_STATE}`, {
projectPath: TEST_HOST,
});
delete window.location;
window.location = { ...windowLocation, assign: jest.fn() };
createMountedWrapper();
return wrapper.vm.$nextTick();
});
afterEach(() => {
window.location = windowLocation;
});
it('encodes dashboard param', () => {
findDashboardDropdown().vm.$emit('selectDashboard', {
path: '.gitlab/dashboards/dashboard&copy.yml',
display_name: 'dashboard&copy.yml',
});
expect(window.location.assign).toHaveBeenCalledWith(
`${TEST_HOST}/-/metrics/dashboard%26copy.yml`,
);
});
});
});
describe('when all panels in the first group are loading', () => {
......@@ -991,20 +959,6 @@ describe('Dashboard', () => {
});
});
describe('Dashboard dropdown', () => {
beforeEach(() => {
createMountedWrapper({ hasMetrics: true });
setupAllDashboards(store);
return wrapper.vm.$nextTick();
});
it('shows the dashboard dropdown', () => {
const dashboardDropdown = wrapper.find(DashboardsDropdown);
expect(dashboardDropdown.exists()).toBe(true);
});
});
describe('external dashboard link', () => {
beforeEach(() => {
createMountedWrapper({
......
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