Commit 28046a19 authored by Mike Greiling's avatar Mike Greiling

Merge branch 'fe-fix-karma-vue-test-utils-violations' into 'master'

Fe fix karma vue test utils violations

Closes #32213

See merge request gitlab-org/gitlab!18765
parents 41f1591b eb55ed89
...@@ -4,11 +4,12 @@ import { GlPopover, GlLink } from '@gitlab/ui'; ...@@ -4,11 +4,12 @@ import { GlPopover, GlLink } from '@gitlab/ui';
import { TEST_HOST } from 'helpers/test_constants'; import { TEST_HOST } from 'helpers/test_constants';
import component from 'ee/approvals/components/approval_check_popover.vue'; import component from 'ee/approvals/components/approval_check_popover.vue';
const localVue = createLocalVue();
describe('Approval Check Popover', () => { describe('Approval Check Popover', () => {
let wrapper; let wrapper;
beforeEach(() => { beforeEach(() => {
const localVue = createLocalVue();
wrapper = shallowMount(component, { wrapper = shallowMount(component, {
localVue, localVue,
propsData: { propsData: {
......
...@@ -4,21 +4,21 @@ import noteActions from '~/notes/components/note_actions.vue'; ...@@ -4,21 +4,21 @@ import noteActions from '~/notes/components/note_actions.vue';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import { userDataMock } from '../../../../spec/frontend/notes/mock_data'; import { userDataMock } from '../../../../spec/frontend/notes/mock_data';
const localVue = createLocalVue();
describe('noteActions', () => { describe('noteActions', () => {
let wrapper; let wrapper;
let store; let store;
let props; let props;
const createWrapper = propsData => { const createWrapper = propsData =>
const localVue = createLocalVue(); shallowMount(localVue.extend(noteActions), {
return shallowMount(noteActions, {
store, store,
propsData, propsData,
localVue, localVue,
sync: false, sync: false,
attachToDocument: true, attachToDocument: true,
}); });
};
beforeEach(() => { beforeEach(() => {
store = createStore(); store = createStore();
......
...@@ -28,9 +28,10 @@ const mockItem = Object.assign({}, mockIssue1, { ...@@ -28,9 +28,10 @@ const mockItem = Object.assign({}, mockIssue1, {
assignees: epicUtils.extractIssueAssignees(mockIssue1.assignees), assignees: epicUtils.extractIssueAssignees(mockIssue1.assignees),
}); });
const localVue = createLocalVue();
const createComponent = (parentItem = mockParentItem, item = mockItem) => { const createComponent = (parentItem = mockParentItem, item = mockItem) => {
const store = createDefaultStore(); const store = createDefaultStore();
const localVue = createLocalVue();
const children = epicUtils.processQueryResponse(mockQueryResponse.data.group); const children = epicUtils.processQueryResponse(mockQueryResponse.data.group);
store.dispatch('setInitialParentItem', mockParentItem); store.dispatch('setInitialParentItem', mockParentItem);
......
...@@ -23,9 +23,10 @@ const mockItem = Object.assign({}, mockEpic1, { ...@@ -23,9 +23,10 @@ const mockItem = Object.assign({}, mockEpic1, {
pathIdSeparator: PathIdSeparator.Epic, pathIdSeparator: PathIdSeparator.Epic,
}); });
const localVue = createLocalVue();
const createComponent = (parentItem = mockParentItem, item = mockItem) => { const createComponent = (parentItem = mockParentItem, item = mockItem) => {
const store = createDefaultStore(); const store = createDefaultStore();
const localVue = createLocalVue();
const children = epicUtils.processQueryResponse(mockQueryResponse.data.group); const children = epicUtils.processQueryResponse(mockQueryResponse.data.group);
store.dispatch('setInitialParentItem', mockParentItem); store.dispatch('setInitialParentItem', mockParentItem);
...@@ -44,7 +45,7 @@ const createComponent = (parentItem = mockParentItem, item = mockItem) => { ...@@ -44,7 +45,7 @@ const createComponent = (parentItem = mockParentItem, item = mockItem) => {
isSubItem: true, isSubItem: true,
}); });
return shallowMount(TreeItem, { return shallowMount(localVue.extend(TreeItem), {
localVue, localVue,
store, store,
stubs: { stubs: {
...@@ -54,6 +55,7 @@ const createComponent = (parentItem = mockParentItem, item = mockItem) => { ...@@ -54,6 +55,7 @@ const createComponent = (parentItem = mockParentItem, item = mockItem) => {
parentItem, parentItem,
item, item,
}, },
sync: false,
}); });
}; };
......
...@@ -22,7 +22,12 @@ describe('Batch comments diff file drafts component', () => { ...@@ -22,7 +22,12 @@ describe('Batch comments diff file drafts component', () => {
}, },
}); });
vm = shallowMount(DiffFileDrafts, { store, localVue, propsData: { fileHash: 'filehash' } }); vm = shallowMount(localVue.extend(DiffFileDrafts), {
store,
localVue,
propsData: { fileHash: 'filehash' },
sync: false,
});
} }
afterEach(() => { afterEach(() => {
......
...@@ -5,6 +5,8 @@ import { createStore } from 'ee/batch_comments/stores'; ...@@ -5,6 +5,8 @@ import { createStore } from 'ee/batch_comments/stores';
import '~/behaviors/markdown/render_gfm'; import '~/behaviors/markdown/render_gfm';
import { createDraft } from '../mock_data'; import { createDraft } from '../mock_data';
const localVue = createLocalVue();
describe('Batch comments draft note component', () => { describe('Batch comments draft note component', () => {
let wrapper; let wrapper;
let draft; let draft;
...@@ -14,8 +16,7 @@ describe('Batch comments draft note component', () => { ...@@ -14,8 +16,7 @@ describe('Batch comments draft note component', () => {
draft = createDraft(); draft = createDraft();
const localVue = createLocalVue(); wrapper = shallowMount(localVue.extend(DraftNote), {
wrapper = shallowMount(DraftNote, {
store, store,
propsData: { draft }, propsData: { draft },
sync: false, sync: false,
......
...@@ -17,7 +17,7 @@ describe('CustomMetricsForm', () => { ...@@ -17,7 +17,7 @@ describe('CustomMetricsForm', () => {
legend: '', legend: '',
}, },
}) { }) {
wrapper = shallowMount(CustomMetricsForm, { wrapper = shallowMount(localVue.extend(CustomMetricsForm), {
localVue, localVue,
sync: false, sync: false,
propsData: { propsData: {
......
import Vue from 'vue';
import IssuesAnalytics from 'ee/issues_analytics/components/issues_analytics.vue'; import IssuesAnalytics from 'ee/issues_analytics/components/issues_analytics.vue';
import EmptyState from 'ee/issues_analytics/components/empty_state.vue'; import EmptyState from 'ee/issues_analytics/components/empty_state.vue';
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import { createStore } from 'ee/issues_analytics/stores'; import { createStore } from 'ee/issues_analytics/stores';
const localVue = createLocalVue();
describe('Issues Analytics component', () => { describe('Issues Analytics component', () => {
let vm; let vm;
let store; let store;
let mountComponent; let mountComponent;
const Component = Vue.extend(IssuesAnalytics);
const mockChartData = { '2017-11': 0, '2017-12': 2 }; const mockChartData = { '2017-11': 0, '2017-12': 2 };
beforeEach(() => { beforeEach(() => {
...@@ -22,13 +22,14 @@ describe('Issues Analytics component', () => { ...@@ -22,13 +22,14 @@ describe('Issues Analytics component', () => {
filterBlockEl: document.querySelector('#mock-filter'), filterBlockEl: document.querySelector('#mock-filter'),
}; };
return shallowMount(Component, { return shallowMount(localVue.extend(IssuesAnalytics), {
propsData: props, propsData: props,
stubs: { stubs: {
GlColumnChart: true, GlColumnChart: true,
EmptyState, EmptyState,
}, },
store, store,
localVue,
}).vm; }).vm;
}; };
......
...@@ -14,12 +14,25 @@ import propsData from 'spec/monitoring/components/dashboard_spec'; ...@@ -14,12 +14,25 @@ import propsData from 'spec/monitoring/components/dashboard_spec';
import CustomMetricsFormFields from 'ee/custom_metrics/components/custom_metrics_form_fields.vue'; import CustomMetricsFormFields from 'ee/custom_metrics/components/custom_metrics_form_fields.vue';
import * as types from '~/monitoring/stores/mutation_types'; import * as types from '~/monitoring/stores/mutation_types';
const localVue = createLocalVue();
describe('Dashboard', () => { describe('Dashboard', () => {
let Component; let Component;
let mock; let mock;
let store; let store;
let vm; let vm;
const localVue = createLocalVue();
const createComponent = (props = {}) => {
vm = shallowMount(localVue.extend(Component), {
propsData: {
...propsData,
...props,
},
store,
sync: false,
localVue,
});
};
beforeEach(() => { beforeEach(() => {
setFixtures(` setFixtures(`
...@@ -60,52 +73,37 @@ describe('Dashboard', () => { ...@@ -60,52 +73,37 @@ describe('Dashboard', () => {
describe('add custom metrics', () => { describe('add custom metrics', () => {
describe('when not available', () => { describe('when not available', () => {
beforeEach(() => { beforeEach(() => {
vm = shallowMount(Component, { createComponent({
propsData: {
...propsData,
customMetricsAvailable: false, customMetricsAvailable: false,
customMetricsPath: '/endpoint', customMetricsPath: '/endpoint',
hasMetrics: true, hasMetrics: true,
prometheusAlertsAvailable: true, prometheusAlertsAvailable: true,
alertsEndpoint: '/endpoint', alertsEndpoint: '/endpoint',
},
store,
}); });
}); });
it('does not render add button on the dashboard', done => { it('does not render add button on the dashboard', () => {
setTimeout(() => {
expect(vm.element.querySelector('.js-add-metric-button')).toBe(null); expect(vm.element.querySelector('.js-add-metric-button')).toBe(null);
done();
});
}); });
}); });
describe('when available', () => { describe('when available', () => {
beforeEach(() => { beforeEach(done => {
vm = shallowMount(Component, { createComponent({
propsData: {
...propsData,
customMetricsAvailable: true, customMetricsAvailable: true,
customMetricsPath: '/endpoint', customMetricsPath: '/endpoint',
hasMetrics: true, hasMetrics: true,
prometheusAlertsAvailable: true, prometheusAlertsAvailable: true,
alertsEndpoint: '/endpoint', alertsEndpoint: '/endpoint',
},
store,
}); });
setupComponentStore(vm); setupComponentStore(vm);
});
it('renders add button on the dashboard', done => { vm.vm.$nextTick(done);
localVue.nextTick(() => {
expect(vm.element.querySelector('.js-add-metric-button').innerText).toContain(
'Add metric',
);
done();
}); });
it('renders add button on the dashboard', () => {
expect(vm.element.querySelector('.js-add-metric-button').innerText).toContain('Add metric');
}); });
it('uses modal for custom metrics form', () => { it('uses modal for custom metrics form', () => {
......
import component from 'ee/onboarding/onboarding_helper/components/action_popover.vue'; import component from 'ee/onboarding/onboarding_helper/components/action_popover.vue';
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import eventHub from 'ee/onboarding/onboarding_helper/event_hub'; import eventHub from 'ee/onboarding/onboarding_helper/event_hub';
const localVue = createLocalVue();
describe('User onboarding action popover', () => { describe('User onboarding action popover', () => {
let wrapper; let wrapper;
let props; let props;
...@@ -11,29 +13,29 @@ describe('User onboarding action popover', () => { ...@@ -11,29 +13,29 @@ describe('User onboarding action popover', () => {
const placement = 'top'; const placement = 'top';
const showDefault = true; const showDefault = true;
beforeEach(() => { const createComponent = () => {
props = { props = {
target, target,
content, content,
placement, placement,
showDefault, showDefault,
}; };
wrapper = shallowMount(component, { wrapper = shallowMount(localVue.extend(component), {
propsData: props, propsData: props,
sync: false,
localVue,
}); });
}); };
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
describe('mounted', () => { describe('when mounted', () => {
it("binds 'onboardingHelper.showActionPopover', 'onboardingHelper.hideActionPopover' and 'onboardingHelper.destroyActionPopover' event listener on eventHub", () => { it("binds 'onboardingHelper.showActionPopover', 'onboardingHelper.hideActionPopover' and 'onboardingHelper.destroyActionPopover' event listener on eventHub", () => {
spyOn(eventHub, '$on'); spyOn(eventHub, '$on');
const wrapperX = shallowMount(component, { createComponent();
propsData: props,
});
expect(eventHub.$on).toHaveBeenCalledWith( expect(eventHub.$on).toHaveBeenCalledWith(
'onboardingHelper.showActionPopover', 'onboardingHelper.showActionPopover',
...@@ -49,11 +51,14 @@ describe('User onboarding action popover', () => { ...@@ -49,11 +51,14 @@ describe('User onboarding action popover', () => {
'onboardingHelper.destroyActionPopover', 'onboardingHelper.destroyActionPopover',
jasmine.any(Function), jasmine.any(Function),
); );
wrapperX.destroy();
}); });
}); });
describe('after mount', () => {
beforeEach(() => {
createComponent();
});
describe('beforeDestroy', () => { describe('beforeDestroy', () => {
it("unbinds 'showActionPopover', 'hideActionPopover' and 'destroyActionPopover' event handler", () => { it("unbinds 'showActionPopover', 'hideActionPopover' and 'destroyActionPopover' event handler", () => {
spyOn(eventHub, '$off'); spyOn(eventHub, '$off');
...@@ -83,4 +88,5 @@ describe('User onboarding action popover', () => { ...@@ -83,4 +88,5 @@ describe('User onboarding action popover', () => {
expect(wrapper.text()).toEqual(content); expect(wrapper.text()).toEqual(content);
}); });
}); });
});
}); });
import component from 'ee/onboarding/onboarding_helper/components/help_content_popover.vue'; import component from 'ee/onboarding/onboarding_helper/components/help_content_popover.vue';
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
const localVue = createLocalVue();
describe('User onboarding help content popover', () => { describe('User onboarding help content popover', () => {
let wrapper; let wrapper;
...@@ -42,7 +44,7 @@ describe('User onboarding help content popover', () => { ...@@ -42,7 +44,7 @@ describe('User onboarding help content popover', () => {
}; };
function createComponent(propsData) { function createComponent(propsData) {
wrapper = shallowMount(component, { propsData }); wrapper = shallowMount(localVue.extend(component), { propsData, localVue, sync: false });
} }
afterEach(() => { afterEach(() => {
......
import component from 'ee/onboarding/onboarding_helper/components/onboarding_helper.vue'; import component from 'ee/onboarding/onboarding_helper/components/onboarding_helper.vue';
import TourPartsList from 'ee/onboarding/onboarding_helper/components/tour_parts_list.vue'; import TourPartsList from 'ee/onboarding/onboarding_helper/components/tour_parts_list.vue';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import { GlProgressBar, GlLoadingIcon } from '@gitlab/ui'; import { GlProgressBar, GlLoadingIcon } from '@gitlab/ui';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
const localVue = createLocalVue();
describe('User onboarding tour parts list', () => { describe('User onboarding tour parts list', () => {
let wrapper; let wrapper;
...@@ -29,7 +31,7 @@ describe('User onboarding tour parts list', () => { ...@@ -29,7 +31,7 @@ describe('User onboarding tour parts list', () => {
}; };
function createComponent(propsData) { function createComponent(propsData) {
wrapper = shallowMount(component, { propsData }); wrapper = shallowMount(localVue.extend(component), { propsData, localVue, sync: false });
} }
beforeEach(() => { beforeEach(() => {
...@@ -125,10 +127,16 @@ describe('User onboarding tour parts list', () => { ...@@ -125,10 +127,16 @@ describe('User onboarding tour parts list', () => {
describe('watch', () => { describe('watch', () => {
describe('watch initialShow', () => { describe('watch initialShow', () => {
it('sets showPopover to true if initialShow is true', () => { it('sets showPopover to true if initialShow is true', done => {
wrapper.setProps({ initialShow: true }); wrapper.setProps({ initialShow: true });
wrapper.vm
.$nextTick()
.then(() => {
expect(wrapper.vm.showPopover).toBe(true); expect(wrapper.vm.showPopover).toBe(true);
})
.then(done)
.catch(done.fail);
}); });
}); });
...@@ -314,7 +322,7 @@ describe('User onboarding tour parts list', () => { ...@@ -314,7 +322,7 @@ describe('User onboarding tour parts list', () => {
expect(wrapper.find('.qa-toggle-btn').exists()).toBe(true); expect(wrapper.find('.qa-toggle-btn').exists()).toBe(true);
}); });
it('renders the proper toggle button icons', () => { it('renders the proper toggle button icons', done => {
const btn = wrapper.find('.qa-toggle-btn'); const btn = wrapper.find('.qa-toggle-btn');
const icon = btn.find(Icon); const icon = btn.find(Icon);
...@@ -322,7 +330,13 @@ describe('User onboarding tour parts list', () => { ...@@ -322,7 +330,13 @@ describe('User onboarding tour parts list', () => {
wrapper.vm.expanded = true; wrapper.vm.expanded = true;
wrapper.vm
.$nextTick()
.then(() => {
expect(icon.props('name')).toEqual('close'); expect(icon.props('name')).toEqual('close');
})
.then(done)
.catch(done.fail);
}); });
it('renders the tour parts list if there are tour titles', () => { it('renders the tour parts list if there are tour titles', () => {
......
import component from 'ee/onboarding/onboarding_helper/components/tour_parts_list.vue'; import component from 'ee/onboarding/onboarding_helper/components/tour_parts_list.vue';
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
const localVue = createLocalVue();
describe('User onboarding tour parts list', () => { describe('User onboarding tour parts list', () => {
let wrapper; let wrapper;
...@@ -18,7 +20,7 @@ describe('User onboarding tour parts list', () => { ...@@ -18,7 +20,7 @@ describe('User onboarding tour parts list', () => {
let tourItems; let tourItems;
function createComponent(propsData) { function createComponent(propsData) {
wrapper = shallowMount(component, { propsData }); wrapper = shallowMount(localVue.extend(component), { propsData, localVue, sync: false });
} }
beforeEach(() => { beforeEach(() => {
......
...@@ -3,9 +3,11 @@ import component from 'ee/onboarding/onboarding_welcome/components/welcome_page. ...@@ -3,9 +3,11 @@ import component from 'ee/onboarding/onboarding_welcome/components/welcome_page.
import ActionPopover from 'ee/onboarding/onboarding_helper/components/action_popover.vue'; import ActionPopover from 'ee/onboarding/onboarding_helper/components/action_popover.vue';
import HelpContentPopover from 'ee/onboarding/onboarding_helper/components/help_content_popover.vue'; import HelpContentPopover from 'ee/onboarding/onboarding_helper/components/help_content_popover.vue';
import UserAvatarImage from '~/vue_shared/components/user_avatar/user_avatar_image.vue'; import UserAvatarImage from '~/vue_shared/components/user_avatar/user_avatar_image.vue';
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import onboardingUtils from 'ee/onboarding/utils'; import onboardingUtils from 'ee/onboarding/utils';
const localVue = createLocalVue();
describe('User onboarding welcome page', () => { describe('User onboarding welcome page', () => {
let wrapper; let wrapper;
const props = { const props = {
...@@ -16,7 +18,7 @@ describe('User onboarding welcome page', () => { ...@@ -16,7 +18,7 @@ describe('User onboarding welcome page', () => {
}; };
function createComponent(propsData) { function createComponent(propsData) {
wrapper = shallowMount(component, { propsData }); wrapper = shallowMount(localVue.extend(component), { propsData, localVue, sync: false });
} }
afterEach(() => { afterEach(() => {
......
...@@ -14,14 +14,17 @@ describe('project component', () => { ...@@ -14,14 +14,17 @@ describe('project component', () => {
const ProjectComponent = localVue.extend(Project); const ProjectComponent = localVue.extend(Project);
let wrapper; let wrapper;
beforeEach(() => { const createComponent = (props = {}) => {
wrapper = shallowMount(ProjectComponent, { wrapper = shallowMount(ProjectComponent, {
sync: false, sync: false,
store, store,
localVue, localVue,
propsData: { project: mockOneProject }, propsData: {
}); project: mockOneProject,
...props,
},
}); });
};
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -37,12 +40,8 @@ describe('project component', () => { ...@@ -37,12 +40,8 @@ describe('project component', () => {
upgrade_required: true, upgrade_required: true,
upgrade_path: '/upgrade', upgrade_path: '/upgrade',
}; };
wrapper = shallowMount(ProjectComponent, {
sync: false, createComponent({ project });
store,
localVue,
propsData: { project },
});
}); });
it('shows project title', () => { it('shows project title', () => {
...@@ -72,12 +71,8 @@ describe('project component', () => { ...@@ -72,12 +71,8 @@ describe('project component', () => {
upgrade_required: true, upgrade_required: true,
upgrade_path: '', upgrade_path: '',
}; };
wrapper = shallowMount(ProjectComponent, {
sync: false, createComponent({ project });
store,
localVue,
propsData: { project },
});
}); });
it('shows upgrade license text', () => { it('shows upgrade license text', () => {
...@@ -91,6 +86,10 @@ describe('project component', () => { ...@@ -91,6 +86,10 @@ describe('project component', () => {
}); });
describe('wrapped components', () => { describe('wrapped components', () => {
beforeEach(() => {
createComponent();
});
describe('project header', () => { describe('project header', () => {
it('binds project', () => { it('binds project', () => {
const header = wrapper.find(ProjectHeader); const header = wrapper.find(ProjectHeader);
......
...@@ -3,16 +3,16 @@ import { GlButton } from '@gitlab/ui'; ...@@ -3,16 +3,16 @@ import { GlButton } from '@gitlab/ui';
import CreateEpicForm from 'ee/related_items_tree/components/create_epic_form.vue'; import CreateEpicForm from 'ee/related_items_tree/components/create_epic_form.vue';
const createComponent = (isSubmitting = false) => { const localVue = createLocalVue();
const localVue = createLocalVue();
return mount(CreateEpicForm, { const createComponent = (isSubmitting = false) =>
mount(localVue.extend(CreateEpicForm), {
localVue, localVue,
propsData: { propsData: {
isSubmitting, isSubmitting,
}, },
sync: false,
}); });
};
describe('RelatedItemsTree', () => { describe('RelatedItemsTree', () => {
describe('CreateEpicForm', () => { describe('CreateEpicForm', () => {
......
...@@ -11,16 +11,18 @@ import IssueActionsSplitButton from 'ee/related_items_tree/components/issue_acti ...@@ -11,16 +11,18 @@ import IssueActionsSplitButton from 'ee/related_items_tree/components/issue_acti
import { mockInitialConfig, mockParentItem } from '../mock_data'; import { mockInitialConfig, mockParentItem } from '../mock_data';
const localVue = createLocalVue();
const createComponent = () => { const createComponent = () => {
const store = createDefaultStore(); const store = createDefaultStore();
const localVue = createLocalVue();
store.dispatch('setInitialConfig', mockInitialConfig); store.dispatch('setInitialConfig', mockInitialConfig);
store.dispatch('setInitialParentItem', mockParentItem); store.dispatch('setInitialParentItem', mockParentItem);
return shallowMount(RelatedItemsTreeApp, { return shallowMount(localVue.extend(RelatedItemsTreeApp), {
localVue, localVue,
store, store,
sync: false,
}); });
}; };
......
...@@ -4,10 +4,10 @@ import RelatedItemsBody from 'ee/related_items_tree/components/related_items_tre ...@@ -4,10 +4,10 @@ import RelatedItemsBody from 'ee/related_items_tree/components/related_items_tre
import { mockParentItem } from '../mock_data'; import { mockParentItem } from '../mock_data';
const createComponent = (parentItem = mockParentItem, children = []) => { const localVue = createLocalVue();
const localVue = createLocalVue();
return shallowMount(RelatedItemsBody, { const createComponent = (parentItem = mockParentItem, children = []) =>
shallowMount(localVue.extend(RelatedItemsBody), {
localVue, localVue,
stubs: { stubs: {
'tree-root': true, 'tree-root': true,
...@@ -16,8 +16,8 @@ const createComponent = (parentItem = mockParentItem, children = []) => { ...@@ -16,8 +16,8 @@ const createComponent = (parentItem = mockParentItem, children = []) => {
parentItem, parentItem,
children, children,
}, },
sync: false,
}); });
};
describe('RelatedItemsTree', () => { describe('RelatedItemsTree', () => {
describe('RelatedTreeBody', () => { describe('RelatedTreeBody', () => {
......
...@@ -14,16 +14,16 @@ const mockClosedAt = `${currentDate.getFullYear() - 1}-${currentDate.getMonth() ...@@ -14,16 +14,16 @@ const mockClosedAt = `${currentDate.getFullYear() - 1}-${currentDate.getMonth()
1}-${currentDate.getDate()}`; 1}-${currentDate.getDate()}`;
const mockClosedAtYear = currentDate.getFullYear() - 1; const mockClosedAtYear = currentDate.getFullYear() - 1;
const localVue = createLocalVue();
const createComponent = ({ const createComponent = ({
getTargetRef = () => {}, getTargetRef = () => {},
isOpen = false, isOpen = false,
state = 'closed', state = 'closed',
createdAt = mockCreatedAt, createdAt = mockCreatedAt,
closedAt = mockClosedAt, closedAt = mockClosedAt,
}) => { }) =>
const localVue = createLocalVue(); shallowMount(localVue.extend(StateTooltip), {
return shallowMount(StateTooltip, {
localVue, localVue,
propsData: { propsData: {
getTargetRef, getTargetRef,
...@@ -32,8 +32,8 @@ const createComponent = ({ ...@@ -32,8 +32,8 @@ const createComponent = ({
createdAt, createdAt,
closedAt, closedAt,
}, },
sync: false,
}); });
};
describe('RelatedItemsTree', () => { describe('RelatedItemsTree', () => {
describe('RelatedItemsTreeHeader', () => { describe('RelatedItemsTreeHeader', () => {
......
...@@ -16,9 +16,10 @@ const mockItem = Object.assign({}, mockIssue1, { ...@@ -16,9 +16,10 @@ const mockItem = Object.assign({}, mockIssue1, {
assignees: epicUtils.extractIssueAssignees(mockIssue1.assignees), assignees: epicUtils.extractIssueAssignees(mockIssue1.assignees),
}); });
const localVue = createLocalVue();
const createComponent = (parentItem = mockParentItem, item = mockItem) => { const createComponent = (parentItem = mockParentItem, item = mockItem) => {
const store = createDefaultStore(); const store = createDefaultStore();
const localVue = createLocalVue();
const children = epicUtils.processQueryResponse(mockQueryResponse.data.group); const children = epicUtils.processQueryResponse(mockQueryResponse.data.group);
store.dispatch('setInitialParentItem', mockParentItem); store.dispatch('setInitialParentItem', mockParentItem);
...@@ -36,9 +37,10 @@ const createComponent = (parentItem = mockParentItem, item = mockItem) => { ...@@ -36,9 +37,10 @@ const createComponent = (parentItem = mockParentItem, item = mockItem) => {
item, item,
}); });
return shallowMount(TreeItemRemoveModal, { return shallowMount(localVue.extend(TreeItemRemoveModal), {
localVue, localVue,
store, store,
sync: false,
}); });
}; };
......
...@@ -18,13 +18,14 @@ import { ...@@ -18,13 +18,14 @@ import {
const { epic } = mockQueryResponse.data.group; const { epic } = mockQueryResponse.data.group;
const localVue = createLocalVue();
const createComponent = ({ const createComponent = ({
parentItem = mockParentItem, parentItem = mockParentItem,
epicPageInfo = epic.children.pageInfo, epicPageInfo = epic.children.pageInfo,
issuesPageInfo = epic.issues.pageInfo, issuesPageInfo = epic.issues.pageInfo,
} = {}) => { } = {}) => {
const store = createDefaultStore(); const store = createDefaultStore();
const localVue = createLocalVue();
const children = epicUtils.processQueryResponse(mockQueryResponse.data.group); const children = epicUtils.processQueryResponse(mockQueryResponse.data.group);
store.dispatch('setInitialParentItem', mockParentItem); store.dispatch('setInitialParentItem', mockParentItem);
...@@ -44,7 +45,7 @@ const createComponent = ({ ...@@ -44,7 +45,7 @@ const createComponent = ({
pageInfo: issuesPageInfo, pageInfo: issuesPageInfo,
}); });
return shallowMount(TreeRoot, { return shallowMount(localVue.extend(TreeRoot), {
localVue, localVue,
store, store,
stubs: { stubs: {
...@@ -55,6 +56,7 @@ const createComponent = ({ ...@@ -55,6 +56,7 @@ const createComponent = ({
parentItem, parentItem,
children, children,
}, },
sync: false,
}); });
}; };
......
import Vue from 'vue'; import Vue from 'vue';
import component from 'ee/security_dashboard/components/vulnerability_chart_buttons.vue'; import component from 'ee/security_dashboard/components/vulnerability_chart_buttons.vue';
import { DAYS } from 'ee/security_dashboard/store/modules/vulnerabilities/constants'; import { DAYS } from 'ee/security_dashboard/store/modules/vulnerabilities/constants';
import { shallowMount, mount } from '@vue/test-utils'; import { shallowMount, mount, createLocalVue } from '@vue/test-utils';
const localVue = createLocalVue();
describe('Vulnerability Chart Buttons', () => { describe('Vulnerability Chart Buttons', () => {
let wrapper;
const Component = Vue.extend(component); const Component = Vue.extend(component);
const days = [DAYS.THIRTY, DAYS.SIXTY, DAYS.NINETY]; const days = [DAYS.THIRTY, DAYS.SIXTY, DAYS.NINETY];
const createWrapper = (props = {}, mountfn = shallowMount) => {
wrapper = mountfn(localVue.extend(Component), {
propsData: { days, ...props },
localVue,
sync: false,
});
};
afterEach(() => {
wrapper.destroy();
});
describe('when rendering the buttons', () => { describe('when rendering the buttons', () => {
it('should render with 90 days selected', () => { it('should render with 90 days selected', () => {
const activeDay = DAYS.NINETY; const activeDay = DAYS.NINETY;
const wrapper = shallowMount(Component, { propsData: { days, activeDay } }); createWrapper({ activeDay });
const activeButton = wrapper.find('[data-days="90"].active'); const activeButton = wrapper.find('[data-days="90"].active');
expect(activeButton.attributes('data-days')).toMatch('90'); expect(activeButton.attributes('data-days')).toMatch('90');
...@@ -18,7 +34,8 @@ describe('Vulnerability Chart Buttons', () => { ...@@ -18,7 +34,8 @@ describe('Vulnerability Chart Buttons', () => {
it('should render with 60 days selected', () => { it('should render with 60 days selected', () => {
const activeDay = DAYS.SIXTY; const activeDay = DAYS.SIXTY;
const wrapper = shallowMount(Component, { propsData: { days, activeDay } }); createWrapper({ activeDay });
const activeButton = wrapper.find('[data-days="60"].active'); const activeButton = wrapper.find('[data-days="60"].active');
expect(activeButton.attributes('data-days')).toMatch('60'); expect(activeButton.attributes('data-days')).toMatch('60');
...@@ -26,7 +43,8 @@ describe('Vulnerability Chart Buttons', () => { ...@@ -26,7 +43,8 @@ describe('Vulnerability Chart Buttons', () => {
it('should render with 30 days selected', () => { it('should render with 30 days selected', () => {
const activeDay = DAYS.THIRTY; const activeDay = DAYS.THIRTY;
const wrapper = shallowMount(Component, { propsData: { days, activeDay } }); createWrapper({ activeDay });
const activeButton = wrapper.find('[data-days="30"].active'); const activeButton = wrapper.find('[data-days="30"].active');
expect(activeButton.attributes('data-days')).toMatch('30'); expect(activeButton.attributes('data-days')).toMatch('30');
...@@ -35,10 +53,9 @@ describe('Vulnerability Chart Buttons', () => { ...@@ -35,10 +53,9 @@ describe('Vulnerability Chart Buttons', () => {
describe('when clicking the button', () => { describe('when clicking the button', () => {
const activeDay = DAYS.THIRTY; const activeDay = DAYS.THIRTY;
let wrapper;
beforeEach(() => { beforeEach(() => {
wrapper = mount(Component, { propsData: { days, activeDay }, sync: false }); createWrapper({ activeDay }, mount);
}); });
it('should call the clickHandler', () => { it('should call the clickHandler', () => {
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import StorageApp from 'ee/storage_counter/components/app.vue'; import StorageApp from 'ee/storage_counter/components/app.vue';
import Project from 'ee/storage_counter/components/project.vue'; import Project from 'ee/storage_counter/components/project.vue';
import { projects, withRootStorageStatistics } from '../data'; import { projects, withRootStorageStatistics } from '../data';
const localVue = createLocalVue();
describe('Storage counter app', () => { describe('Storage counter app', () => {
let wrapper; let wrapper;
...@@ -15,10 +17,11 @@ describe('Storage counter app', () => { ...@@ -15,10 +17,11 @@ describe('Storage counter app', () => {
}, },
}; };
wrapper = shallowMount(StorageApp, { wrapper = shallowMount(localVue.extend(StorageApp), {
propsData: { namespacePath: 'h5bp', helpPagePath: 'help' }, propsData: { namespacePath: 'h5bp', helpPagePath: 'help' },
mocks: { $apollo }, mocks: { $apollo },
sync: true, sync: false,
localVue,
}); });
} }
...@@ -30,33 +33,51 @@ describe('Storage counter app', () => { ...@@ -30,33 +33,51 @@ describe('Storage counter app', () => {
wrapper.destroy(); wrapper.destroy();
}); });
it('renders the 2 projects', () => { it('renders the 2 projects', done => {
wrapper.setData({ wrapper.setData({
namespace: projects, namespace: projects,
}); });
wrapper.vm
.$nextTick()
.then(() => {
expect(wrapper.findAll(Project).length).toEqual(2); expect(wrapper.findAll(Project).length).toEqual(2);
})
.then(done)
.catch(done.fail);
}); });
describe('with rootStorageStatistics information', () => { describe('with rootStorageStatistics information', () => {
it('renders total usage', () => { it('renders total usage', done => {
wrapper.setData({ wrapper.setData({
namespace: withRootStorageStatistics, namespace: withRootStorageStatistics,
}); });
wrapper.vm
.$nextTick()
.then(() => {
expect(wrapper.find('.js-total-usage').text()).toContain( expect(wrapper.find('.js-total-usage').text()).toContain(
withRootStorageStatistics.totalUsage, withRootStorageStatistics.totalUsage,
); );
})
.then(done)
.catch(done.fail);
}); });
}); });
describe('without rootStorageStatistics information', () => { describe('without rootStorageStatistics information', () => {
it('renders N/A', () => { it('renders N/A', done => {
wrapper.setData({ wrapper.setData({
namespace: projects, namespace: projects,
}); });
wrapper.vm
.$nextTick()
.then(() => {
expect(wrapper.find('.js-total-usage').text()).toContain('N/A'); expect(wrapper.find('.js-total-usage').text()).toContain('N/A');
})
.then(done)
.catch(done.fail);
}); });
}); });
}); });
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import Project from 'ee/storage_counter/components/project.vue'; import Project from 'ee/storage_counter/components/project.vue';
import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue'; import ProjectAvatar from '~/vue_shared/components/project_avatar/default.vue';
...@@ -22,11 +22,15 @@ const data = { ...@@ -22,11 +22,15 @@ const data = {
}, },
}; };
const localVue = createLocalVue();
function factory(project) { function factory(project) {
wrapper = shallowMount(Project, { wrapper = shallowMount(localVue.extend(Project), {
propsData: { propsData: {
project, project,
}, },
localVue,
sync: false,
}); });
} }
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import StorageRow from 'ee/storage_counter/components/storage_row.vue'; import StorageRow from 'ee/storage_counter/components/storage_row.vue';
import { numberToHumanSize } from '~/lib/utils/number_utils'; import { numberToHumanSize } from '~/lib/utils/number_utils';
...@@ -7,13 +7,16 @@ const data = { ...@@ -7,13 +7,16 @@ const data = {
name: 'LFS Package', name: 'LFS Package',
value: 1293346, value: 1293346,
}; };
const localVue = createLocalVue();
function factory({ name, value }) { function factory({ name, value }) {
wrapper = shallowMount(StorageRow, { wrapper = shallowMount(localVue.extend(StorageRow), {
propsData: { propsData: {
name, name,
value, value,
}, },
localVue,
sync: false,
}); });
} }
......
...@@ -23,6 +23,7 @@ describe('Approval auth component', () => { ...@@ -23,6 +23,7 @@ describe('Approval auth component', () => {
...props, ...props,
modalId: 'testid', modalId: 'testid',
}, },
sync: false,
localVue, localVue,
}); });
}; };
......
...@@ -4,15 +4,14 @@ import diffModule from '~/diffs/store/modules'; ...@@ -4,15 +4,14 @@ import diffModule from '~/diffs/store/modules';
import SettingsDropdown from '~/diffs/components/settings_dropdown.vue'; import SettingsDropdown from '~/diffs/components/settings_dropdown.vue';
import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '~/diffs/constants'; import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '~/diffs/constants';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('Diff settiings dropdown component', () => { describe('Diff settiings dropdown component', () => {
let vm; let vm;
let actions; let actions;
function createComponent(extendStore = () => {}) { function createComponent(extendStore = () => {}) {
const localVue = createLocalVue();
localVue.use(Vuex);
const store = new Vuex.Store({ const store = new Vuex.Store({
modules: { modules: {
diffs: { diffs: {
...@@ -26,9 +25,10 @@ describe('Diff settiings dropdown component', () => { ...@@ -26,9 +25,10 @@ describe('Diff settiings dropdown component', () => {
extendStore(store); extendStore(store);
vm = mount(SettingsDropdown, { vm = mount(localVue.extend(SettingsDropdown), {
localVue, localVue,
store, store,
sync: false,
}); });
} }
......
import Vue from 'vue';
import frequentItemsListItemComponent from '~/frequent_items/components/frequent_items_list_item.vue'; import frequentItemsListItemComponent from '~/frequent_items/components/frequent_items_list_item.vue';
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import { trimText } from 'spec/helpers/text_helper'; import { trimText } from 'spec/helpers/text_helper';
import { mockProject } from '../mock_data'; // can also use 'mockGroup', but not useful to test here import { mockProject } from '../mock_data'; // can also use 'mockGroup', but not useful to test here
const createComponent = () => { const localVue = createLocalVue();
const Component = Vue.extend(frequentItemsListItemComponent);
return shallowMount(Component, { describe('FrequentItemsListItemComponent', () => {
let wrapper;
const createComponent = (props = {}) => {
wrapper = shallowMount(localVue.extend(frequentItemsListItemComponent), {
propsData: { propsData: {
itemId: mockProject.id, itemId: mockProject.id,
itemName: mockProject.name, itemName: mockProject.name,
namespace: mockProject.namespace, namespace: mockProject.namespace,
webUrl: mockProject.webUrl, webUrl: mockProject.webUrl,
avatarUrl: mockProject.avatarUrl, avatarUrl: mockProject.avatarUrl,
...props,
}, },
sync: false,
localVue,
}); });
}; };
describe('FrequentItemsListItemComponent', () => {
let wrapper;
let vm;
beforeEach(() => {
wrapper = createComponent();
({ vm } = wrapper);
});
afterEach(() => { afterEach(() => {
vm.$destroy(); wrapper.destroy();
wrapper = null;
}); });
describe('computed', () => { describe('computed', () => {
describe('hasAvatar', () => { describe('hasAvatar', () => {
it('should return `true` or `false` if whether avatar is present or not', () => { it('should return `true` or `false` if whether avatar is present or not', () => {
wrapper.setProps({ avatarUrl: 'path/to/avatar.png' }); createComponent({ avatarUrl: 'path/to/avatar.png' });
expect(vm.hasAvatar).toBe(true); expect(wrapper.vm.hasAvatar).toBe(true);
});
wrapper.setProps({ avatarUrl: null }); it('should return `false` if avatar is not present', () => {
createComponent({ avatarUrl: null });
expect(vm.hasAvatar).toBe(false); expect(wrapper.vm.hasAvatar).toBe(false);
}); });
}); });
describe('highlightedItemName', () => { describe('highlightedItemName', () => {
it('should enclose part of project name in <b> & </b> which matches with `matcher` prop', () => { it('should enclose part of project name in <b> & </b> which matches with `matcher` prop', () => {
wrapper.setProps({ matcher: 'lab' }); createComponent({ matcher: 'lab' });
expect(wrapper.find('.js-frequent-items-item-title').html()).toContain( expect(wrapper.find('.js-frequent-items-item-title').html()).toContain(
'<b>L</b><b>a</b><b>b</b>', '<b>L</b><b>a</b><b>b</b>',
...@@ -55,7 +53,7 @@ describe('FrequentItemsListItemComponent', () => { ...@@ -55,7 +53,7 @@ describe('FrequentItemsListItemComponent', () => {
}); });
it('should return project name as it is if `matcher` is not available', () => { it('should return project name as it is if `matcher` is not available', () => {
wrapper.setProps({ matcher: null }); createComponent({ matcher: null });
expect(trimText(wrapper.find('.js-frequent-items-item-title').text())).toBe( expect(trimText(wrapper.find('.js-frequent-items-item-title').text())).toBe(
mockProject.name, mockProject.name,
...@@ -65,13 +63,13 @@ describe('FrequentItemsListItemComponent', () => { ...@@ -65,13 +63,13 @@ describe('FrequentItemsListItemComponent', () => {
describe('truncatedNamespace', () => { describe('truncatedNamespace', () => {
it('should truncate project name from namespace string', () => { it('should truncate project name from namespace string', () => {
wrapper.setProps({ namespace: 'platform / nokia-3310' }); createComponent({ namespace: 'platform / nokia-3310' });
expect(trimText(wrapper.find('.js-frequent-items-item-namespace').text())).toBe('platform'); expect(trimText(wrapper.find('.js-frequent-items-item-namespace').text())).toBe('platform');
}); });
it('should truncate namespace string from the middle if it includes more than two groups in path', () => { it('should truncate namespace string from the middle if it includes more than two groups in path', () => {
wrapper.setProps({ createComponent({
namespace: 'platform / hardware / broadcom / Wifi Group / Mobile Chipset / nokia-3310', namespace: 'platform / hardware / broadcom / Wifi Group / Mobile Chipset / nokia-3310',
}); });
...@@ -84,6 +82,8 @@ describe('FrequentItemsListItemComponent', () => { ...@@ -84,6 +82,8 @@ describe('FrequentItemsListItemComponent', () => {
describe('template', () => { describe('template', () => {
it('should render component element', () => { it('should render component element', () => {
createComponent();
expect(wrapper.classes()).toContain('frequent-items-list-item-container'); expect(wrapper.classes()).toContain('frequent-items-list-item-container');
expect(wrapper.findAll('a').length).toBe(1); expect(wrapper.findAll('a').length).toBe(1);
expect(wrapper.findAll('.frequent-items-item-avatar-container').length).toBe(1); expect(wrapper.findAll('.frequent-items-item-avatar-container').length).toBe(1);
......
import Vue from 'vue';
import searchComponent from '~/frequent_items/components/frequent_items_search_input.vue'; import searchComponent from '~/frequent_items/components/frequent_items_search_input.vue';
import eventHub from '~/frequent_items/event_hub'; import eventHub from '~/frequent_items/event_hub';
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
const createComponent = (namespace = 'projects') => { const localVue = createLocalVue();
const Component = Vue.extend(searchComponent);
return shallowMount(Component, { propsData: { namespace } }); const createComponent = (namespace = 'projects') =>
}; shallowMount(localVue.extend(searchComponent), {
propsData: { namespace },
localVue,
sync: false,
});
describe('FrequentItemsSearchInputComponent', () => { describe('FrequentItemsSearchInputComponent', () => {
let wrapper; let wrapper;
...@@ -40,7 +42,7 @@ describe('FrequentItemsSearchInputComponent', () => { ...@@ -40,7 +42,7 @@ describe('FrequentItemsSearchInputComponent', () => {
spyOn(eventHub, '$on'); spyOn(eventHub, '$on');
const vmX = createComponent().vm; const vmX = createComponent().vm;
Vue.nextTick(() => { localVue.nextTick(() => {
expect(eventHub.$on).toHaveBeenCalledWith( expect(eventHub.$on).toHaveBeenCalledWith(
`${vmX.namespace}-dropdownOpen`, `${vmX.namespace}-dropdownOpen`,
jasmine.any(Function), jasmine.any(Function),
...@@ -58,7 +60,7 @@ describe('FrequentItemsSearchInputComponent', () => { ...@@ -58,7 +60,7 @@ describe('FrequentItemsSearchInputComponent', () => {
vmX.$mount(); vmX.$mount();
vmX.$destroy(); vmX.$destroy();
Vue.nextTick(() => { localVue.nextTick(() => {
expect(eventHub.$off).toHaveBeenCalledWith( expect(eventHub.$off).toHaveBeenCalledWith(
`${vmX.namespace}-dropdownOpen`, `${vmX.namespace}-dropdownOpen`,
jasmine.any(Function), jasmine.any(Function),
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import Form from '~/jobs/components/manual_variables_form.vue'; import Form from '~/jobs/components/manual_variables_form.vue';
const localVue = createLocalVue();
describe('Manual Variables Form', () => { describe('Manual Variables Form', () => {
let wrapper; let wrapper;
const requiredProps = { const requiredProps = {
action: { action: {
path: '/play', path: '/play',
...@@ -14,8 +17,10 @@ describe('Manual Variables Form', () => { ...@@ -14,8 +17,10 @@ describe('Manual Variables Form', () => {
}; };
const factory = (props = {}) => { const factory = (props = {}) => {
wrapper = shallowMount(Form, { wrapper = shallowMount(localVue.extend(Form), {
propsData: props, propsData: props,
localVue,
sync: false,
}); });
}; };
...@@ -23,8 +28,15 @@ describe('Manual Variables Form', () => { ...@@ -23,8 +28,15 @@ describe('Manual Variables Form', () => {
factory(requiredProps); factory(requiredProps);
}); });
afterEach(() => { afterEach(done => {
// The component has a `nextTick` callback after some events so we need
// to wait for those to finish before destroying.
setImmediate(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
done();
});
}); });
it('renders empty form with correct placeholders', () => { it('renders empty form with correct placeholders', () => {
...@@ -71,7 +83,7 @@ describe('Manual Variables Form', () => { ...@@ -71,7 +83,7 @@ describe('Manual Variables Form', () => {
}); });
describe('when deleting a variable', () => { describe('when deleting a variable', () => {
it('removes the variable row', () => { beforeEach(done => {
wrapper.vm.variables = [ wrapper.vm.variables = [
{ {
key: 'new key', key: 'new key',
...@@ -80,6 +92,10 @@ describe('Manual Variables Form', () => { ...@@ -80,6 +92,10 @@ describe('Manual Variables Form', () => {
}, },
]; ];
wrapper.vm.$nextTick(done);
});
it('removes the variable row', () => {
wrapper.find(GlButton).vm.$emit('click'); wrapper.find(GlButton).vm.$emit('click');
expect(wrapper.vm.variables.length).toBe(0); expect(wrapper.vm.variables.length).toBe(0);
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import { GlColumnChart } from '@gitlab/ui/dist/charts'; import { GlColumnChart } from '@gitlab/ui/dist/charts';
import ColumnChart from '~/monitoring/components/charts/column.vue'; import ColumnChart from '~/monitoring/components/charts/column.vue';
const localVue = createLocalVue();
describe('Column component', () => { describe('Column component', () => {
let columnChart; let columnChart;
beforeEach(() => { beforeEach(() => {
columnChart = shallowMount(ColumnChart, { columnChart = shallowMount(localVue.extend(ColumnChart), {
propsData: { propsData: {
graphData: { graphData: {
queries: [ queries: [
...@@ -28,6 +30,8 @@ describe('Column component', () => { ...@@ -28,6 +30,8 @@ describe('Column component', () => {
}, },
containerWidth: 100, containerWidth: 100,
}, },
sync: false,
localVue,
}); });
}); });
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import EmptyChart from '~/monitoring/components/charts/empty_chart.vue'; import EmptyChart from '~/monitoring/components/charts/empty_chart.vue';
const localVue = createLocalVue();
describe('Empty Chart component', () => { describe('Empty Chart component', () => {
let emptyChart; let emptyChart;
const graphTitle = 'Memory Usage'; const graphTitle = 'Memory Usage';
beforeEach(() => { beforeEach(() => {
emptyChart = shallowMount(EmptyChart, { emptyChart = shallowMount(localVue.extend(EmptyChart), {
propsData: { propsData: {
graphTitle, graphTitle,
}, },
sync: false,
localVue,
}); });
}); });
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import SingleStatChart from '~/monitoring/components/charts/single_stat.vue'; import SingleStatChart from '~/monitoring/components/charts/single_stat.vue';
import { graphDataPrometheusQuery } from '../mock_data'; import { graphDataPrometheusQuery } from '../mock_data';
const localVue = createLocalVue();
describe('Single Stat Chart component', () => { describe('Single Stat Chart component', () => {
let singleStatChart; let singleStatChart;
beforeEach(() => { beforeEach(() => {
singleStatChart = shallowMount(SingleStatChart, { singleStatChart = shallowMount(localVue.extend(SingleStatChart), {
propsData: { propsData: {
graphData: graphDataPrometheusQuery, graphData: graphDataPrometheusQuery,
}, },
sync: false,
localVue,
}); });
}); });
......
...@@ -72,6 +72,17 @@ describe('Dashboard', () => { ...@@ -72,6 +72,17 @@ describe('Dashboard', () => {
let mock; let mock;
let store; let store;
let component; let component;
let wrapper;
const createComponentWrapper = (props = {}, options = {}) => {
wrapper = shallowMount(localVue.extend(DashboardComponent), {
localVue,
sync: false,
propsData: { ...propsData, ...props },
store,
...options,
});
};
beforeEach(() => { beforeEach(() => {
setFixtures(` setFixtures(`
...@@ -81,13 +92,16 @@ describe('Dashboard', () => { ...@@ -81,13 +92,16 @@ describe('Dashboard', () => {
store = createStore(); store = createStore();
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
DashboardComponent = Vue.extend(Dashboard); DashboardComponent = localVue.extend(Dashboard);
}); });
afterEach(() => { afterEach(() => {
if (component) { if (component) {
component.$destroy(); component.$destroy();
} }
if (wrapper) {
wrapper.destroy();
}
mock.restore(); mock.restore();
}); });
...@@ -123,15 +137,8 @@ describe('Dashboard', () => { ...@@ -123,15 +137,8 @@ describe('Dashboard', () => {
}); });
describe('cluster health', () => { describe('cluster health', () => {
let wrapper;
beforeEach(done => { beforeEach(done => {
wrapper = shallowMount(DashboardComponent, { createComponentWrapper({ hasMetrics: true });
localVue,
sync: false,
propsData: { ...propsData, hasMetrics: true },
store,
});
// all_dashboards is not defined in health dashboards // all_dashboards is not defined in health dashboards
wrapper.vm.$store.commit(`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, undefined); wrapper.vm.$store.commit(`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, undefined);
...@@ -383,7 +390,6 @@ describe('Dashboard', () => { ...@@ -383,7 +390,6 @@ describe('Dashboard', () => {
}); });
describe('drag and drop function', () => { describe('drag and drop function', () => {
let wrapper;
let expectedPanelCount; // also called metrics, naming to be improved: https://gitlab.com/gitlab-org/gitlab/issues/31565 let expectedPanelCount; // also called metrics, naming to be improved: https://gitlab.com/gitlab-org/gitlab/issues/31565
const findDraggables = () => wrapper.findAll(VueDraggable); const findDraggables = () => wrapper.findAll(VueDraggable);
...@@ -400,13 +406,7 @@ describe('Dashboard', () => { ...@@ -400,13 +406,7 @@ describe('Dashboard', () => {
}); });
beforeEach(done => { beforeEach(done => {
wrapper = shallowMount(DashboardComponent, { createComponentWrapper({ hasMetrics: true }, { attachToDocument: true });
localVue,
sync: false,
propsData: { ...propsData, hasMetrics: true },
store,
attachToDocument: true,
});
setupComponentStore(wrapper.vm); setupComponentStore(wrapper.vm);
...@@ -417,6 +417,10 @@ describe('Dashboard', () => { ...@@ -417,6 +417,10 @@ describe('Dashboard', () => {
wrapper.destroy(); wrapper.destroy();
}); });
afterEach(() => {
wrapper.destroy();
});
it('wraps vuedraggable', () => { it('wraps vuedraggable', () => {
expect(findDraggablePanels().exists()).toBe(true); expect(findDraggablePanels().exists()).toBe(true);
expect(findDraggablePanels().length).toEqual(expectedPanelCount); expect(findDraggablePanels().length).toEqual(expectedPanelCount);
...@@ -502,7 +506,6 @@ describe('Dashboard', () => { ...@@ -502,7 +506,6 @@ describe('Dashboard', () => {
// https://gitlab.com/gitlab-org/gitlab-ce/issues/66922 // https://gitlab.com/gitlab-org/gitlab-ce/issues/66922
// eslint-disable-next-line jasmine/no-disabled-tests // eslint-disable-next-line jasmine/no-disabled-tests
xdescribe('link to chart', () => { xdescribe('link to chart', () => {
let wrapper;
const currentDashboard = 'TEST_DASHBOARD'; const currentDashboard = 'TEST_DASHBOARD';
localVue.use(GlToast); localVue.use(GlToast);
const link = () => wrapper.find('.js-chart-link'); const link = () => wrapper.find('.js-chart-link');
...@@ -511,13 +514,7 @@ describe('Dashboard', () => { ...@@ -511,13 +514,7 @@ describe('Dashboard', () => {
beforeEach(done => { beforeEach(done => {
mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse); mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse);
wrapper = shallowMount(DashboardComponent, { createComponentWrapper({ hasMetrics: true, currentDashboard }, { attachToDocument: true });
localVue,
sync: false,
attachToDocument: true,
propsData: { ...propsData, hasMetrics: true, currentDashboard },
store,
});
setTimeout(done); setTimeout(done);
}); });
...@@ -614,19 +611,12 @@ describe('Dashboard', () => { ...@@ -614,19 +611,12 @@ describe('Dashboard', () => {
}); });
describe('dashboard edit link', () => { describe('dashboard edit link', () => {
let wrapper;
const findEditLink = () => wrapper.find('.js-edit-link'); const findEditLink = () => wrapper.find('.js-edit-link');
beforeEach(done => { beforeEach(done => {
mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse); mock.onGet(mockApiEndpoint).reply(200, metricsGroupsAPIResponse);
wrapper = shallowMount(DashboardComponent, { createComponentWrapper({ hasMetrics: true }, { attachToDocument: true });
localVue,
sync: false,
attachToDocument: true,
propsData: { ...propsData, hasMetrics: true },
store,
});
wrapper.vm.$store.commit( wrapper.vm.$store.commit(
`monitoringDashboard/${types.SET_ALL_DASHBOARDS}`, `monitoringDashboard/${types.SET_ALL_DASHBOARDS}`,
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import GraphGroup from '~/monitoring/components/graph_group.vue'; import GraphGroup from '~/monitoring/components/graph_group.vue';
const localVue = createLocalVue();
describe('Graph group component', () => { describe('Graph group component', () => {
let graphGroup; let graphGroup;
const findPrometheusGroup = () => graphGroup.find('.prometheus-graph-group'); const findPrometheusGroup = () => graphGroup.find('.prometheus-graph-group');
const findPrometheusPanel = () => graphGroup.find('.prometheus-panel'); const findPrometheusPanel = () => graphGroup.find('.prometheus-panel');
const createComponent = propsData => {
graphGroup = shallowMount(localVue.extend(GraphGroup), {
propsData,
sync: false,
localVue,
});
};
afterEach(() => { afterEach(() => {
graphGroup.destroy(); graphGroup.destroy();
}); });
describe('When groups can be collapsed', () => { describe('When groups can be collapsed', () => {
beforeEach(() => { beforeEach(() => {
graphGroup = shallowMount(GraphGroup, { createComponent({
propsData: {
name: 'panel', name: 'panel',
collapseGroup: true, collapseGroup: true,
},
}); });
}); });
...@@ -33,12 +42,10 @@ describe('Graph group component', () => { ...@@ -33,12 +42,10 @@ describe('Graph group component', () => {
describe('When groups can not be collapsed', () => { describe('When groups can not be collapsed', () => {
beforeEach(() => { beforeEach(() => {
graphGroup = shallowMount(GraphGroup, { createComponent({
propsData: {
name: 'panel', name: 'panel',
collapseGroup: true, collapseGroup: true,
showPanels: false, showPanels: false,
},
}); });
}); });
...@@ -49,12 +56,7 @@ describe('Graph group component', () => { ...@@ -49,12 +56,7 @@ describe('Graph group component', () => {
describe('When collapseGroup prop is updated', () => { describe('When collapseGroup prop is updated', () => {
beforeEach(() => { beforeEach(() => {
graphGroup = shallowMount(GraphGroup, { createComponent({ name: 'panel', collapseGroup: false });
propsData: {
name: 'panel',
collapseGroup: false,
},
});
}); });
it('previously collapsed group should respond to the prop change', done => { it('previously collapsed group should respond to the prop change', done => {
......
...@@ -2,15 +2,14 @@ import Vuex from 'vuex'; ...@@ -2,15 +2,14 @@ import Vuex from 'vuex';
import { createLocalVue, mount } from '@vue/test-utils'; import { createLocalVue, mount } from '@vue/test-utils';
import ReplyButton from '~/notes/components/note_actions/reply_button.vue'; import ReplyButton from '~/notes/components/note_actions/reply_button.vue';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('ReplyButton', () => { describe('ReplyButton', () => {
let wrapper; let wrapper;
beforeEach(() => { beforeEach(() => {
const localVue = createLocalVue(); wrapper = mount(localVue.extend(ReplyButton), {
localVue.use(Vuex);
wrapper = mount(ReplyButton, {
sync: false, sync: false,
localVue, localVue,
}); });
......
...@@ -12,7 +12,7 @@ describe('noteActions', () => { ...@@ -12,7 +12,7 @@ describe('noteActions', () => {
const shallowMountNoteActions = propsData => { const shallowMountNoteActions = propsData => {
const localVue = createLocalVue(); const localVue = createLocalVue();
return shallowMount(noteActions, { return shallowMount(localVue.extend(noteActions), {
store, store,
propsData, propsData,
localVue, localVue,
......
...@@ -14,7 +14,7 @@ describe('issue_note_form component', () => { ...@@ -14,7 +14,7 @@ describe('issue_note_form component', () => {
const createComponentWrapper = () => { const createComponentWrapper = () => {
const localVue = createLocalVue(); const localVue = createLocalVue();
return shallowMount(NoteForm, { return shallowMount(localVue.extend(NoteForm), {
store, store,
propsData: props, propsData: props,
// see https://gitlab.com/gitlab-org/gitlab-foss/issues/56317 for the following // see https://gitlab.com/gitlab-org/gitlab-foss/issues/56317 for the following
......
...@@ -10,6 +10,8 @@ import mockDiffFile from '../../diffs/mock_data/diff_file'; ...@@ -10,6 +10,8 @@ import mockDiffFile from '../../diffs/mock_data/diff_file';
const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json'; const discussionWithTwoUnresolvedNotes = 'merge_requests/resolved_diff_discussion.json';
const localVue = createLocalVue();
describe('noteable_discussion component', () => { describe('noteable_discussion component', () => {
let store; let store;
let wrapper; let wrapper;
...@@ -22,8 +24,7 @@ describe('noteable_discussion component', () => { ...@@ -22,8 +24,7 @@ describe('noteable_discussion component', () => {
store.dispatch('setNoteableData', noteableDataMock); store.dispatch('setNoteableData', noteableDataMock);
store.dispatch('setNotesData', notesDataMock); store.dispatch('setNotesData', notesDataMock);
const localVue = createLocalVue(); wrapper = mount(localVue.extend(noteableDiscussion), {
wrapper = mount(noteableDiscussion, {
store, store,
propsData: { discussion: discussionMock }, propsData: { discussion: discussionMock },
localVue, localVue,
......
...@@ -18,7 +18,7 @@ describe('issue_note', () => { ...@@ -18,7 +18,7 @@ describe('issue_note', () => {
store.dispatch('setNotesData', notesDataMock); store.dispatch('setNotesData', notesDataMock);
const localVue = createLocalVue(); const localVue = createLocalVue();
wrapper = shallowMount(issueNote, { wrapper = shallowMount(localVue.extend(issueNote), {
store, store,
propsData: { propsData: {
note, note,
......
...@@ -20,7 +20,7 @@ describe('RelatedMergeRequests', () => { ...@@ -20,7 +20,7 @@ describe('RelatedMergeRequests', () => {
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
mock.onGet(`${API_ENDPOINT}?per_page=100`).reply(200, mockData, { 'x-total': 2 }); mock.onGet(`${API_ENDPOINT}?per_page=100`).reply(200, mockData, { 'x-total': 2 });
wrapper = mount(RelatedMergeRequests, { wrapper = mount(localVue.extend(RelatedMergeRequests), {
localVue, localVue,
sync: false, sync: false,
store: createStore(), store: createStore(),
......
...@@ -4,18 +4,19 @@ import MrWidgetPipeline from '~/vue_merge_request_widget/components/mr_widget_pi ...@@ -4,18 +4,19 @@ import MrWidgetPipeline from '~/vue_merge_request_widget/components/mr_widget_pi
import ArtifactsApp from '~/vue_merge_request_widget/components/artifacts_list_app.vue'; import ArtifactsApp from '~/vue_merge_request_widget/components/artifacts_list_app.vue';
import { mockStore } from '../mock_data'; import { mockStore } from '../mock_data';
const localVue = createLocalVue();
describe('MrWidgetPipelineContainer', () => { describe('MrWidgetPipelineContainer', () => {
let wrapper; let wrapper;
const factory = (props = {}) => { const factory = (props = {}) => {
const localVue = createLocalVue();
wrapper = mount(localVue.extend(MrWidgetPipelineContainer), { wrapper = mount(localVue.extend(MrWidgetPipelineContainer), {
propsData: { propsData: {
mr: Object.assign({}, mockStore), mr: Object.assign({}, mockStore),
...props, ...props,
}, },
localVue, localVue,
sync: false,
}); });
}; };
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import GraphqlPagination from '~/vue_shared/components/pagination/graphql_pagination.vue'; import GraphqlPagination from '~/vue_shared/components/pagination/graphql_pagination.vue';
const localVue = createLocalVue();
describe('Graphql Pagination component', () => { describe('Graphql Pagination component', () => {
let wrapper; let wrapper;
function factory({ hasNextPage = true, hasPreviousPage = true }) { function factory({ hasNextPage = true, hasPreviousPage = true }) {
wrapper = shallowMount(GraphqlPagination, { wrapper = shallowMount(localVue.extend(GraphqlPagination), {
propsData: { propsData: {
hasNextPage, hasNextPage,
hasPreviousPage, hasPreviousPage,
}, },
sync: false,
localVue,
}); });
} }
......
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