Commit 7d69161d authored by Tan Le's avatar Tan Le

Use global Vue instance in frontend specs

Vue instance is not shared across tests and we should use this instead
of the deprecated createLocalVue function.
parent 505e29d3
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import App from 'ee/approvals/components/app.vue'; import App from 'ee/approvals/components/app.vue';
import ModalRuleCreate from 'ee/approvals/components/modal_rule_create.vue'; import ModalRuleCreate from 'ee/approvals/components/modal_rule_create.vue';
...@@ -10,8 +11,7 @@ import showToast from '~/vue_shared/plugins/global_toast'; ...@@ -10,8 +11,7 @@ import showToast from '~/vue_shared/plugins/global_toast';
jest.mock('~/vue_shared/plugins/global_toast'); jest.mock('~/vue_shared/plugins/global_toast');
const localVue = createLocalVue(); Vue.use(Vuex);
localVue.use(Vuex);
const TEST_RULES_CLASS = 'js-fake-rules'; const TEST_RULES_CLASS = 'js-fake-rules';
const APP_PREFIX = 'lorem-ipsum'; const APP_PREFIX = 'lorem-ipsum';
...@@ -23,8 +23,7 @@ describe('EE Approvals App', () => { ...@@ -23,8 +23,7 @@ describe('EE Approvals App', () => {
const targetBranchName = 'development'; const targetBranchName = 'development';
const factory = () => { const factory = () => {
wrapper = shallowMount(localVue.extend(App), { wrapper = shallowMount(App, {
localVue,
slots, slots,
store: new Vuex.Store(store), store: new Vuex.Store(store),
}); });
......
import { GlDropdown, GlDropdownItem, GlSearchBoxByType } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem, GlSearchBoxByType } from '@gitlab/ui';
import { createLocalVue, shallowMount, mount } from '@vue/test-utils'; import { shallowMount, mount } from '@vue/test-utils';
import { nextTick } from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import Api from 'ee/api'; import Api from 'ee/api';
import BranchesSelect from 'ee/approvals/components/branches_select.vue'; import BranchesSelect from 'ee/approvals/components/branches_select.vue';
...@@ -15,9 +15,8 @@ const TEST_PROTECTED_BRANCHES = [ ...@@ -15,9 +15,8 @@ const TEST_PROTECTED_BRANCHES = [
const TEST_BRANCHES_SELECTIONS = [TEST_DEFAULT_BRANCH, ...TEST_PROTECTED_BRANCHES]; const TEST_BRANCHES_SELECTIONS = [TEST_DEFAULT_BRANCH, ...TEST_PROTECTED_BRANCHES];
const branchNames = () => TEST_BRANCHES_SELECTIONS.map((branch) => branch.name); const branchNames = () => TEST_BRANCHES_SELECTIONS.map((branch) => branch.name);
const protectedBranchNames = () => TEST_PROTECTED_BRANCHES.map((branch) => branch.name); const protectedBranchNames = () => TEST_PROTECTED_BRANCHES.map((branch) => branch.name);
const localVue = createLocalVue();
localVue.use(Vuex); Vue.use(Vuex);
describe('Branches Select', () => { describe('Branches Select', () => {
let wrapper; let wrapper;
...@@ -33,7 +32,6 @@ describe('Branches Select', () => { ...@@ -33,7 +32,6 @@ describe('Branches Select', () => {
projectId: '1', projectId: '1',
...props, ...props,
}, },
localVue,
store: new Vuex.Store(store), store: new Vuex.Store(store),
attachTo: document.body, attachTo: document.body,
}); });
...@@ -83,7 +81,7 @@ describe('Branches Select', () => { ...@@ -83,7 +81,7 @@ describe('Branches Select', () => {
it('displays all the protected branches and any branch', async () => { it('displays all the protected branches and any branch', async () => {
createComponent(); createComponent();
await nextTick(); await Vue.nextTick();
expect(findDropdown().props('loading')).toBe(true); expect(findDropdown().props('loading')).toBe(true);
await waitForPromises(); await waitForPromises();
...@@ -101,7 +99,7 @@ describe('Branches Select', () => { ...@@ -101,7 +99,7 @@ describe('Branches Select', () => {
const term = 'lorem'; const term = 'lorem';
findSearch().vm.$emit('input', term); findSearch().vm.$emit('input', term);
await nextTick(); await Vue.nextTick();
expect(findSearch().props('isLoading')).toBe(true); expect(findSearch().props('isLoading')).toBe(true);
await waitForPromises(); await waitForPromises();
......
import { GlIcon } from '@gitlab/ui'; import { GlIcon } from '@gitlab/ui';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex';
import HiddenGroupsItem from 'ee/approvals/components/hidden_groups_item.vue'; import HiddenGroupsItem from 'ee/approvals/components/hidden_groups_item.vue';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
const localVue = createLocalVue(); Vue.use(Vuex);
describe('Approvals HiddenGroupsItem', () => { describe('Approvals HiddenGroupsItem', () => {
let wrapper; let wrapper;
const factory = (options = {}) => { const factory = (options = {}) => {
wrapper = extendedWrapper( wrapper = extendedWrapper(
shallowMount(localVue.extend(HiddenGroupsItem), { shallowMount(HiddenGroupsItem, {
...options, ...options,
localVue,
directives: { directives: {
GlTooltip: createMockDirective(), GlTooltip: createMockDirective(),
}, },
......
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import ModalRuleCreate from 'ee/approvals/components/modal_rule_create.vue'; import ModalRuleCreate from 'ee/approvals/components/modal_rule_create.vue';
import RuleForm from 'ee/approvals/components/rule_form.vue'; import RuleForm from 'ee/approvals/components/rule_form.vue';
...@@ -9,8 +10,7 @@ const TEST_MODAL_ID = 'test-modal-create-id'; ...@@ -9,8 +10,7 @@ const TEST_MODAL_ID = 'test-modal-create-id';
const TEST_RULE = { id: 7 }; const TEST_RULE = { id: 7 };
const MODAL_MODULE = 'createModal'; const MODAL_MODULE = 'createModal';
const localVue = createLocalVue(); Vue.use(Vuex);
localVue.use(Vuex);
describe('Approvals ModalRuleCreate', () => { describe('Approvals ModalRuleCreate', () => {
let createModalState; let createModalState;
...@@ -36,9 +36,8 @@ describe('Approvals ModalRuleCreate', () => { ...@@ -36,9 +36,8 @@ describe('Approvals ModalRuleCreate', () => {
...options.propsData, ...options.propsData,
}; };
wrapper = shallowMount(localVue.extend(ModalRuleCreate), { wrapper = shallowMount(ModalRuleCreate, {
...options, ...options,
localVue,
store, store,
propsData, propsData,
stubs: { stubs: {
......
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import MRRulesHiddenInputs from 'ee/approvals/components/mr_edit/mr_rules_hidden_inputs.vue'; import MRRulesHiddenInputs from 'ee/approvals/components/mr_edit/mr_rules_hidden_inputs.vue';
import { createStoreOptions } from 'ee/approvals/stores'; import { createStoreOptions } from 'ee/approvals/stores';
import MREditModule from 'ee/approvals/stores/modules/mr_edit'; import MREditModule from 'ee/approvals/stores/modules/mr_edit';
import { createMRRule } from '../../mocks'; import { createMRRule } from '../../mocks';
const localVue = createLocalVue(); Vue.use(Vuex);
localVue.use(Vuex);
const { const {
INPUT_ID, INPUT_ID,
...@@ -28,8 +28,7 @@ describe('EE Approvlas MRRulesHiddenInputs', () => { ...@@ -28,8 +28,7 @@ describe('EE Approvlas MRRulesHiddenInputs', () => {
let store; let store;
const factory = () => { const factory = () => {
wrapper = shallowMount(localVue.extend(MRRulesHiddenInputs), { wrapper = shallowMount(MRRulesHiddenInputs, {
localVue,
store: new Vuex.Store(store), store: new Vuex.Store(store),
}); });
}; };
......
import { mount, createLocalVue } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import MRRules from 'ee/approvals/components/mr_edit/mr_rules.vue'; import MRRules from 'ee/approvals/components/mr_edit/mr_rules.vue';
import RuleControls from 'ee/approvals/components/rule_controls.vue'; import RuleControls from 'ee/approvals/components/rule_controls.vue';
...@@ -10,8 +11,7 @@ import { createEmptyRule, createMRRule, createMRRuleWithSource } from '../../moc ...@@ -10,8 +11,7 @@ import { createEmptyRule, createMRRule, createMRRuleWithSource } from '../../moc
const { HEADERS } = Rules; const { HEADERS } = Rules;
const localVue = createLocalVue(); Vue.use(Vuex);
localVue.use(Vuex);
describe('EE Approvals MRRules', () => { describe('EE Approvals MRRules', () => {
let wrapper; let wrapper;
...@@ -24,8 +24,7 @@ describe('EE Approvals MRRules', () => { ...@@ -24,8 +24,7 @@ describe('EE Approvals MRRules', () => {
store.modules.approvals.state.rules = approvalRules; store.modules.approvals.state.rules = approvalRules;
} }
wrapper = mount(localVue.extend(MRRules), { wrapper = mount(MRRules, {
localVue,
store: new Vuex.Store(store), store: new Vuex.Store(store),
attachTo: document.body, attachTo: document.body,
}); });
......
import { mount, createLocalVue } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import ApprovalGateIcon from 'ee/approvals/components/approval_gate_icon.vue'; import ApprovalGateIcon from 'ee/approvals/components/approval_gate_icon.vue';
import RuleInput from 'ee/approvals/components/mr_edit/rule_input.vue'; import RuleInput from 'ee/approvals/components/mr_edit/rule_input.vue';
...@@ -13,8 +14,7 @@ import { createProjectRules, createExternalRule } from '../../mocks'; ...@@ -13,8 +14,7 @@ import { createProjectRules, createExternalRule } from '../../mocks';
const TEST_RULES = createProjectRules(); const TEST_RULES = createProjectRules();
const localVue = createLocalVue(); Vue.use(Vuex);
localVue.use(Vuex);
const findCell = (tr, name) => tr.find(`td.js-${name}`); const findCell = (tr, name) => tr.find(`td.js-${name}`);
...@@ -37,7 +37,6 @@ describe('Approvals ProjectRules', () => { ...@@ -37,7 +37,6 @@ describe('Approvals ProjectRules', () => {
wrapper = mount(ProjectRules, { wrapper = mount(ProjectRules, {
propsData: props, propsData: props,
store: new Vuex.Store(store), store: new Vuex.Store(store),
localVue,
...options, ...options,
}); });
}; };
......
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import { createLocalVue, shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import RuleControls from 'ee/approvals/components/rule_controls.vue'; import RuleControls from 'ee/approvals/components/rule_controls.vue';
import { createStoreOptions } from 'ee/approvals/stores'; import { createStoreOptions } from 'ee/approvals/stores';
import MREditModule from 'ee/approvals/stores/modules/mr_edit'; import MREditModule from 'ee/approvals/stores/modules/mr_edit';
const localVue = createLocalVue(); Vue.use(Vuex);
localVue.use(Vuex);
const TEST_RULE = { id: 10 }; const TEST_RULE = { id: 10 };
...@@ -19,11 +19,10 @@ describe('EE Approvals RuleControls', () => { ...@@ -19,11 +19,10 @@ describe('EE Approvals RuleControls', () => {
let actions; let actions;
const factory = () => { const factory = () => {
wrapper = shallowMount(localVue.extend(RuleControls), { wrapper = shallowMount(RuleControls, {
propsData: { propsData: {
rule: TEST_RULE, rule: TEST_RULE,
}, },
localVue,
store: new Vuex.Store(store), store: new Vuex.Store(store),
}); });
}; };
......
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import ApproverTypeSelect from 'ee/approvals/components/approver_type_select.vue'; import ApproverTypeSelect from 'ee/approvals/components/approver_type_select.vue';
import ApproversList from 'ee/approvals/components/approvers_list.vue'; import ApproversList from 'ee/approvals/components/approvers_list.vue';
...@@ -58,8 +58,7 @@ const urlTakenError = { ...@@ -58,8 +58,7 @@ const urlTakenError = {
}, },
}; };
const localVue = createLocalVue(); Vue.use(Vuex);
localVue.use(Vuex);
const addType = (type) => (x) => Object.assign(x, { type }); const addType = (type) => (x) => Object.assign(x, { type });
...@@ -72,7 +71,6 @@ describe('EE Approvals RuleForm', () => { ...@@ -72,7 +71,6 @@ describe('EE Approvals RuleForm', () => {
wrapper = shallowMount(RuleForm, { wrapper = shallowMount(RuleForm, {
propsData: props, propsData: props,
store: new Vuex.Store(store), store: new Vuex.Store(store),
localVue,
provide: { provide: {
glFeatures: { glFeatures: {
ffComplianceApprovalGates: true, ffComplianceApprovalGates: true,
...@@ -174,8 +172,7 @@ describe('EE Approvals RuleForm', () => { ...@@ -174,8 +172,7 @@ describe('EE Approvals RuleForm', () => {
wrapper.vm.branches = ['3']; wrapper.vm.branches = ['3'];
wrapper.vm.submit(); wrapper.vm.submit();
localVue Vue.nextTick()
.nextTick()
.then(() => { .then(() => {
expect(findBranchesValidation()).toEqual({ expect(findBranchesValidation()).toEqual({
isValid: false, isValid: false,
...@@ -280,7 +277,7 @@ describe('EE Approvals RuleForm', () => { ...@@ -280,7 +277,7 @@ describe('EE Approvals RuleForm', () => {
wrapper.vm.submit(); wrapper.vm.submit();
await nextTick(); await Vue.nextTick();
expect(findExternalUrlValidation()).toEqual({ expect(findExternalUrlValidation()).toEqual({
isValid: false, isValid: false,
...@@ -354,8 +351,7 @@ describe('EE Approvals RuleForm', () => { ...@@ -354,8 +351,7 @@ describe('EE Approvals RuleForm', () => {
wrapper.vm.submit(); wrapper.vm.submit();
localVue Vue.nextTick()
.nextTick()
.then(() => { .then(() => {
expect(findNameValidation()).toEqual({ expect(findNameValidation()).toEqual({
isValid: false, isValid: false,
...@@ -371,8 +367,7 @@ describe('EE Approvals RuleForm', () => { ...@@ -371,8 +367,7 @@ describe('EE Approvals RuleForm', () => {
wrapper.vm.submit(); wrapper.vm.submit();
localVue Vue.nextTick()
.nextTick()
.then(() => { .then(() => {
expect(findApprovalsRequiredValidation()).toEqual({ expect(findApprovalsRequiredValidation()).toEqual({
isValid: false, isValid: false,
...@@ -387,8 +382,7 @@ describe('EE Approvals RuleForm', () => { ...@@ -387,8 +382,7 @@ describe('EE Approvals RuleForm', () => {
wrapper.vm.approvers = []; wrapper.vm.approvers = [];
wrapper.vm.submit(); wrapper.vm.submit();
localVue Vue.nextTick()
.nextTick()
.then(() => { .then(() => {
expect(findApproversValidation()).toEqual({ expect(findApproversValidation()).toEqual({
isValid: false, isValid: false,
...@@ -542,7 +536,7 @@ describe('EE Approvals RuleForm', () => { ...@@ -542,7 +536,7 @@ describe('EE Approvals RuleForm', () => {
describe('with empty name and empty approvers', () => { describe('with empty name and empty approvers', () => {
beforeEach((done) => { beforeEach((done) => {
wrapper.vm.submit(); wrapper.vm.submit();
localVue.nextTick(done); Vue.nextTick(done);
}); });
it('does not post rule', () => { it('does not post rule', () => {
...@@ -565,7 +559,7 @@ describe('EE Approvals RuleForm', () => { ...@@ -565,7 +559,7 @@ describe('EE Approvals RuleForm', () => {
wrapper.vm.name = 'Lorem'; wrapper.vm.name = 'Lorem';
wrapper.vm.submit(); wrapper.vm.submit();
localVue.nextTick(done); Vue.nextTick(done);
}); });
it('does not put fallback rule', () => { it('does not put fallback rule', () => {
...@@ -582,7 +576,7 @@ describe('EE Approvals RuleForm', () => { ...@@ -582,7 +576,7 @@ describe('EE Approvals RuleForm', () => {
wrapper.vm.approvers = TEST_APPROVERS; wrapper.vm.approvers = TEST_APPROVERS;
wrapper.vm.submit(); wrapper.vm.submit();
localVue.nextTick(done); Vue.nextTick(done);
}); });
it('does not put fallback rule', () => { it('does not put fallback rule', () => {
...@@ -600,7 +594,7 @@ describe('EE Approvals RuleForm', () => { ...@@ -600,7 +594,7 @@ describe('EE Approvals RuleForm', () => {
wrapper.vm.name = 'Lorem'; wrapper.vm.name = 'Lorem';
wrapper.vm.submit(); wrapper.vm.submit();
localVue.nextTick(done); Vue.nextTick(done);
}); });
it('does not put fallback rule', () => { it('does not put fallback rule', () => {
...@@ -795,7 +789,7 @@ describe('EE Approvals RuleForm', () => { ...@@ -795,7 +789,7 @@ describe('EE Approvals RuleForm', () => {
wrapper.vm.approvers = TEST_APPROVERS; wrapper.vm.approvers = TEST_APPROVERS;
wrapper.vm.submit(); wrapper.vm.submit();
return localVue.nextTick(); return Vue.nextTick();
}); });
it('posts new rule', () => { it('posts new rule', () => {
...@@ -814,7 +808,7 @@ describe('EE Approvals RuleForm', () => { ...@@ -814,7 +808,7 @@ describe('EE Approvals RuleForm', () => {
beforeEach(() => { beforeEach(() => {
wrapper.vm.submit(); wrapper.vm.submit();
return localVue.nextTick(); return Vue.nextTick();
}); });
it('puts fallback rule', () => { it('puts fallback rule', () => {
...@@ -845,7 +839,7 @@ describe('EE Approvals RuleForm', () => { ...@@ -845,7 +839,7 @@ describe('EE Approvals RuleForm', () => {
wrapper.vm.submit(); wrapper.vm.submit();
return localVue.nextTick(); return Vue.nextTick();
}); });
it('deletes rule', () => { it('deletes rule', () => {
...@@ -865,7 +859,7 @@ describe('EE Approvals RuleForm', () => { ...@@ -865,7 +859,7 @@ describe('EE Approvals RuleForm', () => {
wrapper.vm.approvers = TEST_APPROVERS; wrapper.vm.approvers = TEST_APPROVERS;
wrapper.vm.submit(); wrapper.vm.submit();
localVue.nextTick(done); Vue.nextTick(done);
}); });
it('puts rule', () => { it('puts rule', () => {
...@@ -896,7 +890,7 @@ describe('EE Approvals RuleForm', () => { ...@@ -896,7 +890,7 @@ describe('EE Approvals RuleForm', () => {
}, },
); );
await nextTick(); await Vue.nextTick();
expect(findApproverTypeSelect().exists()).toBe(false); expect(findApproverTypeSelect().exists()).toBe(false);
}); });
......
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