Commit 0bcefe43 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'xanf-vtu-v1-monitoring' into 'master'

Upgrading VTU to v1: Remove deprecated `methods` from spec/frontend/monitoring

See merge request gitlab-org/gitlab!50511
parents 29380f1b ca400cfb
import { nextTick } from 'vue';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlDropdownItem, GlIcon } from '@gitlab/ui'; import { GlDropdownItem, GlIcon } from '@gitlab/ui';
...@@ -27,7 +28,6 @@ describe('DashboardsDropdown', () => { ...@@ -27,7 +28,6 @@ describe('DashboardsDropdown', () => {
...props, ...props,
defaultBranch, defaultBranch,
}, },
sync: false,
...storeOpts, ...storeOpts,
...opts, ...opts,
}); });
...@@ -72,24 +72,22 @@ describe('DashboardsDropdown', () => { ...@@ -72,24 +72,22 @@ describe('DashboardsDropdown', () => {
expect(findNoItemsMsg().isVisible()).toBe(false); expect(findNoItemsMsg().isVisible()).toBe(false);
}); });
it('filters dropdown items when searched for item exists in the list', () => { it('filters dropdown items when searched for item exists in the list', async () => {
const searchTerm = 'Overview'; const searchTerm = 'Overview';
setSearchTerm(searchTerm); setSearchTerm(searchTerm);
await nextTick();
return wrapper.vm.$nextTick().then(() => {
expect(findItems()).toHaveLength(1); expect(findItems()).toHaveLength(1);
}); });
});
it('shows no items found message when searched for item does not exists in the list', () => { it('shows no items found message when searched for item does not exists in the list', async () => {
const searchTerm = 'does-not-exist'; const searchTerm = 'does-not-exist';
setSearchTerm(searchTerm); setSearchTerm(searchTerm);
await nextTick();
return wrapper.vm.$nextTick().then(() => {
expect(findNoItemsMsg().isVisible()).toBe(true); expect(findNoItemsMsg().isVisible()).toBe(true);
}); });
}); });
});
describe('when a dashboard is selected', () => { describe('when a dashboard is selected', () => {
beforeEach(() => { beforeEach(() => {
......
import { nextTick } from 'vue';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import DuplicateDashboardForm from '~/monitoring/components/duplicate_dashboard_form.vue'; import DuplicateDashboardForm from '~/monitoring/components/duplicate_dashboard_form.vue';
...@@ -9,7 +10,6 @@ const createMountedWrapper = (props = {}) => { ...@@ -9,7 +10,6 @@ const createMountedWrapper = (props = {}) => {
// Use `mount` to render native input elements // Use `mount` to render native input elements
wrapper = mount(DuplicateDashboardForm, { wrapper = mount(DuplicateDashboardForm, {
propsData: { ...props }, propsData: { ...props },
sync: false,
// We need to attach to document, so that `document.activeElement` is properly set in jsdom // We need to attach to document, so that `document.activeElement` is properly set in jsdom
attachToDocument: true, attachToDocument: true,
}); });
...@@ -47,34 +47,34 @@ describe('DuplicateDashboardForm', () => { ...@@ -47,34 +47,34 @@ describe('DuplicateDashboardForm', () => {
describe('validates the file name', () => { describe('validates the file name', () => {
const findInvalidFeedback = () => findByRef('fileNameFormGroup').find('.invalid-feedback'); const findInvalidFeedback = () => findByRef('fileNameFormGroup').find('.invalid-feedback');
it('when is empty', () => { it('when is empty', async () => {
setValue('fileName', ''); setValue('fileName', '');
return wrapper.vm.$nextTick(() => { await nextTick();
expect(findByRef('fileNameFormGroup').classes()).toContain('is-valid'); expect(findByRef('fileNameFormGroup').classes()).toContain('is-valid');
expect(findInvalidFeedback().exists()).toBe(false); expect(findInvalidFeedback().exists()).toBe(false);
}); });
});
it('when is valid', () => { it('when is valid', async () => {
setValue('fileName', 'my_dashboard.yml'); setValue('fileName', 'my_dashboard.yml');
return wrapper.vm.$nextTick(() => { await nextTick();
expect(findByRef('fileNameFormGroup').classes()).toContain('is-valid'); expect(findByRef('fileNameFormGroup').classes()).toContain('is-valid');
expect(findInvalidFeedback().exists()).toBe(false); expect(findInvalidFeedback().exists()).toBe(false);
}); });
});
it('when is not valid', () => { it('when is not valid', async () => {
setValue('fileName', 'my_dashboard.exe'); setValue('fileName', 'my_dashboard.exe');
return wrapper.vm.$nextTick(() => { await nextTick();
expect(findByRef('fileNameFormGroup').classes()).toContain('is-invalid'); expect(findByRef('fileNameFormGroup').classes()).toContain('is-invalid');
expect(findInvalidFeedback().text()).toBeTruthy(); expect(findInvalidFeedback().text()).toBeTruthy();
}); });
}); });
});
describe('emits `change` event', () => { describe('emits `change` event', () => {
const lastChange = () => const lastChange = () =>
wrapper.vm.$nextTick().then(() => { nextTick().then(() => {
wrapper.find('form').trigger('change'); wrapper.find('form').trigger('change');
// Resolves to the last emitted change // Resolves to the last emitted change
...@@ -133,21 +133,21 @@ describe('DuplicateDashboardForm', () => { ...@@ -133,21 +133,21 @@ describe('DuplicateDashboardForm', () => {
expect(lastChange()).resolves.toMatchObject({ expect(lastChange()).resolves.toMatchObject({
branch: defaultBranch, branch: defaultBranch,
}), }),
wrapper.vm.$nextTick(() => { nextTick(() => {
expect(findByRef('branchName').isVisible()).toBe(false); expect(findByRef('branchName').isVisible()).toBe(false);
}), }),
]); ]);
}); });
it('when `new` branch option is chosen, focuses on the branch name input', () => { it('when `new` branch option is chosen, focuses on the branch name input', async () => {
setChecked(wrapper.vm.$options.radioVals.NEW); setChecked(wrapper.vm.$options.radioVals.NEW);
return wrapper.vm.$nextTick().then(() => { await nextTick();
wrapper.find('form').trigger('change'); wrapper.find('form').trigger('change');
expect(document.activeElement).toBe(findByRef('branchName').element); expect(document.activeElement).toBe(findByRef('branchName').element);
}); });
}); });
});
}); });
describe('DuplicateDashboardForm escapes elements', () => { describe('DuplicateDashboardForm escapes elements', () => {
......
import Vuex from 'vuex';
import Vue from 'vue';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlAlert, GlLoadingIcon, GlModal } from '@gitlab/ui'; import { GlAlert, GlLoadingIcon, GlModal } from '@gitlab/ui';
...@@ -8,6 +10,8 @@ import DuplicateDashboardForm from '~/monitoring/components/duplicate_dashboard_ ...@@ -8,6 +10,8 @@ import DuplicateDashboardForm from '~/monitoring/components/duplicate_dashboard_
import { dashboardGitResponse } from '../mock_data'; import { dashboardGitResponse } from '../mock_data';
Vue.use(Vuex);
describe('duplicate dashboard modal', () => { describe('duplicate dashboard modal', () => {
let wrapper; let wrapper;
let mockDashboards; let mockDashboards;
...@@ -15,25 +19,28 @@ describe('duplicate dashboard modal', () => { ...@@ -15,25 +19,28 @@ describe('duplicate dashboard modal', () => {
let duplicateDashboardAction; let duplicateDashboardAction;
let okEvent; let okEvent;
function createComponent(opts = {}) { function createComponent() {
const storeOpts = { const store = new Vuex.Store({
methods: { modules: {
duplicateSystemDashboard: jest.fn(), monitoringDashboard: {
namespaced: true,
actions: {
duplicateSystemDashboard: duplicateDashboardAction,
}, },
computed: { getters: {
allDashboards: () => mockDashboards, allDashboards: () => mockDashboards,
selectedDashboard: () => mockSelectedDashboard, selectedDashboard: () => mockSelectedDashboard,
}, },
}; },
},
});
return shallowMount(DuplicateDashboardModal, { return shallowMount(DuplicateDashboardModal, {
propsData: { propsData: {
defaultBranch: 'master', defaultBranch: 'master',
modalId: 'id', modalId: 'id',
}, },
sync: false, store,
...storeOpts,
...opts,
}); });
} }
...@@ -51,12 +58,7 @@ describe('duplicate dashboard modal', () => { ...@@ -51,12 +58,7 @@ describe('duplicate dashboard modal', () => {
preventDefault: jest.fn(), preventDefault: jest.fn(),
}; };
wrapper = createComponent({ wrapper = createComponent();
methods: {
// Mock vuex actions
duplicateSystemDashboard: duplicateDashboardAction,
},
});
wrapper.vm.$refs.duplicateDashboardModal.hide = jest.fn(); wrapper.vm.$refs.duplicateDashboardModal.hide = jest.fn();
}); });
...@@ -65,10 +67,10 @@ describe('duplicate dashboard modal', () => { ...@@ -65,10 +67,10 @@ describe('duplicate dashboard modal', () => {
expect(findDuplicateDashboardForm().exists()).toBe(true); expect(findDuplicateDashboardForm().exists()).toBe(true);
}); });
it('saves a new dashboard', () => { it('saves a new dashboard', async () => {
findModal().vm.$emit('ok', okEvent); findModal().vm.$emit('ok', okEvent);
return waitForPromises().then(() => { await waitForPromises();
expect(okEvent.preventDefault).toHaveBeenCalled(); expect(okEvent.preventDefault).toHaveBeenCalled();
expect(wrapper.emitted().dashboardDuplicated).toBeTruthy(); expect(wrapper.emitted().dashboardDuplicated).toBeTruthy();
expect(wrapper.emitted().dashboardDuplicated[0]).toEqual([dashboardGitResponse[0]]); expect(wrapper.emitted().dashboardDuplicated[0]).toEqual([dashboardGitResponse[0]]);
...@@ -76,15 +78,15 @@ describe('duplicate dashboard modal', () => { ...@@ -76,15 +78,15 @@ describe('duplicate dashboard modal', () => {
expect(wrapper.vm.$refs.duplicateDashboardModal.hide).toHaveBeenCalled(); expect(wrapper.vm.$refs.duplicateDashboardModal.hide).toHaveBeenCalled();
expect(findAlert().exists()).toBe(false); expect(findAlert().exists()).toBe(false);
}); });
});
it('handles error when a new dashboard is not saved', () => { it('handles error when a new dashboard is not saved', async () => {
const errMsg = 'An error occurred'; const errMsg = 'An error occurred';
duplicateDashboardAction.mockRejectedValueOnce(errMsg); duplicateDashboardAction.mockRejectedValueOnce(errMsg);
findModal().vm.$emit('ok', okEvent); findModal().vm.$emit('ok', okEvent);
return waitForPromises().then(() => { await waitForPromises();
expect(okEvent.preventDefault).toHaveBeenCalled(); expect(okEvent.preventDefault).toHaveBeenCalled();
expect(findAlert().exists()).toBe(true); expect(findAlert().exists()).toBe(true);
...@@ -93,7 +95,6 @@ describe('duplicate dashboard modal', () => { ...@@ -93,7 +95,6 @@ describe('duplicate dashboard modal', () => {
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false); expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
expect(wrapper.vm.$refs.duplicateDashboardModal.hide).not.toHaveBeenCalled(); expect(wrapper.vm.$refs.duplicateDashboardModal.hide).not.toHaveBeenCalled();
}); });
});
it('updates the form on changes', () => { it('updates the form on changes', () => {
const formVals = { const formVals = {
......
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